stanfordnlp/CoreNLP · error · IllegalArgumentException
Input array with 0 columns
Error message
Input array with 0 columns
What it means
ConvertModels.toMatrix rejects input where the first row has zero columns (in.get(0).size()==0), throwing IllegalArgumentException('Input array with 0 columns'). A matrix with rows but no columns cannot be dimensioned.
Solutions
- Ensure each inner list has at least one element before calling toMatrix
- Check the upstream feature extraction for rows that produce zero features
- Inspect the source model serialization for empty vectors
Example fix
// before
SimpleMatrix m = ConvertModels.toMatrix(rows);
// after
if (rows.isEmpty() || rows.get(0).isEmpty()) { throw new IllegalStateException("row has 0 columns"); }
SimpleMatrix m = ConvertModels.toMatrix(rows); Defensive patterns
Strategy: validation
Validate before calling
if (rows == null || rows.isEmpty() || rows.get(0).isEmpty()) {
throw new IllegalArgumentException("toMatrix requires at least one column in row 0");
} Type guard
static boolean hasColumns(java.util.List<java.util.List<Double>> rows) {
return rows != null && !rows.isEmpty() && rows.get(0) != null && !rows.get(0).isEmpty();
} Try / catch
try {
SimpleMatrix m = ConvertModels.toMatrix(rows);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("0 columns")) {
throw new IllegalStateException("model rows have no features; check feature extraction", e);
}
throw e;
} Prevention
- Reject empty inner rows at feature-extraction time
- Sanity-check the first row of any List<List<Double>> built from deserialized models
- Log feature counts per entry to catch all-empty rows early
When it happens
Trigger: Calling toMatrix with a non-empty outer list whose first element is an empty List<Double>, e.g. antecedentMatrix/anaphorMatrix built from a model with no features per entry.
Common situations: Model files serialized with empty per-row vectors, or feature-extraction producing empty lists for every entry during model conversion.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Input array with 0 rows
- Input array with uneven columns
- Attempt to make ObjectBank with empty file list
- Can't parse a zero-length sentence!
- No matching files
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/b6981906ad0067e0.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/neural/ConvertModels.java:83
return out;
}
public static List<List<List<Double>>> fromTensor(SimpleTensor in) {
List<List<List<Double>>> out = new ArrayList<>();
for (int i = 0; i < in.numSlices(); ++i) {
out.add(fromMatrix(in.getSlice(i)));
}
return out;
}
public static SimpleMatrix toMatrix(List<List<Double>> in) {
if (in.size() == 0) {
throw new IllegalArgumentException("Input array with 0 rows");
}
if (in.get(0).size() == 0) {
throw new IllegalArgumentException("Input array with 0 columns");
}
for (int i = 1; i < in.size(); ++i) {
if (in.get(i).size() != in.get(0).size()) {
throw new IllegalArgumentException("Input array with uneven columns");
}
}
SimpleMatrix out = new SimpleMatrix(in.size(), in.get(0).size());
for (int i = 0; i < in.size(); ++i) {
List<Double> row = in.get(i);
for (int j = 0; j < row.size(); ++j) {
out.set(i, j, row.get(j));
}
}
return out;
}
View on GitHub (pinned to 1b7edd19c4)