{"record":{"id":"d8b952fdaf3481dd","repo":"stanfordnlp/CoreNLP","slug":"is-not-a-legal-logprior","errorCode":null,"errorMessage":" is not a legal LogPrior.","messagePattern":" is not a legal LogPrior\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/classify/LogPrior.java","lineNumber":69,"sourceCode":"  }\n\n  public LogPrior(int intPrior) {\n    this(intPrior, 1.0, 0.1);\n  }\n\n  public LogPrior(LogPriorType type) {\n    this(type, 1.0, 0.1);\n  }\n\n  // why isn't this functionality in enum?\n  private static LogPriorType intToType(int intPrior) {\n    LogPriorType[] values = LogPriorType.values();\n    for (LogPriorType val : values) {\n      if (val.ordinal() == intPrior) {\n        return val;\n      }\n    }\n    throw new IllegalArgumentException(intPrior + \" is not a legal LogPrior.\");\n  }\n\n  public LogPrior(int intPrior, double sigma, double epsilon) {\n    this(intToType(intPrior), sigma, epsilon);\n  }\n\n  public LogPrior(LogPriorType type, double sigma, double epsilon) {\n    this.type = type;\n    if (type != LogPriorType.ADAPT) {\n      setSigma(sigma);\n      setEpsilon(epsilon);\n    }\n  }\n\n\n  // this is the C variable in CSFoo's MM paper C = 1/\\sigma^2\n//  private double[] regularizationHyperparameters = null;\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/classify/LogPrior.java#L51-L87","documentation":"LogPrior.intToType converts a legacy integer code to a LogPriorType by matching against enum ordinals. If the integer does not match any enum ordinal, an IllegalArgumentException naming the offending int is thrown. This protects the int-based constructor LogPrior(int, double, double) against stale or out-of-range codes.","triggerScenarios":"Calling new LogPrior(intPrior, sigma, epsilon) with an integer outside 0..LogPriorType.values().length-1, or an integer serialized under an older version of the enum whose ordinal no longer exists.","commonSituations":"Persisted model/config files storing numeric prior codes that no longer match the current enum order after the library was upgraded; hand-written integer constants that don't correspond to any ordinal.","solutions":["Use a valid integer ordinal from LogPriorType.values(), or better, construct with the enum: new LogPrior(LogPriorType.QUADRATIC, sigma, epsilon)","Check whether the int came from a saved config produced with a different library version and re-map it","Iterate LogPriorType.values() to print valid ordinals and pick the right one"],"exampleFix":"// before\nLogPrior prior = new LogPrior(7, 1.0, 0.1);\n// after\nLogPrior prior = new LogPrior(LogPrior.LogPriorType.QUADRATIC, 1.0, 0.1);","handlingStrategy":"type-guard","validationCode":"int n = LogPriorType.values().length;\nif (intPrior < 0 || intPrior >= n)\n  throw new IllegalArgumentException(\"intPrior must be in [0,\" + (n-1) + \"]: \" + intPrior);","typeGuard":"boolean isValidLogPriorInt(int code) {\n  return code >= 0 && code < LogPrior.LogPriorType.values().length;\n}","tryCatchPattern":"try {\n  LogPrior p = new LogPrior(intPrior, sigma, epsilon);\n} catch (IllegalArgumentException e) {\n  LogPrior p = new LogPrior(LogPrior.LogPriorType.QUADRATIC, sigma, epsilon);\n}","preventionTips":["Prefer enum-based constructors over int codes to avoid ordinal drift across versions","When migrating saved configs, re-map integer codes against the current LogPriorType.values()","Never persist raw ordinals; persist the enum name instead"],"tags":["java","illegalargumentexception","enum","serialization"],"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"}