{"record":{"id":"e6154fd0754f282c","repo":"jenkinsci/jenkins","slug":"the-name-0-is-already-in-use","errorCode":null,"errorMessage":"The name “{0}” is already in use.","messagePattern":"The name “(.+?)” is already in use\\.","errorType":"validation","errorClass":"Failure","httpStatus":null,"severity":"warning","filePath":"core/src/main/java/hudson/model/AbstractItem.java","lineNumber":312,"sourceCode":"            }\n            Jenkins.get().getProjectNamingStrategy().checkName(getParent().getFullName(), newName);\n            checkIfNameIsUsed(newName);\n            checkRename(newName);\n        } catch (Failure e) {\n            return FormValidation.error(e.getMessage());\n        }\n        return FormValidation.ok();\n    }\n\n    /**\n     * Check new name for job\n     * @param newName - New name for job.\n     */\n    private void checkIfNameIsUsed(@NonNull String newName) throws Failure {\n        try {\n            Item item = getParent().getItem(newName);\n            if (item != null) {\n                throw new Failure(Messages.AbstractItem_NewNameInUse(newName));\n            }\n            try (ACLContext ctx = ACL.as2(ACL.SYSTEM2)) {\n                item = getParent().getItem(newName);\n                if (item != null) {\n                    if (LOGGER.isLoggable(Level.FINE)) {\n                        LOGGER.log(Level.FINE, \"Unable to rename the job {0}: name {1} is already in use. \" +\n                                \"User {2} has no {3} permission for existing job with the same name\",\n                                new Object[] {this.getFullName(), newName, ctx.getPreviousContext2().getAuthentication().getName(), Item.DISCOVER.name});\n                    }\n                    // Don't explicitly mention that there is another item with the same name.\n                    throw new Failure(Messages.Jenkins_NotAllowedName(newName));\n                }\n            }\n        } catch (AccessDeniedException ex) {\n            if (LOGGER.isLoggable(Level.FINE)) {\n                LOGGER.log(Level.FINE, \"Unable to rename the job {0}: name {1} is already in use. \" +\n                        \"User {2} has {3} permission, but no {4} for existing job with the same name\",\n                        new Object[] {this.getFullName(), newName, User.current(), Item.DISCOVER.name, Item.READ.name});","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/core/src/main/java/hudson/model/AbstractItem.java#L294-L330","documentation":"Thrown by checkIfNameIsUsed(newName) when a same-named item already exists in the parent and the current user can see it (getItem returns non-null without ACL elevation). The localized 'NewNameInUse' message tells the user the name is taken. This is the straightforward collision case — the rename would create a duplicate.","triggerScenarios":"During a rename, checkIfNameIsUsed calls getParent().getItem(newName); if non-null (and visible to the caller), it throws Failure with AbstractItem_NewNameInUse.","commonSituations":"Renaming a job to a name that matches an existing job in the same folder; case-insensitive collisions on case-insensitive filesystems; automation scripts computing new names that clash.","solutions":["Choose a unique new name that does not exist in the same parent folder","Check for collisions before submitting: call getParent().getItem(newName) and validate","If the target item is one you intend to replace, delete or rename it first","Be aware of case-insensitive matching on Windows/macOS filesystems"],"exampleFix":"// before: rename blindly\nitem.renameTo(takenName);\n// after: check first\nif (item.getParent().getItem(takenName) != null) {\n    throw new Failure(\"Name '\" + takenName + \"' is already in use\");\n}\nitem.renameTo(takenName);","handlingStrategy":"validation","validationCode":"if (item.getParent().getItem(newName) != null) {\n    throw new IllegalStateException(\"Name '\" + newName + \"' already exists in parent\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    // rename flow\n} catch (Failure f) {\n    if (f.getMessage().contains(\"already in use\")) {\n        // prompt user for a different name\n    }\n    throw f;\n}","preventionTips":["Check getParent().getItem(newName) for collisions before submitting a rename","Be aware of case-insensitive filesystems on Windows/macOS","In automation, compute unique names or pre-check existence"],"tags":["item","rename","naming","collision","stapler","validation"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}