theonedev/onedev · error · IllegalArgumentException
{0} flags already created
Error message
{0} flags already created What it means
A RevWalk can create at most 32 RevFlags (one bit per flag, minus reserved bits); allocFlag() throws this IllegalArgumentException once no free bits remain. It is thrown when RevWalk.newFlag(name) is called after all flag bits have been handed out.
Source
Thrown at server-core/src/main/java/org/eclipse/jgit/revwalk/RevWalk.java:1427
* <p>
* Applications are only assured to be able to create 24 unique flags on any
* given revision walker instance. Any flags beyond 24 are offered only if
* the implementation has extra free space within its internal storage.
*
* @param name
* description of the flag, primarily useful for debugging.
* @return newly constructed flag instance.
* @throws java.lang.IllegalArgumentException
* too many flags have been reserved on this revision walker.
*/
public RevFlag newFlag(String name) {
final int m = allocFlag();
return new RevFlag(this, name, m);
}
int allocFlag() {
if (freeFlags == 0)
throw new IllegalArgumentException(
MessageFormat.format(JGitText.get().flagsAlreadyCreated,
Integer.valueOf(32 - RESERVED_FLAGS)));
final int m = Integer.lowestOneBit(freeFlags);
freeFlags &= ~m;
return m;
}
/**
* Automatically carry a flag from a child commit to its parents.
* <p>
* A carried flag is copied from the child commit onto its parents when the
* child commit is popped from the lowest level of walk's internal graph.
*
* @param flag
* the flag to carry onto parents, if set on a descendant.
*/
public void carry(RevFlag flag) {
if ((freeFlags & flag.mask) != 0)View on GitHub (pinned to d44925c47c)
Solutions
- Reuse a fixed small set of flags instead of creating one per item or per request.
- Call revWalk.disposeFlag(flag) when a flag is no longer needed to return its bit.
- Create a fresh RevWalk per traversal instead of reusing one indefinitely.
- Refactor to encode per-item state elsewhere (e.g. a map keyed by commit) rather than flags.
Example fix
// before
for (String name : names) flags.add(walk.newFlag(name)); // >32 names -> throws
// after
Map<String, RevFlag> flags = new HashMap<>();
for (String name : names) {
if (flags.size() >= 20) throw new IllegalStateException("too many flags");
flags.put(name, walk.newFlag(name));
} Defensive patterns
Strategy: validation
Validate before calling
if (flagCount >= 20) throw new IllegalStateException("RevWalk flag budget exhausted");
RevFlag f = walk.newFlag(name); Type guard
// track budget in a small wrapper
class FlagPool { int used = 0; RevFlag create(RevWalk w, String n) { if (used >= 20) throw new IllegalStateException(); used++; return w.newFlag(n); } } Try / catch
try {
flag = walk.newFlag(name);
} catch (IllegalArgumentException e) {
throw new IllegalStateException("Too many RevFlags created (max 32)", e);
} Prevention
- Define a fixed set of flags at walk construction
- Dispose flags with disposeFlag when done
- Never create flags inside per-item loops
- Use one RevWalk per traversal, not a long-lived shared one
When it happens
Trigger: Calling revWalk.newFlag(...) more than 32-minus-reserved times on the same RevWalk instance; creating flags inside a loop that runs per item instead of once per walk; leaking flags by never disposing them (revWalk.disposeFlag) in long-lived walks.
Common situations: Long-running server walks reused across many requests that accumulate new flags; plugin/framework code generating flags per user request from a shared walk.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Flag {0} is disposed
- Flag {0} not from this walk
- Ref name is required when commit hash is specified
- Either commit hash, branch or tag should be specified
- Unable to find commit to import build spec (import project:
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/63917a321b803a30.
Report an issue: GitHub.