{"record":{"id":"2839e441564d8e34","repo":"theonedev/onedev","slug":"flag-0-is-disposed","errorCode":null,"errorMessage":"Flag {0} is disposed","messagePattern":"Flag (.+?) is disposed","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/eclipse/jgit/revwalk/RevWalk.java","lineNumber":1446,"sourceCode":"\t\t\t\t\tMessageFormat.format(JGitText.get().flagsAlreadyCreated,\n\t\t\t\t\t\t\tInteger.valueOf(32 - RESERVED_FLAGS)));\n\t\tfinal int m = Integer.lowestOneBit(freeFlags);\n\t\tfreeFlags &= ~m;\n\t\treturn m;\n\t}\n\n\t/**\n\t * Automatically carry a flag from a child commit to its parents.\n\t * <p>\n\t * A carried flag is copied from the child commit onto its parents when the\n\t * child commit is popped from the lowest level of walk's internal graph.\n\t *\n\t * @param flag\n\t *            the flag to carry onto parents, if set on a descendant.\n\t */\n\tpublic void carry(RevFlag flag) {\n\t\tif ((freeFlags & flag.mask) != 0)\n\t\t\tthrow new IllegalArgumentException(MessageFormat\n\t\t\t\t\t.format(JGitText.get().flagIsDisposed, flag.name));\n\t\tif (flag.walker != this)\n\t\t\tthrow new IllegalArgumentException(MessageFormat\n\t\t\t\t\t.format(JGitText.get().flagNotFromThis, flag.name));\n\t\tcarryFlags |= flag.mask;\n\t}\n\n\t/**\n\t * Automatically carry flags from a child commit to its parents.\n\t * <p>\n\t * A carried flag is copied from the child commit onto its parents when the\n\t * child commit is popped from the lowest level of walk's internal graph.\n\t *\n\t * @param set\n\t *            the flags to carry onto parents, if set on a descendant.\n\t */\n\tpublic void carry(Collection<RevFlag> set) {\n\t\tfor (RevFlag flag : set)","sourceCodeStart":1428,"sourceCodeEnd":1464,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/eclipse/jgit/revwalk/RevWalk.java#L1428-L1464","documentation":"RevWalk.carry(flag) registers a flag to be carried from child commits to parents. If the flag has already been disposed (its bit was returned to freeFlags via disposeFlag/dispose flag set), the walk refuses to use it and throws this IllegalArgumentException.","triggerScenarios":"Calling carry(flag) after revWalk.disposeFlag(flag) (or disposeFlagSet) on the same flag; keeping a RevFlag reference past the disposal of its flag and re-registering it later; disposing flags at the end of one traversal then reusing the walk and flag objects in another.","commonSituations":"Code that disposes flags in a finally block but then calls carry in a later retry of the same walk; shared utility that disposes flags unconditionally after first use.","solutions":["Re-create the flag with revWalk.newFlag(name) and carry the new instance.","Ensure disposeFlag is only called when the flag will never be used again on this walk.","Reorder code so carry() happens before any disposal logic."],"exampleFix":"// before\nwalk.disposeFlag(flag);\nwalk.carry(flag); // throws\n// after\nRevFlag flag = walk.newFlag(\"MINE\");\nwalk.carry(flag);\n// dispose only after traversal completes\n// walk.disposeFlag(flag);","handlingStrategy":"validation","validationCode":"boolean isUsable(RevWalk w, RevFlag f) {\n    return f.walker == w; // a disposed flag's bit is back in w.freeFlags; recreate instead of reusing\n}","typeGuard":"RevFlag requireLiveFlag(RevWalk w, RevFlag f) {\n    if (f.walker != w) throw new IllegalStateException(\"flag not from this walk or disposed\");\n    return f;\n}","tryCatchPattern":"try {\n    walk.carry(flag);\n} catch (IllegalArgumentException e) {\n    flag = walk.newFlag(flag.getName());\n    walk.carry(flag);\n}","preventionTips":["Only call disposeFlag when the flag is permanently finished","Re-create flags instead of reusing references after disposal","Order setup (newFlag -> carry) before any teardown logic"],"tags":["git","revflag","use-after-dispose"],"backgroundTag":"invalid-flag-value","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}