JetBrains/intellij-community · error · NullPointerException
Access by hierarchical idx %s failed: Encountered a null ele
Error message
Access by hierarchical idx %s failed: Encountered a null element by path %s.
What it means
extractValueByHierarchicalIndex throws NullPointerException when an intermediate (non-final) level of the path resolves to null. A null is only acceptable at the last level (returned as null value); a null before more levels remain means the nesting structure is shallower than the path demands.
Source
Thrown at grid/core-impl/src/datagrid/HierarchicalColumnsDataGridModel.java:445
for (int i = 0; i < hierarchicalIdx.length; ++i) {
int idx = hierarchicalIdx[i];
if (idx < 0 || idx >= data.length) {
throw new IndexOutOfBoundsException(
String.format(
"Access by hierarchical idx %s failed: Index out of bounds at element by path %s",
Arrays.toString(hierarchicalIdx),
Arrays.toString(Arrays.copyOfRange(hierarchicalIdx, 0, i))
)
);
}
result = data[idx];
if (result == null && i == hierarchicalIdx.length - 1) {
return null;
}
else if (result == null) {
throw new NullPointerException(
String.format(
"Access by hierarchical idx %s failed: Encountered a null element by path %s.",
Arrays.toString(hierarchicalIdx),
Arrays.toString(Arrays.copyOfRange(hierarchicalIdx, 0, i))
)
);
}
if (result instanceof Object[] vals) {
data = vals;
continue;
}
if (result instanceof List<?> vals) {
data = vals.toArray();
continue;
}
View on GitHub (pinned to be881553f2)
Solutions
- Treat null intermediates as absent values: pre-check levels and short-circuit to null when a non-final level is null.
- Make the data producer materialize empty arrays instead of nulls for missing intermediate levels.
- Align column-hierarchy depth with the deepest row actually present, or prune columns for levels that never exist.
Example fix
// before
Object v = getValue(row, path); // throws NPE on null intermediate
// after
Object v = hasCompletePath(row, path) ? getValue(row, path) : null;
// helper
static boolean hasCompletePath(GridRow row, int[] path) {
Object[] data = GridRow.getValues(row);
for (int i = 0; i < path.length - 1; i++) {
if (path[i] >= data.length) return false;
Object o = data[path[i]];
if (!(o instanceof Object[] a)) return false;
data = a;
}
return true;
} Defensive patterns
Strategy: validation
Validate before calling
static boolean pathFullyMaterialized(Object[] values, int[] path) {
Object[] data = values;
for (int i = 0; i < path.length - 1; i++) {
if (path[i] >= data.length) return false;
Object o = data[path[i]];
if (!(o instanceof Object[] a)) return false;
data = a;
}
return true;
}
Object v = pathFullyMaterialized(GridRow.getValues(row), path) ? getValue(row, path) : null; Prevention
- Materialize empty arrays instead of nulls for absent intermediate levels at ingestion time.
- Keep column-hierarchy depth no greater than the shallowest row's real nesting, or treat null intermediates as absent values.
When it happens
Trigger: Path [0, 1, 2] where data[0][1] is null but the path expects one more level; rows whose nested sub-arrays are absent for optional columns.
Common situations: Sparse hierarchical data (optional nested sections serialized as null); a column hierarchy deeper than some rows' actual value nesting.
Related errors
- Row %d access failed: %s
- Access by hierarchical idx %s failed: Index out of bounds at
- Row %d failed: hierarchicalIdx cannot be null
- Row %d access failed: hierarchicalIdx cannot be empty
- Access by hierarchical idx %s failed: Encountered an unexpec
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/c70812a58880c445.
Report an issue: GitHub.