{"record":{"id":"5ada4a889ec83acc","repo":"elastic/elasticsearch","slug":"name-description-was-null","errorCode":null,"errorMessage":"${name} ${description} was null","messagePattern":"(.+?) (.+?) was null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/AbstractLazyPropertyCollection.java","lineNumber":31,"sourceCode":"public abstract class AbstractLazyPropertyCollection {\n\n    final String name;\n    final Object owner;\n\n    public AbstractLazyPropertyCollection(String name) {\n        this(name, null);\n    }\n\n    public AbstractLazyPropertyCollection(String name, Object owner) {\n        this.name = name;\n        this.owner = owner;\n    }\n\n    public abstract List<? extends Object> getNormalizedCollection();\n\n    void assertNotNull(Object value, String description) {\n        if (value == null) {\n            throw new NullPointerException(name + \" \" + description + \" was null\" + (owner != null ? \" when configuring \" + owner : \"\"));\n        }\n    }\n\n}\n","sourceCodeStart":13,"sourceCodeEnd":36,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/AbstractLazyPropertyCollection.java#L13-L36","documentation":"AbstractLazyPropertyCollection is the base for Gradle lazy property containers (e.g. dependency/module lists). assertNotNull is called by subclasses when normalising their collection; if a caller passed null for a required element the method throws a NullPointerException naming the collection, the description of the offending argument, and the owner being configured if known.","triggerScenarios":"Invoking an add/with method on a lazy collection subclass with a null element while the subclass delegates through assertNotNull(value, description). The owner context is appended only when the collection was constructed with an owner.","commonSituations":"A build plugin call like dependencies.add(null) or a convention that forwards a possibly-null provider value; a refactor that removed a provider's convention without a fallback; a third-party plugin integrating with ES build tools passing null.","solutions":["Read the message: it states which collection and which description was null, plus the owner.","Filter or default the value before adding: `Optional.ofNullable(x).ifPresent(coll::add)`.","Fix the upstream provider so it never supplies null — set a convention or use a Property."],"exampleFix":"// before\ncollection.add(maybeNullProvider.getOrNull())\n// after\nOptional.ofNullable(maybeNullProvider.getOrNull()).ifPresent(collection::add)","handlingStrategy":"type-guard","validationCode":"static <T> void addIfPresent(AbstractLazyPropertyCollection coll, T value, String description) {\n    if (value == null) {\n        throw new NullPointerException(coll + \" \" + description + \" was null\");\n    }\n    // coll.add(value) — guarded\n}","typeGuard":"static <T> boolean isAddable(T value) {\n    return value != null;\n}","tryCatchPattern":"try {\n    collection.add(value);\n} catch (NullPointerException npe) {\n    if (npe.getMessage().contains(\"was null\")) {\n        getLogger().warn(\"Skipping null element: {}\", npe.getMessage());\n    } else { throw npe; }\n}","preventionTips":["Filter nulls out of collections before adding (use Optional/Stream).","Give lazy collections an owner at construction so NPE messages name the configuring object.","Prefer Gradle Provider/Property over raw values that may be null."],"tags":["gradle","build-config","null-safety","validation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}