{"record":{"id":"b9cf65f78394a08c","repo":"stanfordnlp/CoreNLP","slug":"unknown-null-attribute","errorCode":null,"errorMessage":"Unknown null attribute.","messagePattern":"Unknown null attribute\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/ChunkAnnotationUtils.java","lineNumber":866,"sourceCode":"        if (value != null)  {\n          try {\n            Class valueClass = AnnotationLookup.getValueType(coreKeyClass);\n            if (valueClass == String.class) {\n              chunk.set(coreKeyClass, value);\n            } else {\n             Method valueOfMethod = valueClass.getMethod(\"valueOf\", String.class);\n              if (valueOfMethod != null) {\n                chunk.set(coreKeyClass, valueOfMethod.invoke(valueClass, value));\n              }\n            }\n          } catch (Exception ex) {\n            throw new RuntimeException(\"Unable to annotate attribute \" + key, ex);\n          }\n        } else {\n          chunk.set(coreKeyClass, null);\n        }\n      } else {\n        throw new UnsupportedOperationException(\"Unknown null attribute.\");\n      }\n    }\n  }\n\n  public static void annotateChunks(List<? extends CoreMap> chunks, int start, int end, Map<String,String> attributes) {\n    for (int i = start; i < end; i++) {\n      annotateChunk(chunks.get(i), attributes);\n    }\n  }\n\n  public static void annotateChunks(List<? extends CoreMap> chunks, Map<String,String> attributes) {\n    for (CoreMap chunk:chunks) {\n      annotateChunk(chunk, attributes);\n    }\n  }\n\n  public static <T extends CoreMap> T createCoreMap(CoreMap cm, String text, int start, int end,\n                                                    CoreTokenFactory<T> factory) {","sourceCodeStart":848,"sourceCodeEnd":884,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/ChunkAnnotationUtils.java#L848-L884","documentation":"In ChunkAnnotationUtils.annotateWithMatchingFields, when the attribute value is null, the code only supports setting null on keys that are handled by the primary branch; reaching the else clause means a null value was supplied for an attribute the method doesn't support, so it throws UnsupportedOperationException('Unknown null attribute.').","triggerScenarios":"Passing an entry with a null value in the attributes map to annotateChunk/annotateChunks for a key that is not one of the recognized null-supported annotation classes.","commonSituations":"Programmatic construction of the attributes map inserting null values; generic code copying properties where some are null.","solutions":["Remove null-valued entries from the attributes map before calling","Only pass keys the method supports when the value is null","Provide a non-null string value and let valueOf parse it"],"exampleFix":"// before\nattributes.put(\"Tag\", null);\nannotateChunk(chunk, attributes);\n// after\nattributes.remove(\"Tag\"); // or set a real value\nannotateChunk(chunk, attributes);","handlingStrategy":"validation","validationCode":"attributes.values().removeIf(Objects::isNull); // strip null entries before annotateChunk","typeGuard":"static boolean hasNullValues(Map<String,String> m) {\n  return m.values().stream().anyMatch(Objects::isNull);\n}","tryCatchPattern":"try {\n  ChunkAnnotationUtils.annotateChunk(chunk, attributes);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().equals(\"Unknown null attribute.\")) {\n    // remove null entries and retry\n  } else throw e;\n}","preventionTips":["Never put null values in the attributes map","Filter/omit attributes you cannot populate"],"tags":["stanford-corenlp","null-value","unsupported-operation","annotation-attributes"],"backgroundTag":"unsupported-operation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}