{"record":{"id":"f338e2e55880a643","repo":"MuntashirAkon/AppManager","slug":"sign-character-in-wrong-position","errorCode":null,"errorMessage":"Sign character in wrong position","messagePattern":"Sign character in wrong position","errorType":"validation","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/compat/IntegerCompat.java","lineNumber":59,"sourceCode":"            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) {\n            index++;\n            radix = 8;\n        }\n\n        if (nm.startsWith(\"-\", index) || nm.startsWith(\"+\", index)) {\n            throw new NumberFormatException(\"Sign character in wrong position\");\n        }\n\n        return Integer.parseUnsignedInt(nm.substring(index), radix);\n    }\n}\n","sourceCodeStart":41,"sourceCodeEnd":65,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/compat/IntegerCompat.java#L41-L65","documentation":"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.","triggerScenarios":"Calling IntegerCompat.decode with strings like \"0x-1F\", \"-0x+20\", \"10-2\", or any string with an embedded sign character after the prefix position.","commonSituations":"Concatenated/malformed numeric strings from files or IPC; sign accidentally duplicated (\"--5\"); passing hex literals with an internal minus from user input.","solutions":["Validate the string matches ^[+-]?(0[xX#])?[0-9a-fA-F]+$ before decoding.","Strip or normalize stray sign characters at the input boundary.","Catch NumberFormatException and report an invalid-number message.","Use Long.parseLong/BigInteger for formats IntegerCompat.decode does not support."],"exampleFix":"// before\nint v = IntegerCompat.decode(raw); // raw = \"0x-1F\"\n// after\nif (raw.matches(\"[+-]?(0[xX#])?[0-9a-fA-F]+\")) {\n    int v = IntegerCompat.decode(raw);\n} else {\n    throw new NumberFormatException(\"Not a valid integer: \" + raw);\n}","handlingStrategy":"validation","validationCode":"if (!nm.matches(\"[+-]?(0[xX#])?[0-9a-fA-F]+\")) throw new NumberFormatException(\"Invalid integer: \" + nm);","typeGuard":null,"tryCatchPattern":"try {\n    int v = IntegerCompat.decode(nm);\n} catch (NumberFormatException e) {\n    throw new NumberFormatException(\"Malformed integer: \" + nm);\n}","preventionTips":["Regex-validate numeric strings before decode","Normalize signs and radix prefixes at input","Never build numeric strings by raw concatenation"],"tags":["number-format","parsing","sign-character"],"backgroundTag":"invalid-argument-format","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"}