{"record":{"id":"2f269fca7ffde7f8","repo":"apache/maven","slug":"is-null","errorCode":null,"errorMessage":"{} is null","messagePattern":"(.+?) is null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/ImplUtils.java","lineNumber":32,"sourceCode":" * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied.  See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\npackage org.apache.maven.impl;\n\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.Objects;\nimport java.util.function.Function;\nimport java.util.stream.Collectors;\n\nclass ImplUtils {\n\n    public static <T> T cast(Class<T> clazz, Object o, String name) {\n        if (!clazz.isInstance(o)) {\n            if (o == null) {\n                throw new IllegalArgumentException(name + \" is null\");\n            }\n            throw new IllegalArgumentException(name + \" is not an instance of \" + clazz.getName());\n        }\n        return clazz.cast(o);\n    }\n\n    public static <U, V> List<V> map(Collection<U> list, Function<U, V> mapper) {\n        return list.stream().map(mapper).filter(Objects::nonNull).collect(Collectors.toList());\n    }\n}\n","sourceCodeStart":14,"sourceCodeEnd":43,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/ImplUtils.java#L14-L43","documentation":"ImplUtils.cast(clazz, object, name) is the gate behind internal conversions such as InternalSession.from(...): when the supplied object is null it throws IllegalArgumentException(name + \" is null\"). In practice this means an API method received null where an internal implementation instance was mandatory — most commonly a RepositorySystemSession whose session data carries no InternalSession binding.","triggerScenarios":"InternalSession.from(repositorySystemSession) when the session data map has no InternalSession entry (never associated via InternalSession.associate); calling impl services with a Session or model object that a lookup returned null for.","commonSituations":"Embedders building a standalone RepositorySystemSession with the resolver and then handing it to Maven API code that expects a Maven-created session; races where associate() has not run yet; DI misconfiguration returning null bindings.","solutions":["Obtain the Session from Maven itself (session lookup / MavenExecutionRequest bootstrap) rather than constructing repository sessions manually","Ensure InternalSession.associate(repositorySession, mavenSession) ran once before impl code touches the session","Null-check objects returned from lookups before passing them into impl-layer APIs"],"exampleFix":"// before: raw resolver session, never associated\nRepositorySystemSession rss = new DefaultRepositorySystemSession(session);\nservice.doSomething(rss); // cast -> \"session is null\"\n\n// after: go through Maven's session so the internal binding exists\nSession session = lookupService.lookup(Session.class);\nservice.doSomething(session);","handlingStrategy":"validation","validationCode":"// null-check everything coming from lookups before it reaches impl-layer APIs\nObjects.requireNonNull(session, \"session\");\nObjects.requireNonNull(model, \"model\");\nservice.doSomething(session, model);","typeGuard":null,"tryCatchPattern":"try {\n    service.doSomething(session);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().endsWith(\"is null\")) {\n        // a required internal instance was never bound/associated; re-bootstrap the session\n        throw new IllegalStateException(\"Session not initialized through Maven bootstrap\", e);\n    }\n    throw e;\n}","preventionTips":["Obtain Session and other SPI objects from Maven's own bootstrap, never construct them ad hoc","Null-check lookup results (DI can legally return null for absent bindings)","In embedders, run InternalSession.associate once at startup before any impl call"],"tags":["maven","internal-api","null-check","session"],"backgroundTag":"null-argument","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}