stanfordnlp/CoreNLP · error · IllegalStateException

Variable : Can't have as assignment ( ) that is out of…

Error message

Variable ${n}: Can't have as assignment (${assignment}) that is out of bounds for dimension size (${deterministic.length})

What it means

CliqueTree.messagePassing builds a deterministic indicator vector for an observed variable using its observed assignment as an index into the factor's dimension. If the parsed VARIABLE_OBSERVED_VALUE metadata exceeds the dimension size, the index would fall outside the array, so an IllegalStateException is thrown.

Solutions

  1. Verify the observed value is within [0, dimensionSize-1] for the variable and fix the input metadata.
  2. Remember assignments are 0-based; subtract 1 if your data is 1-based.
  3. Catch IllegalStateException during calculateMarginals/result/mapMarginals and report the offending variable to the data pipeline.

Example fix

// before
metaData.put("OBSERVED", "2"); // binary variable
// after
metaData.put("OBSERVED", "1"); // valid 0-based index
Defensive patterns

Strategy: validation

Validate before calling

int dim = model.getVariableMetaDataByReference(varId).size(); // or featuresTable dimension
int obs = Integer.parseInt(meta.get("OBSERVED"));
if (obs < 0 || obs >= dim) throw new IllegalArgumentException("observed value out of range for var " + varId);

Type guard

boolean isValidAssignment(int assignment, int dimensionSize) { return assignment >= 0 && assignment < dimensionSize; }

Try / catch

try { marginals = cliqueTree.calculateMarginals(); } catch (IllegalStateException e) { if (e.getMessage().contains("out of bounds")) { /* fix conditioning metadata */ } else throw e; }

Prevention

When it happens

Trigger: Setting variable metadata VARIABLE_OBSERVED_VALUE (e.g. via Conditioning) to an integer >= the variable's number of states/dimension size before computing marginals.

Common situations: Data files assigning observed values like '2' to binary variables; off-by-one usage where users pass 1-based indices into 0-based assignment space (assignment == length already triggers because the check uses >, but length-sized value for a length dimension writes at index length in the 0..length-1 space when equal... the check rejects assignment > length).

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/loglinear/inference/CliqueTree.java:542

      cachedCliqueList = cliques;
      cachedMessages = messages;
      cachedBackwardPassedMessages = backwardPassedMessages;
    }

    // Calculate final marginals for each variable

    double[][] marginals = new double[maxVar + 1][];

    // Include observed variables as deterministic

    for (GraphicalModel.Factor fac : model.factors) {
      for (int i = 0; i < fac.neigborIndices.length; i++) {
        int n = fac.neigborIndices[i];
        if (model.getVariableMetaDataByReference(n).containsKey(VARIABLE_OBSERVED_VALUE)) {
          double[] deterministic = new double[fac.featuresTable.getDimensions()[i]];
          int assignment = Integer.parseInt(model.getVariableMetaDataByReference(n).get(VARIABLE_OBSERVED_VALUE));
          if (assignment > deterministic.length) {
            throw new IllegalStateException("Variable " + n + ": Can't have as assignment (" + assignment + ") that is out of bounds for dimension size (" + deterministic.length + ")");
          }
          deterministic[assignment] = 1.0;
          marginals[n] = deterministic;
        }
      }
    }

    Map<GraphicalModel.Factor, TableFactor> jointMarginals = new IdentityHashMap<>();

    if (marginalize == MarginalizationMethod.SUM && includeJointMarginalsAndPartition) {
      boolean[] partitionIncludesTrees = new boolean[treeIndex + 1];
      double[] treePartitionFunctions = new double[treeIndex + 1];

      for (int i = 0; i < cliques.length; i++) {
        TableFactor convergedClique = cliques[i];

        for (int j = 0; j < cliques.length; j++) {
          if (i == j) continue;

View on GitHub (pinned to 1b7edd19c4)