{"record":{"id":"1a9aa7d0fdbd0011","repo":"MuntashirAkon/AppManager","slug":"zero-length-string","errorCode":null,"errorMessage":"Zero length string","messagePattern":"Zero length string","errorType":"validation","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/compat/IntegerCompat.java","lineNumber":35,"sourceCode":"    }\n\n    /**\n     * Return a 0x prefixed unsigned hex.\n     */\n    @NonNull\n    public static String toUnsignedHex(int signedInt) {\n        return \"0x\" + Integer.toHexString(signedInt);\n    }\n\n    /**\n     * Same as {@link Integer#decode(String)} except it allows decoding both signed and unsigned values\n     */\n    public static int decode(@NonNull String nm) throws NumberFormatException {\n        int radix = 10;\n        int index = 0;\n\n        if (nm.length() == 0) {\n            throw new NumberFormatException(\"Zero length string\");\n        }\n        char firstChar = nm.charAt(0);\n        // Handle sign, if present\n        if (firstChar == '-') {\n            // First character is a signed character, use regular decoding\n            return Integer.decode(nm);\n        } else if (firstChar == '+') {\n            index++;\n        }\n\n        // Handle radix specifier, if present\n        if (nm.startsWith(\"0x\", index) || nm.startsWith(\"0X\", index)) {\n            index += 2;\n            radix = 16;\n        } else if (nm.startsWith(\"#\", index)) {\n            index++;\n            radix = 16;\n        } else if (nm.startsWith(\"0\", index) && nm.length() > 1 + index) {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/compat/IntegerCompat.java#L17-L53","documentation":"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.","triggerScenarios":"Calling IntegerCompat.decode(\"\") or with a null-coerced/trimmed-to-empty string, e.g. split() results that yield empty tokens.","commonSituations":"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.","solutions":["Check the string is non-empty before calling decode.","Trim whitespace and reject/redirect empty input at the parsing boundary.","Provide a default value when the input is blank.","Catch NumberFormatException and surface a user-friendly parse error."],"exampleFix":"// before\nint value = IntegerCompat.decode(input.trim());\n// after\nString t = input == null ? \"\" : input.trim();\nint value = t.isEmpty() ? 0 : IntegerCompat.decode(t);","handlingStrategy":"validation","validationCode":"if (nm == null || nm.trim().isEmpty()) throw new IllegalArgumentException(\"Input required\");","typeGuard":null,"tryCatchPattern":"try {\n    int v = IntegerCompat.decode(nm);\n} catch (NumberFormatException e) {\n    v = defaultValue;\n}","preventionTips":["Trim and check emptiness before parsing","Use Optional/default fallbacks at parse boundaries","Validate split() tokens before decode"],"tags":["number-format","parsing","empty-string"],"backgroundTag":"empty-required-field","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}