pxb1988/dex2jar · error · CantNotFixContentException
#+BBBB0000
Error message
#+BBBB0000
What it means
CodeWriter.build21h assembles the 21h instruction format (const/const-wide/high16), which stores only the high 16 bits of the constant; the low bits must be zero. If a CONST_HIGH16 value has any non-zero low 16 bits, the instruction cannot represent it exactly, so CantNotFixContentException is thrown with message '#+BBBB0000'.
Solutions
- Mask-check the constant: only use CONST_HIGH16 when (v & 0xFFFF) == 0, otherwise emit CONST_32 (CONST).
- Change the emitted opcode to CONST (31i format) for arbitrary 32-bit constants.
- Fix the opcode-selection logic in visitConstStmt/optimizer to test low bits before choosing 21h.
- Catch CantNotFixContentException around const emission and fall back to the wide format.
Example fix
// before: assumes magnitude implies encodable emitConst(CONST_HIGH16, a, 0x12345678); // after: choose format by value shape if ((v & 0xFFFF) == 0) emitConst(CONST_HIGH16, a, v); else emitConst(CONST, a, v);
Defensive patterns
Strategy: validation
Validate before calling
boolean fitsConstHigh16(int v) { return (v & 0xFFFF) == 0; } Try / catch
try {
emitConst(CONST_HIGH16, a, v);
} catch (CantNotFixContentException e) {
emitConst(CONST, a, v); // fall back to full 32-bit const
} Prevention
- Check (v & 0xFFFF) == 0 before selecting const/high16
- Never pick const opcodes by magnitude alone; test the actual bit pattern
- Unit-test constant narrowing with values like 0x12345678
- Keep a fallback path to the full-width const opcode
When it happens
Trigger: visitConstStmt dispatching a CONST_HIGH16 op whose int value has (v & 0xFFFF) != 0, e.g. const/high16 with literal 0x12345678.
Common situations: Constant folding or translation pipelines that select the high16 opcode based only on magnitude without checking the low bits are zero; writing optimizers that replace const with const/high16 as a size optimization incorrectly.
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/1bc49b995dd13319.
Report an issue: GitHub.
Appendix: source
Thrown at dex-writer/src/main/java/com/googlecode/d2j/dex/writer/CodeWriter.java:182
// B|A|op
private byte[] build12x(Op op, int vA, int vB) {
checkRegA(op, "vA", vA);
checkRegA(op, "vB", vB);
b.position(0);
b.put((byte) op.opcode).put((byte) ((vA & 0xF) | (vB << 4)));
return copy(b);
}
// AA|op BBBB
private byte[] build21h(Op op, int vAA, Number value) {
checkRegAA(op, "vAA", vAA);
int realV;
if (op == CONST_HIGH16) { // op vAA, #+BBBB0000
int v = ((Number) value).intValue();
if ((v & 0xFFFF) != 0) {
throw new CantNotFixContentException(op, "#+BBBB0000", v);
}
realV = v >> 16;
} else { // CONST_WIDE_HIGH16 //op vAA, #+BBBB000000000000
long v = ((Number) value).longValue();
if ((v & 0x0000FFFFffffFFFFL) != 0) {
throw new CantNotFixContentException(op, "#+BBBB000000000000", v);
}
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);View on GitHub (pinned to b5bda4fb49)