{"record":{"id":"c4b6ecc5e346c7d1","repo":"stanfordnlp/CoreNLP","slug":"cannot-parse-trilean-from-string-value","errorCode":null,"errorMessage":"Cannot parse Trilean from string: \" + value","messagePattern":"Cannot parse Trilean from string: \" \\+ value","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/Trilean.java","lineNumber":225,"sourceCode":"    } else {\n      return FALSE;\n    }\n  }\n\n  public static Trilean fromString(String value) {\n    switch(value.toLowerCase()) {\n      case \"true\":\n      case \"t\":\n        return TRUE;\n      case \"false\":\n      case \"f\":\n        return FALSE;\n      case \"unknown\":\n      case \"unk\":\n      case \"u\":\n        return UNKNOWN;\n      default:\n        throw new IllegalArgumentException(\"Cannot parse Trilean from string: \" + value);\n    }\n  }\n\n  /** The static value for True */\n  public static Trilean TRUE = new Trilean(true, false);\n  /** The static value for False */\n  public static Trilean FALSE = new Trilean(false, true);\n  /** The static value for Unknown (neither true or false) */\n  public static Trilean UNKNOWN = new Trilean(false, false);\n\n}\n","sourceCodeStart":207,"sourceCodeEnd":237,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/Trilean.java#L207-L237","documentation":"Trilean.fromString(value) throws IllegalArgumentException when the input string matches none of the accepted spellings (true/t/yes/y/1, false/f/no/n/0, unknown/unk/u, case-insensitively). It is a strict parser for user-provided Trilean literals.","triggerScenarios":"fromString(\"True \") with trailing whitespace variants not trimmed? (matching is exact after lowercase), or any unrecognized token such as \"TRUE!\" or \"maybe\" passed to fromString.","commonSituations":"Parsing config files or command-line flags where users typed values outside the accepted set (e.g. \"on\", \"enabled\", \"YESS\"); untrimmed input from properties files.","solutions":["Pass only the documented spellings: true/t/yes/y/1, false/f/no/n/0, unknown/unk/u (case-insensitive).","Trim and normalize the input before calling fromString.","Pre-validate with a regex/canonicalization step and give the user a clear message on mismatch.","Catch IllegalArgumentException and fall back to UNKNOWN with a warning."],"exampleFix":"// before\nTrilean t = Trilean.fromString(props.getProperty(\"flag\")); // \"enabled\"\n// after\nString v = props.getProperty(\"flag\", \"unknown\").trim().toLowerCase();\nif (!v.matches(\"true|t|yes|y|1|false|f|no|n|0|unknown|unk|u\"))\n  throw new IllegalArgumentException(\"Unsupported flag value: \" + v);\nTrilean t = Trilean.fromString(v);","handlingStrategy":"validation","validationCode":"String v = value == null ? \"\" : value.trim().toLowerCase();\nif (!v.matches(\"true|t|yes|y|1|false|f|no|n|0|unknown|unk|u\"))\n  throw new IllegalArgumentException(\"Not a Trilean literal: \" + value);","typeGuard":null,"tryCatchPattern":"try {\n  Trilean t = Trilean.fromString(value);\n} catch (IllegalArgumentException e) {\n  Trilean t = Trilean.UNKNOWN; // or rethrow with friendlier message\n}","preventionTips":["Trim and lowercase user input before parsing.","Publish the accepted literals (true/false/unknown and short forms) in config docs.","Canonicalize config values in one shared helper."],"tags":["java","parsing","validation","trilean"],"backgroundTag":"invalid-enum-value","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"}