pxb1988/dex2jar · error · CantNotFixContentException
#+BBBB
Error message
#+BBBB
What it means
CodeWriter.build21s assembles the 21s format (const/16 and const-wide/16), whose immediate is a signed 16-bit value. For CONST_WIDE_16, if the long value exceeds Short.MAX_VALUE or is below Short.MIN_VALUE, it cannot be stored in the signed 16-bit slot, so CantNotFixContentException with message '#+BBBB' is thrown (the CONST_16 path is guarded by checkContentShort).
Solutions
- Verify the value fits Short range before choosing CONST_WIDE_16; otherwise emit CONST_WIDE_32 or CONST_WIDE.
- Fix the opcode-selection heuristic in visitConstStmt to range-check before narrowing.
- Cast only after the range check: if (v >= Short.MIN_VALUE && v <= Short.MAX_VALUE) use 21s.
- Catch CantNotFixContentException as a fallback trigger to re-emit with a wider opcode.
Example fix
// before emitConst(CONST_WIDE_16, a, 100000L); // after if (v >= Short.MIN_VALUE && v <= Short.MAX_VALUE) emitConst(CONST_WIDE_16, a, v); else emitConst(CONST_WIDE_32, a, v);
Defensive patterns
Strategy: validation
Validate before calling
boolean fitsShort(long v) { return v >= Short.MIN_VALUE && v <= Short.MAX_VALUE; } Try / catch
try {
emitConst(CONST_WIDE_16, a, v);
} catch (CantNotFixContentException e) {
emitConst(CONST_WIDE_32, a, v);
} Prevention
- Range-check against Short.MIN_VALUE/MAX_VALUE before narrowing to 16-bit consts
- Don't classify int values as wide-16 without a range test
- Test constant narrowing at boundary values (-32768, 32767, 32768)
- Preserve a fallback chain: 16 -> 32 -> wide
When it happens
Trigger: visitConstStmt dispatching CONST_WIDE_16 with a long outside -32768..32767, e.g. 100000.
Common situations: Optimizers that try to narrow wide constants to 16-bit forms purely by size heuristics; translators that mislabel int constants as wide without range checks.
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
AI-assisted analysis of pxb1988/dex2jar@b5bda4fb49 (2026-09-08).
Data as JSON: /api/errors/e290aa41aff06d8f.
Report an issue: GitHub.
Appendix: source
Thrown at dex-writer/src/main/java/com/googlecode/d2j/dex/writer/CodeWriter.java:208
}
realV = (int) (v >> 48);
}
b.position(0);
b.put((byte) op.opcode).put((byte) vAA).putShort((short) realV);
return copy(b);
}
// AA|op BBBB
private byte[] build21s(Op op, int vAA, Number value) {
checkRegAA(op, "vAA", vAA);
int realV;
if (op == CONST_16) {
realV = value.intValue();
checkContentShort(op, "#+BBBB", realV);
} else {// CONST_WIDE_16
long v = value.longValue();
if (v > Short.MAX_VALUE || v < Short.MIN_VALUE) {
throw new CantNotFixContentException(op, "#+BBBB", v);
}
realV = (int) v;
}
b.position(0);
b.put((byte) op.opcode).put((byte) vAA).putShort((short) realV);
return copy(b);
}
// AA|op CC|BB
private byte[] build22b(Op op, int vAA, int vBB, int cc) {
checkRegAA(op, "vAA", vAA);
checkRegAA(op, "vBB", vBB);
checkContentByte(op, "#+CC", cc);
b.position(0);
b.put((byte) op.opcode).put((byte) vAA).put((byte) vBB).put((byte) cc);
return copy(b);
}View on GitHub (pinned to b5bda4fb49)