{"record":{"id":"1f2ce48eefe3348e","repo":"stanfordnlp/CoreNLP","slug":"bad-number-put-into-wordtonumber-word-is","errorCode":null,"errorMessage":"Bad number put into wordToNumber.  Word is: \\\"\" + input + \"\\\", originally part of \\\"\" + originalString + \"\\\", piece # \" + curIndex","messagePattern":"Bad number put into wordToNumber\\.  Word is: \\\\\"\" \\+ input \\+ \"\\\\\", originally part of \\\\\"\" \\+ originalString \\+ \"\\\\\", piece # \" \\+ curIndex","errorType":"exception","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/NumberNormalizer.java","lineNumber":287,"sourceCode":"            break;\n          default:\n            // unknown magnitude! Ignore it.\n            break;\n        }\n        if (digitsPattern.matcher(numPart).matches()) {\n          return Long.parseLong(numPart) * magnitude;\n        } else {\n          return Double.parseDouble(numPart) * magnitude;\n        }\n      } else {\n        if (digitsPattern.matcher(numPart).matches()) {\n          return Long.parseLong(numPart);\n        } else {\n          return Double.parseDouble(numPart);\n        }\n      }\n    } else{\n      throw new NumberFormatException(\"Bad number put into wordToNumber.  Word is: \\\"\" + input + \"\\\", originally part of \\\"\" + originalString + \"\\\", piece # \" + curIndex);\n    }\n\n  }\n\n\n  /**\n   * Fairly generous utility function to convert a string representing\n   * a number (hopefully) to a Number.\n   * Assumes that something else has somehow determined that the string\n   * makes ONE suitable number.\n   * The value of the number is determined by:\n   * 0. Breaking up the string into pieces using whitespace\n   *    (stuff like \"and\", \"-\", \",\" is turned into whitespace);\n   * 1. Determining the numeric value of the pieces;\n   * 2. Finding the numeric value of each piece;\n   * 3. Combining the pieces together to form the overall value:\n   *    a. Find the largest component and its value (X),\n   *    b. Let B = overall value of pieces to the left (recursive),","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/NumberNormalizer.java#L269-L305","documentation":"NumberNormalizer.parseNumberPart converts a numeric word piece via Long.parseLong/Double.parseDouble after normalizing commas and trailing 's'; if the piece matches no numeric pattern (numPattern / digitsPatternExtended) it throws NumberFormatException naming the input, the original string, and the piece index. It is a guard for non-numeric text routed into numeric parsing inside wordToNumber.","triggerScenarios":"wordToNumber splitting a string and delegating a piece to parseNumberPart that contains characters beyond the accepted numeric formats (e.g. '1st2', '1.2.3', currency symbols, 'x100').","commonSituations":"Normalizing extracted mention text containing mixed alphanumeric tokens (like '3x' or 'one-two'), noisy OCR/entity text, or regex changes in numPattern across CoreNLP versions altering which strings parse.","solutions":["Pre-clean the token so only numeric pieces (digits, commas, periods, optional trailing 's') reach wordToNumber.","Catch NumberFormatException around the normalizer call and treat the token as non-numeric.","Check the exact failing word/piece index reported in the message and strip unexpected characters before calling."],"exampleFix":"// before\nNumber n = NumberNormalizer.wordToNumber(\"3rd-place\");\n// after\nString token = \"3rd-place\".split(\"-\")[0]; // pass only numeric piece\nNumber n = NumberNormalizer.wordToNumber(token);","handlingStrategy":"try-catch","validationCode":"static boolean isParseableNumberPiece(String s) {\n  return s != null && s.replaceAll(\"[,]\", \"\").matches(\"\\\\d+(\\\\.\\\\d+)?s?\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Number n = NumberNormalizer.wordToNumber(input);\n} catch (NumberFormatException e) {\n  Number n = null; // treat token as non-numeric\n}","preventionTips":["Pass only clean numeric tokens; strip letters, currency, and stray punctuation first.","Catch NumberFormatException at mention-normalization boundaries.","Log the failing word from the message to fix upstream tokenization."],"tags":["nlp","number-format","parsing","java"],"backgroundTag":"invalid-argument-format","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}