{"record":{"id":"8d19daefeb55eeba","repo":"stanfordnlp/CoreNLP","slug":"image-does-not-have-width","errorCode":null,"errorMessage":"Image does not have width","messagePattern":"Image does not have width","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/scenegraph/image/SceneGraphImage.java","lineNumber":92,"sourceCode":"\n      JsonArray attributes = obj.getJsonArray(\"attributes\");\n      for (JsonObject object: attributes.getValuesAs(JsonObject.class)) {\n        img.addAttribute(SceneGraphImageAttribute.fromJSONObject(img, object));\n      }\n\n      JsonArray relationships = obj.getJsonArray(\"relationships\");\n      for (JsonObject relation: relationships.getValuesAs(JsonObject.class)) {\n        img.addRelationship(SceneGraphImageRelationship.fromJSONObject(img, relation));\n      }\n\n      img.id = obj.getInt(\"id\");\n      Number height = obj.getInt(\"height\");\n      Number width = obj.getInt(\"width\");\n      if (height == null) {\n        throw new NullPointerException(\"Image does not have height\");\n      }\n      if (width == null) {\n        throw new NullPointerException(\"Image does not have width\");\n      }\n      img.height = height.intValue();\n      img.width = width.intValue();\n\n      img.url = obj.getString(\"url\");\n\n      return img;\n    } catch (RuntimeException e) {\n      throw new RuntimeException(\"Couldn't parse \\n\" + json, e);\n    }\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  public String toJSON() {\n    JsonObjectBuilder json = Json.createObjectBuilder();\n    json.add(\"id\", this.id);\n    json.add(\"height\", this.height);\n    json.add(\"width\", this.width);","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/scenegraph/image/SceneGraphImage.java#L74-L110","documentation":"SceneGraphImage.readFromJSON requires a \"width\" integer field; when it is absent the NullPointerException \"Image does not have width\" is thrown at src/edu/stanford/nlp/scenegraph/image/SceneGraphImage.java:92. Like the height check, it enforces that the JSON image record contains complete dimension metadata.","triggerScenarios":"Calling readFromJSON on a JSON object missing \"width\" or with \"width\": null — typically the same malformed/partial records that lack \"height\".","commonSituations":"Custom scene-graph JSON exports omitting width; records where dimensions were stripped to save space; dataset preprocessing bugs.","solutions":["Add the \"width\" integer field to the JSON record.","Re-download complete metadata from the dataset source.","Pre-validate containsKey(\"width\")/isNull before parsing and repair or skip bad records.","Fill width from an external image-metadata lookup when only dimensions are missing."],"exampleFix":"// before\nSceneGraphImage img = SceneGraphImage.readFromJSON(obj); // NPE, no width\n// after\nif (!obj.containsKey(\"width\") || obj.isNull(\"width\")) {\n  obj.put(\"width\", imageWidthLookup(obj.getInt(\"id\")));\n}\nSceneGraphImage img = SceneGraphImage.readFromJSON(obj);","handlingStrategy":"validation","validationCode":"if (!obj.containsKey(\"width\") || obj.isNull(\"width\")) {\n  throw new IllegalArgumentException(\"Image record missing width: \" + obj.getInt(\"id\"));\n}","typeGuard":"boolean hasWidth(JsonObject o) { return o.containsKey(\"width\") && !o.isNull(\"width\"); }","tryCatchPattern":"try {\n  return SceneGraphImage.readFromJSON(obj);\n} catch (RuntimeException e) {\n  log.warn(\"Skipping image without width: \" + obj.getInt(\"id\"));\n  return null;\n}","preventionTips":["Include both height and width in generated JSON exports","Validate required keys with json-schema before loading","Fill missing dimensions from image metadata during preprocessing"],"tags":["java","json","validation","missing-field"],"backgroundTag":"missing-required-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}