Buggy code:
@ Override public Document getContentAsDocument ( String path ) throws DocumentException { } @ Override public boolean writeContent ( String path , InputStream content ) { } @ Override public void writeContent ( String site , String path , String fileName , String contentType , InputStream input , String createFolders , String edit , String unlock ) throws ServiceException { } @ Override public void writeContentAndRename ( final String site , final String path , final String targetPath , final String fileName , final String contentType , final InputStream input , final String createFolders , final String edit , final String unlock , final boolean createFolder ) throws ServiceException { } @ Override public Map < String , Object > writeContentAsset ( String site , String path , String assetName , InputStream in , String isImage , String allowedWidth , String allowedHeight , String allowLessSize , String draft , String unlock , String systemAsset ) throws ServiceException { } @ Override public boolean writeContent ( String site , String path , InputStream content ) { } @ Override public boolean createFolder ( String site , String path , String name ) { } @ Override public boolean deleteContent ( String site , String path ) { } @ Override public boolean copyContent ( String site , String fromPath , String toPath ) { } @ Override public boolean moveContent ( String site , String fromPath , String toPath ) { } protected ContentItemTO createNewContentItemTO ( String site , String contentPath ) { } protected ContentItemTO populateContentDrivenProperties ( String site , ContentItemTO item ) throws Exception { } protected void addOrderValue ( List < DmOrderTO > orders , String orderName , String orderStr ) { } protected List < DmOrderTO > getItemOrders ( List < Node > nodes ) { } protected ContentItemTO populateItemChildren ( ContentItemTO item , int depth ) { } @ Override public ContentItemTO getContentItem ( String site , String path ) { } @ Override public ContentItemTO getContentItem ( String site , String path , int depth ) { } @ Override public ContentItemTO getContentItem ( String fullPath ) { } protected void loadContentTypeProperties ( String site , ContentItemTO item , String contentType ) { } protected void populateWorkflowProperties ( String site , ContentItemTO item ) { } protected void populateMetadata ( String site , ContentItemTO item ) { } @ Override public ContentItemTO getContentItemTree ( String site , String path , int depth ) { } @ Override public ContentItemTO getContentItemTree ( String fullPath , int depth ) { } @ Override public VersionTO [ ] getContentItemVersionHistory ( String site , String path ) { } @ Override public boolean revertContentItem ( String site , String path , String version , boolean major , String comment ) { } public ContentItemTO createDummyDmContentItemForDeletedNode ( String site , String relativePath ) { } @ Override public String expandRelativeSitePath ( String site , String relativePath ) { } @ Override public String getRelativeSitePath ( String site , String fullPath ) { } protected String getRelativeSitePath ( String fullPath ) { } protected String getSiteFromFullPath ( String fullPath ) { } protected String getBrowserUri ( ContentItemTO item ) { } protected static String getBrowserUri ( String uri , String replacePattern , boolean isPage ) { } @ Override public String getContentTypeClass ( String site , String uri ) { } protected boolean matchesPatterns ( String uri , List < String > patterns ) { } protected void rename ( final String site , final String path , final String targetPath , final boolean createFolder ) throws ServiceException { } @ Override public ResultTO processContent ( String id , InputStream input , boolean isXml , Map < String , String > params , String contentChainForm ) throws ServiceException { } protected ResultTO doSave ( String id , InputStream input , boolean isXml , Map < String , String > params , String chainName , final String path , final String site ) throws ServiceException { } @ Override public String getNextAvailableName ( String site , String path ) { String [ ] levels = path . split ( "//" ) ; int length = levels . length ; if ( length > 0 ) { ContentItemTO item = getContentItem ( site , path ) ; if ( item != null ) { <START_BUG> String name = item . getName ( ) ; <END_BUG> String parentPath = ContentUtils . getParentUrl ( path ) ; ContentItemTO parentItem = getContentItemTree ( site , parentPath , 1 ) ; if ( parentItem != null ) { int lastIndex = name . lastIndexOf ( "." ) ; String ext = ( item . isFolder ( ) ) ? "" : name . substring ( lastIndex ) ; String originalName = ( item . isFolder ( ) ) ? name : name . substring ( 0 , lastIndex ) ; List < ContentItemTO > children = parentItem . getChildren ( ) ; int lastNumber = 0 ; String namePattern = ( originalName + "\\-[0-9]+" ) + ext ; if ( ( children != null ) && ( ( children . size ( ) ) > 0 ) ) { for ( ContentItemTO child : children ) { if ( ( item . isFolder ( ) ) == ( child . isFolder ( ) ) ) { String childName = child . getName ( ) ; if ( childName . matches ( namePattern ) ) { Pattern pattern = ( item . isFolder ( ) ) ? ContentServiceImpl . COPY_FOLDER_PATTERN : ContentServiceImpl . COPY_FILE_PATTERN ; Matcher matcher = pattern . matcher ( childName ) ; if ( matcher . matches ( ) ) { int helper = ContentFormatUtils . getIntValue ( matcher . group ( 2 ) ) ; lastNumber = ( helper > lastNumber ) ? helper : lastNumber ; } } } } } String nextName = ( ( originalName + "-" ) + ( ++ lastNumber ) ) + ext ; return nextName ;

Fix:
String name = ContentUtils . getPageName ( path ) ;