stanfordnlp/CoreNLP · error · IllegalArgumentException

Value cannot be both true and false.

Error message

Value cannot be both true and false.

What it means

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.

Solutions

  1. Ensure the two inputs are mutually exclusive before constructing (assert !(isTrue && isFalse)).
  2. Pass (false,false) to represent unknown instead of (true,true).
  3. Catch IllegalArgumentException and map it to a domain-specific validation error.

Example fix

// before
Trilean t = new Trilean(isSuccessful, isFailed); // both can be true
// after
if (isSuccessful && isFailed) throw new IllegalStateException("inconsistent flags");
Trilean t = new Trilean(isSuccessful, isFailed);
Defensive patterns

Strategy: validation

Validate before calling

if (isTrue && isFalse)
  throw new IllegalArgumentException("isTrue and isFalse are mutually exclusive");
Trilean t = new Trilean(isTrue, isFalse);

Try / catch

try {
  Trilean t = new Trilean(isTrue, isFalse);
} catch (IllegalArgumentException e) {
  // treat as UNKNOWN or report inconsistent flags
}

Prevention

When it happens

Trigger: new Trilean(true, true) — e.g. deriving the two flags from independent boolean expressions that are not mutually exclusive.

Common situations: 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.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/501021c5ee04f249. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/Trilean.java:29

@SuppressWarnings("UnusedDeclaration")
public class Trilean implements Serializable {
  private static final long serialVersionUID = 42L;

  /**
   * 0 = false
   * 1 = true
   * 2 = unknown
   */
  private final byte value;

  /**
   * Construct a new Trilean value.
   * @param isTrue Set to true if the value is true. Set to false if the value is false or unknown.
   * @param isFalse Set to true if the value is false. Set to false if the value is true or unknown.
   */
  public Trilean(boolean isTrue, boolean isFalse) {
    if (isTrue && isFalse) {
      throw new IllegalArgumentException("Value cannot be both true and false.");
    }
    if (isTrue) {
      value = 1;
    } else if (isFalse) {
      value = 0;
    } else {
      value = 2;
    }
  }

  /**
   * The copy constructor.
   * @param other The value to copy from.
   */
  public Trilean(Trilean other) {
    this.value = other.value;
  }

View on GitHub (pinned to 1b7edd19c4)