{"record":{"id":"501021c5ee04f249","repo":"stanfordnlp/CoreNLP","slug":"value-cannot-be-both-true-and-false","errorCode":null,"errorMessage":"Value cannot be both true and false.","messagePattern":"Value cannot be both true and false\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/Trilean.java","lineNumber":29,"sourceCode":"@SuppressWarnings(\"UnusedDeclaration\")\npublic class Trilean implements Serializable {\n  private static final long serialVersionUID = 42L;\n\n  /**\n   * 0 = false\n   * 1 = true\n   * 2 = unknown\n   */\n  private final byte value;\n\n  /**\n   * Construct a new Trilean value.\n   * @param isTrue Set to true if the value is true. Set to false if the value is false or unknown.\n   * @param isFalse Set to true if the value is false. Set to false if the value is true or unknown.\n   */\n  public Trilean(boolean isTrue, boolean isFalse) {\n    if (isTrue && isFalse) {\n      throw new IllegalArgumentException(\"Value cannot be both true and false.\");\n    }\n    if (isTrue) {\n      value = 1;\n    } else if (isFalse) {\n      value = 0;\n    } else {\n      value = 2;\n    }\n  }\n\n  /**\n   * The copy constructor.\n   * @param other The value to copy from.\n   */\n  public Trilean(Trilean other) {\n    this.value = other.value;\n  }\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/Trilean.java#L11-L47","documentation":"The Trilean(boolean isTrue, boolean isFalse) constructor throws IllegalArgumentException when both arguments are true, since a value cannot simultaneously be true and false. This is a fail-fast guard on a contradictory construction request; (false,false) is legal and means UNKNOWN.","triggerScenarios":"new Trilean(true, true) — e.g. deriving the two flags from independent boolean expressions that are not mutually exclusive.","commonSituations":"Translating legacy two-flag state into Trilean where both flags were set; copy-paste errors passing the same boolean variable for both parameters; refactors that removed a mutual-exclusivity check.","solutions":["Ensure the two inputs are mutually exclusive before constructing (assert !(isTrue && isFalse)).","Pass (false,false) to represent unknown instead of (true,true).","Catch IllegalArgumentException and map it to a domain-specific validation error."],"exampleFix":"// before\nTrilean t = new Trilean(isSuccessful, isFailed); // both can be true\n// after\nif (isSuccessful && isFailed) throw new IllegalStateException(\"inconsistent flags\");\nTrilean t = new Trilean(isSuccessful, isFailed);","handlingStrategy":"validation","validationCode":"if (isTrue && isFalse)\n  throw new IllegalArgumentException(\"isTrue and isFalse are mutually exclusive\");\nTrilean t = new Trilean(isTrue, isFalse);","typeGuard":null,"tryCatchPattern":"try {\n  Trilean t = new Trilean(isTrue, isFalse);\n} catch (IllegalArgumentException e) {\n  // treat as UNKNOWN or report inconsistent flags\n}","preventionTips":["Derive isTrue/isFalse from a single tri-state source, not two booleans.","Assert mutual exclusivity at the boundary where flags are produced.","Remember (false,false) means UNKNOWN — do not try to encode it as (true,true)."],"tags":["java","constructor","validation","logic"],"backgroundTag":"invalid-constructor-argument","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"}