{"record":{"id":"1ab636af12cb74e4","repo":"google/gson","slug":"value-null","errorCode":null,"errorMessage":"value == null","messagePattern":"value == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java","lineNumber":112,"sourceCode":"  @Override\n  public V get(Object key) {\n    Node<K, V> node = findByObject(key);\n    return node != null ? node.value : null;\n  }\n\n  @Override\n  public boolean containsKey(Object key) {\n    return findByObject(key) != null;\n  }\n\n  @CanIgnoreReturnValue\n  @Override\n  public V put(K key, V value) {\n    if (key == null) {\n      throw new NullPointerException(\"key == null\");\n    }\n    if (value == null && !allowNullValues) {\n      throw new NullPointerException(\"value == null\");\n    }\n    Node<K, V> created = find(key, true);\n    V result = created.value;\n    created.value = value;\n    return result;\n  }\n\n  @Override\n  public void clear() {\n    root = null;\n    size = 0;\n    modCount++;\n\n    // Clear iteration order\n    Node<K, V> header = this.header;\n    header.next = header.prev = header;\n  }\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/google/gson/blob/310ac341f2f92a454b229bf21f70d2d18b2b6db7/gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java#L94-L130","documentation":"LinkedTreeMap can be constructed in a mode that disallows null values (allowNullValues=false). put throws NullPointerException when a null value is supplied and the map does not permit null values (LinkedTreeMap.java:111). This is stricter than HashMap to surface accidental null writes.","triggerScenarios":"Calling put(k, null) on a LinkedTreeMap created with new LinkedTreeMap(false) or new LinkedTreeMap(comparator, false).","commonSituations":"Code assuming HashMap-like null values; deserializing JSON with missing fields into a model that maps to a null-valued LinkedTreeMap; switching from a permissive map to LinkedTreeMap without enabling null values.","solutions":["Construct the map allowing null values if your data needs them: new LinkedTreeMap<>(true) or new LinkedTreeMap<>(comparator, true).","Skip or substitute the entry when the value is null instead of storing it.","Use a different Map implementation (HashMap/LinkedHashMap) if null values are intrinsic to your design."],"exampleFix":"// before\nLinkedTreeMap<String,String> m = new LinkedTreeMap<>(); // allowNullValues defaults true but you may pass false\nm.put(\"k\", null);\n// after\nLinkedTreeMap<String,String> m = new LinkedTreeMap<>(true); // explicitly allow null values","handlingStrategy":"validation","validationCode":"if (value == null) throw new IllegalArgumentException(\"value null not allowed\"); map.put(key, value);","typeGuard":"static <V> boolean puttableValue(LinkedTreeMap<?,V> m, V v) { return v != null || m.allowsNullValues(); }","tryCatchPattern":"try { map.put(k, v); } catch (NullPointerException e) { /* value null + not allowed */ }","preventionTips":["Decide on a null-value policy up front and construct the map accordingly (allowNullValues flag).","Replace null values with removal when absence is meant.","Document which maps disallow null values so callers cannot assume HashMap semantics."],"tags":["gson","collections","null","linkedtreemap"],"backgroundTag":null,"analyzedSha":"310ac341f2f92a454b229bf21f70d2d18b2b6db7","analyzedAt":"2026-08-10T02:58:47.455Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}