MuntashirAkon/AppManager · error · NumberFormatException

Sign character in wrong position

Error message

Sign character in wrong position

What it means

IntegerCompat.decode throws NumberFormatException("Sign character in wrong position") when, after consuming an optional leading sign and a radix prefix (0x/0#/0), another '-' or '+' appears where digits are expected. A sign is only valid as the very first character.

Solutions

  1. Validate the string matches ^[+-]?(0[xX#])?[0-9a-fA-F]+$ before decoding.
  2. Strip or normalize stray sign characters at the input boundary.
  3. Catch NumberFormatException and report an invalid-number message.
  4. Use Long.parseLong/BigInteger for formats IntegerCompat.decode does not support.

Example fix

// before
int v = IntegerCompat.decode(raw); // raw = "0x-1F"
// after
if (raw.matches("[+-]?(0[xX#])?[0-9a-fA-F]+")) {
    int v = IntegerCompat.decode(raw);
} else {
    throw new NumberFormatException("Not a valid integer: " + raw);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!nm.matches("[+-]?(0[xX#])?[0-9a-fA-F]+")) throw new NumberFormatException("Invalid integer: " + nm);

Try / catch

try {
    int v = IntegerCompat.decode(nm);
} catch (NumberFormatException e) {
    throw new NumberFormatException("Malformed integer: " + nm);
}

Prevention

When it happens

Trigger: Calling IntegerCompat.decode with strings like "0x-1F", "-0x+20", "10-2", or any string with an embedded sign character after the prefix position.

Common situations: Concatenated/malformed numeric strings from files or IPC; sign accidentally duplicated ("--5"); passing hex literals with an internal minus from user input.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/f338e2e55880a643. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/compat/IntegerCompat.java:59

            return Integer.decode(nm);
        } else if (firstChar == '+') {
            index++;
        }

        // Handle radix specifier, if present
        if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
            index += 2;
            radix = 16;
        } else if (nm.startsWith("#", index)) {
            index++;
            radix = 16;
        } else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
            index++;
            radix = 8;
        }

        if (nm.startsWith("-", index) || nm.startsWith("+", index)) {
            throw new NumberFormatException("Sign character in wrong position");
        }

        return Integer.parseUnsignedInt(nm.substring(index), radix);
    }
}

View on GitHub (pinned to 0152f468fc)