{"record":{"id":"96a1d7991fc6cffb","repo":"theonedev/onedev","slug":"shallow-commits-have-already-been-initialized","errorCode":null,"errorMessage":"Shallow commits have already been initialized.","messagePattern":"Shallow commits have already been initialized\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/eclipse/jgit/revwalk/RevWalk.java","lineNumber":1831,"sourceCode":"\t * There is a sequencing problem if the first commit being parsed is a\n\t * shallow commit, since {@link RevCommit#parseCanonical(RevWalk, byte[])}\n\t * calls this method before its callers add the new commit to the\n\t * {@link RevWalk#objects} map. That means a call from this method to\n\t * {@link #lookupCommit(AnyObjectId)} fails to find that commit and creates\n\t * a new one, which is promptly discarded.\n\t * <p>\n\t * To avoid that, {@link RevCommit#parseCanonical(RevWalk, byte[])} passes\n\t * its commit to this method, so that this method can apply the shallow\n\t * state to it directly and avoid creating the duplicate commit object.\n\t *\n\t * @param rc\n\t *            the initial commit being parsed\n\t * @throws IOException\n\t *             if the shallow commits file can't be read\n\t */\n\tvoid initializeShallowCommits(RevCommit rc) throws IOException {\n\t\tif (shallowCommitsInitialized) {\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\tJGitText.get().shallowCommitsAlreadyInitialized);\n\t\t}\n\n\t\tshallowCommitsInitialized = true;\n\n\t\tif (reader == null) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (ObjectId id : reader.getShallowCommits()) {\n\t\t\tif (id.equals(rc.getId())) {\n\t\t\t\trc.parents = RevCommit.NO_PARENTS;\n\t\t\t} else {\n\t\t\t\tlookupCommit(id).parents = RevCommit.NO_PARENTS;\n\t\t\t}\n\t\t}\n\t}\n}","sourceCodeStart":1813,"sourceCodeEnd":1849,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/eclipse/jgit/revwalk/RevWalk.java#L1813-L1849","documentation":"RevWalk initializes shallow-commit information (from the repository's shallow file) at most once. initializeShallowCommits() throws IllegalStateException if shallowCommitsInitialized is already true, protecting against re-reading and duplicating shallow roots mid-walk.","triggerScenarios":"Internally triggered when commit parsing re-enters initializeShallowCommits after it already ran; direct callers (subclasses/tests) invoking it twice on the same walk; reusing a walk instance across shallow setups.","commonSituations":"Custom RevWalk subclasses that manually parse commits and call initializeShallowCommits unconditionally per commit; concurrency where two threads parse the first commit of a shallow clone simultaneously on one walk.","solutions":["Do not call initializeShallowCommits directly; let RevWalk.parseCommit/parseAny trigger it once.","Guard custom code with a flag before invoking it, or check walk.shallowCommitsInitialized state via subclass accessors.","Use one RevWalk per thread; do not share walk instances across concurrent parsing."],"exampleFix":"// before\nwalk.initializeShallowCommits(rc); // called for every parsed commit\n// after\nif (!shallowCommitsInitialized)\n    walk.initializeShallowCommits(rc);","handlingStrategy":"try-catch","validationCode":"// call at most once per walk instance\nif (!initialized.getAndSet(true))\n    walk.initializeShallowCommits(rc);","typeGuard":"AtomicBoolean shallowInit = new AtomicBoolean(false);\nboolean shouldInit = shallowInit.compareAndSet(false, true);","tryCatchPattern":"try {\n    walk.initializeShallowCommits(rc);\n} catch (IllegalStateException e) {\n    // already initialized - safe to ignore\n}","preventionTips":["Let RevWalk.parseCommit/parseAny trigger shallow init implicitly","Never call initializeShallowCommits per commit in loops","Use one RevWalk per thread to avoid concurrent double-init"],"tags":["git","revwalk","shallow-clone","illegal-state"],"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-14T05:17:10.506Z"}