{"record":{"id":"b4622c7fad99335f","repo":"theonedev/onedev","slug":"inusemessage","errorCode":null,"errorMessage":"${inUseMessage}","messagePattern":"\\$\\{inUseMessage\\}","errorType":"exception","errorClass":"InUseException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/util/usage/Usage.java","lineNumber":57,"sourceCode":"\t\tif (!places.isEmpty()) {\n\t\t\tStringBuilder builder = new StringBuilder(thing + \" is still being used in below places:\\n\");\n\t\t\tfor (String place: places) {\n\t\t\t\tif (!place.startsWith(\"->\"))\n\t\t\t\t\tbuilder.append(\"    -> \" + place).append(\"\\n\");\n\t\t\t\telse\n\t\t\t\t\tbuilder.append(\"    \" + place).append(\"\\n\");\n\t\t\t}\n\t\t\tString message = builder.toString();\n\t\t\treturn message.substring(0, message.length()-1);\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\t\n\tpublic void checkInUse(String thing) {\n\t\tString inUseMessage = getInUseMessage(thing);\n\t\tif (inUseMessage != null)\n\t\t\tthrow new InUseException(inUseMessage);\n\t}\n\t\n}\n","sourceCodeStart":39,"sourceCodeEnd":61,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/util/usage/Usage.java#L39-L61","documentation":"Usage.checkInUse(thing) calls getInUseMessage(thing); if a non-null message is returned it throws InUseException with that message. It guards destructive operations (delete/update) on entities still referenced elsewhere, and callers like checkUsage rely on it to block the operation.","triggerScenarios":"Calling delete or update on an entity (project, group, role, etc.) that other entities still reference; the concrete message comes from the subclass's getInUseMessage implementation.","commonSituations":"Deleting a group that still has members or is referenced by authorizations; removing a build spec or secret still used by jobs; cascade deletes attempted manually instead of via the guarded API.","solutions":["Remove the references reported in the in-use message, then retry delete/update","Call getInUseMessage beforehand and display it to the user instead of attempting the operation","Catch InUseException around delete/update and surface the message in the UI"],"exampleFix":"// before\ngroupService.delete(group);\n// after\nString inUse = groupService.getInUseMessage(group);\nif (inUse == null) {\n    groupService.delete(group);\n} else {\n    throw new ExplicitException(inUse);\n}","handlingStrategy":"try-catch","validationCode":"String inUse = entityService.getInUseMessage(entity);\nif (inUse != null) {\n    throw new ExplicitException(inUse);\n}","typeGuard":null,"tryCatchPattern":"try {\n    service.delete(entity);\n} catch (InUseException e) {\n    ui.showError(e.getMessage());\n}","preventionTips":["Check getInUseMessage before offering destructive actions in UI","Resolve references (members, authorizations, job usages) before deletion","Surface the in-use message instead of a generic delete failure"],"tags":["referential-integrity","delete","in-use"],"backgroundTag":"invalid-state-transition","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}