stanfordnlp/CoreNLP · error · NullPointerException

object did not have bbox field

Error message

object did not have bbox field

What it means

SceneGraphImageObject.fromJSONObject parses a JSON object describing one object in a Stanford Scene Graph Image. It requires the JSON to contain a "bbox" key holding the bounding box (h, w, x, y); when the key is absent the parser throws a NullPointerException so malformed data fails fast instead of producing an object with a null/invalid box.

Solutions

  1. Open the JSON file and add a "bbox" object with integer h, w, x, y to every object entry, or remove/fix the malformed object
  2. Validate the JSON against the SceneGraphImage schema before loading (check each object has bbox)
  3. If the data legitimately lacks boxes, skip such objects by pre-filtering the JSON array before calling fromJSON
  4. Upstream-fix the annotation exporter so it always emits bbox

Example fix

// before (input JSON)
{"objects":[{"object_id":1,"names":["dog"]}]}
// after
{"objects":[{"object_id":1,"names":["dog"],"bbox":{"h":120,"w":90,"x":10,"y":30}}]}
Defensive patterns

Strategy: validation

Validate before calling

boolean hasBbox(JsonObject obj) {
  JsonObject bbox = obj.getJsonObject("bbox");
  return bbox != null && bbox.containsKey("h") && bbox.containsKey("w")
      && bbox.containsKey("x") && bbox.containsKey("y");
}

Type guard

// Java: check Json nullability before use
JsonObject bbox = obj.getJsonObject("bbox");
if (bbox == null) { throw new IllegalArgumentException("missing bbox in " + obj); }

Prevention

When it happens

Trigger: Calling SceneGraphImage.fromJSON (or related loaders) on a JSON file/string whose objects array contains an object entry missing the "bbox" field, e.g. hand-edited region descriptions, partially converted annotations, or a different annotation schema version.

Common situations: Working with legacy or third-party Visual Genome dumps that omit bbox for some objects; annotations exported by a tool that only writes region text; JSON files truncated or written by an older schema.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/scenegraph/image/SceneGraphImageObject.java:59

  @SuppressWarnings("unchecked")
  public static SceneGraphImageObject fromJSONObject(SceneGraphImage img, JsonObject obj) {

    List<String> names = SceneGraphImageUtils.getJsonStringList(obj, "names");
    JsonArray labelArrays = obj.getJsonArray("labels");
    List<List<CoreLabel>> labelsList = null;
    if (labelArrays != null) {
      labelsList = Generics.newArrayList(labelArrays.size());
      for (JsonArray arr : labelArrays.getValuesAs(JsonArray.class)) {
        List<CoreLabel> tokens = Generics.newArrayList(arr.size());
        for (JsonString str : arr.getValuesAs(JsonString.class)) {
          tokens.add(SceneGraphImageUtils.labelFromString(str.getString()));
        }
        labelsList.add(tokens);
      }
    }
    JsonObject boundingBoxObj = obj.getJsonObject("bbox");
    if (boundingBoxObj == null) {
      throw new NullPointerException("object did not have bbox field");
    }

    int h = boundingBoxObj.getInt("h");
    int w = boundingBoxObj.getInt("w");
    int x = boundingBoxObj.getInt("x");
    int y = boundingBoxObj.getInt("y");

    SceneGraphImageBoundingBox boundingBox = new SceneGraphImageBoundingBox(h, w, x, y);

    return new SceneGraphImageObject(boundingBox, names, labelsList);
  }

  @SuppressWarnings("unchecked")
  public JsonObject toJSONObject(SceneGraphImage sceneGraphImage) {
    JsonObjectBuilder obj = Json.createObjectBuilder();

    JsonObjectBuilder bbox = Json.createObjectBuilder();
    bbox.add("h", this.boundingBox.h);

View on GitHub (pinned to 1b7edd19c4)