stanfordnlp/CoreNLP · error · NullPointerException
Image does not have height
Error message
Image does not have height
What it means
SceneGraphImage.readFromJSON reads image metadata from a JSON object. It calls obj.getInt("height") and then checks the result; since JsonObject.getInt never returns null, the guard is effectively a schema assertion — but when the "height" key is absent/invalid the resulting failure surfaces as a NullPointerException with message "Image does not have height" at src/edu/stanford/nlp/scenegraph/image/SceneGraphImage.java:89. It means the input JSON is missing the required height field.
Solutions
- Add the required "height" integer field to the JSON record.
- Re-download the complete image metadata from the dataset source.
- Pre-validate the JSON with containsKey/isNull before calling readFromJSON and skip or repair bad records.
- Supply a default height from a separate metadata source if only dimensions are missing.
Example fix
// before
SceneGraphImage img = SceneGraphImage.readFromJSON(obj); // NPE, no height
// after
if (!obj.containsKey("height") || obj.isNull("height")) {
obj.put("height", imageHeightLookup(obj.getInt("id")));
}
SceneGraphImage img = SceneGraphImage.readFromJSON(obj); Defensive patterns
Strategy: validation
Validate before calling
if (!obj.containsKey("height") || obj.isNull("height") || !obj.containsKey("width") || obj.isNull("width")) {
throw new IllegalArgumentException("Image record missing dimensions: " + obj.getInt("id"));
} Type guard
boolean hasDimensions(JsonObject o) {
return o.containsKey("height") && !o.isNull("height") && o.containsKey("width") && !o.isNull("width");
} Try / catch
try {
return SceneGraphImage.readFromJSON(obj);
} catch (RuntimeException e) {
log.warn("Skipping image without height: " + obj.getInt("id"));
return null;
} Prevention
- Validate dataset JSON against the SceneGraphImage schema in preprocessing
- Never strip metadata fields when slimming dataset files
- Fail fast on the first malformed record in a dry-run pass
When it happens
Trigger: Calling readFromJSON (directly or via SceneGraphImage.readFromFile/img) on a JSON object without an integer "height" key, or with "height": null.
Common situations: Scene-graph dataset files trimmed to only region/relationship data; custom JSON built by scripts that omit metadata fields; partial downloads of Visual Genome image metadata.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Image does not have width
- We need at least 2 extractors for ExtractorMerger to make se
- Too many columns: <columnI>/<numColumns> (offset: <offset>)
- Too few columns: <columnI>/<numColumns> (offset: <offset>)
- Sentence.toSentence: lengths differ
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/15028f9e6c2b0b3d.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/scenegraph/image/SceneGraphImage.java:89
for (JsonObject object: objects.getValuesAs(JsonObject.class)) {
img.objects.add(SceneGraphImageObject.fromJSONObject(img, object));
}
JsonArray attributes = obj.getJsonArray("attributes");
for (JsonObject object: attributes.getValuesAs(JsonObject.class)) {
img.addAttribute(SceneGraphImageAttribute.fromJSONObject(img, object));
}
JsonArray relationships = obj.getJsonArray("relationships");
for (JsonObject relation: relationships.getValuesAs(JsonObject.class)) {
img.addRelationship(SceneGraphImageRelationship.fromJSONObject(img, relation));
}
img.id = obj.getInt("id");
Number height = obj.getInt("height");
Number width = obj.getInt("width");
if (height == null) {
throw new NullPointerException("Image does not have height");
}
if (width == null) {
throw new NullPointerException("Image does not have width");
}
img.height = height.intValue();
img.width = width.intValue();
img.url = obj.getString("url");
return img;
} catch (RuntimeException e) {
throw new RuntimeException("Couldn't parse \n" + json, e);
}
}
@SuppressWarnings("unchecked")
public String toJSON() {
JsonObjectBuilder json = Json.createObjectBuilder();View on GitHub (pinned to 1b7edd19c4)