apache/maven · error · IllegalArgumentException

{} is null

Error message

{} is null

What it means

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.

Source

Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/ImplUtils.java:32

 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.maven.impl;

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

class ImplUtils {

    public static <T> T cast(Class<T> clazz, Object o, String name) {
        if (!clazz.isInstance(o)) {
            if (o == null) {
                throw new IllegalArgumentException(name + " is null");
            }
            throw new IllegalArgumentException(name + " is not an instance of " + clazz.getName());
        }
        return clazz.cast(o);
    }

    public static <U, V> List<V> map(Collection<U> list, Function<U, V> mapper) {
        return list.stream().map(mapper).filter(Objects::nonNull).collect(Collectors.toList());
    }
}

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Obtain the Session from Maven itself (session lookup / MavenExecutionRequest bootstrap) rather than constructing repository sessions manually
  2. Ensure InternalSession.associate(repositorySession, mavenSession) ran once before impl code touches the session
  3. Null-check objects returned from lookups before passing them into impl-layer APIs

Example fix

// before: raw resolver session, never associated
RepositorySystemSession rss = new DefaultRepositorySystemSession(session);
service.doSomething(rss); // cast -> "session is null"

// after: go through Maven's session so the internal binding exists
Session session = lookupService.lookup(Session.class);
service.doSomething(session);
Defensive patterns

Strategy: validation

Validate before calling

// null-check everything coming from lookups before it reaches impl-layer APIs
Objects.requireNonNull(session, "session");
Objects.requireNonNull(model, "model");
service.doSomething(session, model);

Try / catch

try {
    service.doSomething(session);
} catch (IllegalArgumentException e) {
    if (e.getMessage() != null && e.getMessage().endsWith("is null")) {
        // a required internal instance was never bound/associated; re-bootstrap the session
        throw new IllegalStateException("Session not initialized through Maven bootstrap", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/2f269fca7ffde7f8. Report an issue: GitHub.