MuntashirAkon/AppManager · error · NumberFormatException

Zero length string

Error message

Zero length string

What it means

IntegerCompat.decode parses strings like "-0x1F" or "017" that Integer.decode would reject due to overflow/behavioral differences. It throws NumberFormatException("Zero length string") immediately when the input string is empty (nm.length() == 0), because there are no characters to decode.

Solutions

  1. Check the string is non-empty before calling decode.
  2. Trim whitespace and reject/redirect empty input at the parsing boundary.
  3. Provide a default value when the input is blank.
  4. Catch NumberFormatException and surface a user-friendly parse error.

Example fix

// before
int value = IntegerCompat.decode(input.trim());
// after
String t = input == null ? "" : input.trim();
int value = t.isEmpty() ? 0 : IntegerCompat.decode(t);
Defensive patterns

Strategy: validation

Validate before calling

if (nm == null || nm.trim().isEmpty()) throw new IllegalArgumentException("Input required");

Try / catch

try {
    int v = IntegerCompat.decode(nm);
} catch (NumberFormatException e) {
    v = defaultValue;
}

Prevention

When it happens

Trigger: Calling IntegerCompat.decode("") or with a null-coerced/trimmed-to-empty string, e.g. split() results that yield empty tokens.

Common situations: Parsing user-supplied or file-based numeric strings without trimming; splitting a value like "a,,b" and decoding the empty element; CSV lines with missing numeric fields.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

    }

    /**
     * Return a 0x prefixed unsigned hex.
     */
    @NonNull
    public static String toUnsignedHex(int signedInt) {
        return "0x" + Integer.toHexString(signedInt);
    }

    /**
     * Same as {@link Integer#decode(String)} except it allows decoding both signed and unsigned values
     */
    public static int decode(@NonNull String nm) throws NumberFormatException {
        int radix = 10;
        int index = 0;

        if (nm.length() == 0) {
            throw new NumberFormatException("Zero length string");
        }
        char firstChar = nm.charAt(0);
        // Handle sign, if present
        if (firstChar == '-') {
            // First character is a signed character, use regular decoding
            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) {

View on GitHub (pinned to 0152f468fc)