{"id":"bc5e8bdd0434bbf8","repo":"google/gson","slug":"cannot-parse-value-at-path-in-getpreviouspath","errorCode":null,"errorMessage":"Cannot parse {value}; at path {in.getPreviousPath()}","messagePattern":"Cannot parse (.+?); at path (.+?)","errorType":"exception","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"gson/src/main/java/com/google/gson/ToNumberPolicy.java","lineNumber":93,"sourceCode":"      } else {\n        try {\n          return Long.parseLong(value);\n        } catch (NumberFormatException e) {\n          return parseAsDouble(value, in);\n        }\n      }\n    }\n\n    private Number parseAsDouble(String value, JsonReader in) throws IOException {\n      try {\n        Double d = Double.valueOf(value);\n        if ((d.isInfinite() || d.isNaN()) && !in.isLenient()) {\n          throw new MalformedJsonException(\n              \"JSON forbids NaN and infinities: \" + d + \"; at path \" + in.getPreviousPath());\n        }\n        return d;\n      } catch (NumberFormatException e) {\n        throw new JsonParseException(\n            \"Cannot parse \" + value + \"; at path \" + in.getPreviousPath(), e);\n      }\n    }\n  },\n\n  /**\n   * Using this policy will ensure that numbers will be read as numbers of arbitrary length using\n   * {@link BigDecimal}.\n   */\n  BIG_DECIMAL {\n    @Override\n    public BigDecimal readNumber(JsonReader in) throws IOException {\n      String value = in.nextString();\n      try {\n        return NumberLimits.parseBigDecimal(value);\n      } catch (NumberFormatException e) {\n        throw new JsonParseException(\n            \"Cannot parse \" + value + \"; at path \" + in.getPreviousPath(), e);","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/google/gson/blob/8b8628c65699bc4421696183c62ae0c1b9b281dc/gson/src/main/java/com/google/gson/ToNumberPolicy.java#L75-L111","documentation":"In LAZILY_PARSED_NUMBER, when a numeric literal cannot be parsed by Long.parseLong and the fallback Double.valueOf throws NumberFormatException, Gson wraps it as JsonParseException with the offending literal and reader path. The token looked numeric to the reader but is not a valid Java number.","triggerScenarios":"Numeric tokens with leading +, underscores, hex prefixes, locale-specific groupings, or truncated values; leniently accepted tokens like 1.2.3 reaching Double.valueOf; very malformed numbers slipped through a lenient reader.","commonSituations":"Hand-crafted JSON, locales using thousands separators, porting from Jackson (which may accept +N), corrupted transport truncating digits.","solutions":["Inspect the literal at the reported path and correct the source.","Tighten strictness to STRICT so malformed numbers fail earlier with a clearer message.","Register a custom TypeAdapter for the numeric field that handles the offending format.","Pre-validate numeric fields with a regex if the producer is unreliable."],"exampleFix":"// before\n// JSON: { \"price\": \"1.299,50\" }  (locale grouping)\n\n// after\n// JSON: { \"price\": 1299.50 }\n// or register a custom TypeAdapter stripping separators","handlingStrategy":"try-catch","validationCode":"if (!raw.matches(\"-?(?:0|[1-9]\\\\d*)(?:\\\\.\\\\d+)?(?:[eE][+-]?\\\\d+)?\")) {\n  throw new IllegalArgumentException(\"bad number literal: \" + raw);\n}\n","typeGuard":"boolean isParsableJavaNumber(String s) {\n  try { Double.parseDouble(s); return true; }\n  catch (NumberFormatException ex) { return false; }\n}\n","tryCatchPattern":"try {\n  return policy.readNumber(in);\n} catch (JsonParseException ex) {\n  if (ex.getMessage().startsWith(\"Cannot parse\")) {\n    // log literal + path, then return null or default\n  }\n  throw ex;\n}\n","preventionTips":["Tighten reader strictness to STRICT for fail-fast on malformed numbers.","Validate numeric fields with a regex at the trust boundary.","Normalize locale-specific separators upstream."],"tags":["deserialization","numbers","number-format","malformed-json"],"analyzedSha":"8b8628c65699bc4421696183c62ae0c1b9b281dc","analyzedAt":"2026-08-04T19:12:22.202Z","schemaVersion":2}