quarkusio/quarkus · error · IllegalArgumentException

resource is null

Error message

resource is null

What it means

UriBuilderImpl.path(Class, String) validates its arguments up front and throws this IllegalArgumentException when the resource Class parameter is null. Without a class there is nothing to reflect over to find the @Path-annotated method, so the builder fails fast.

Source

Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java:415

    }

    @SuppressWarnings("unchecked")
    public UriBuilder path(Class resource) throws IllegalArgumentException {
        if (resource == null)
            throw new IllegalArgumentException("path is null");
        Path ann = (Path) resource.getAnnotation(Path.class);
        if (ann != null) {
            String[] segments = new String[] { ann.value() };
            path = paths(true, path, segments);
        } else {
            throw new IllegalArgumentException("class must be annotated with @Path");
        }
        return this;
    }

    public UriBuilder path(Class resource, String method) throws IllegalArgumentException {
        if (resource == null)
            throw new IllegalArgumentException("resource is null");
        if (method == null)
            throw new IllegalArgumentException("method is null");
        Method theMethod = null;
        for (Method m : resource.getMethods()) {
            if (m.getName().equals(method)) {
                if (theMethod != null && m.isAnnotationPresent(Path.class)) {
                    throw new IllegalArgumentException("Two methods with the same path " + method);
                }
                if (m.isAnnotationPresent(Path.class))
                    theMethod = m;
            }
        }
        if (theMethod == null)
            throw new IllegalArgumentException("No public method annotated with @Path " + resource.getName() + " " + method);
        return path(theMethod);
    }

    public UriBuilder path(Method method) throws IllegalArgumentException {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Ensure the Class variable is non-null before calling path(resource, method).
  2. Fix the class loading/lookup that produced null (verify class name, classpath, dependency).
  3. Guard with Objects.requireNonNull(resource) or an explicit check before the call.
  4. If you already hold a Method object, call path(Method) instead and skip the class lookup.

Example fix

// before
builder.path(resourceClass, "get"); // resourceClass may be null
// after
Objects.requireNonNull(resourceClass, "resource class must be provided");
builder.path(resourceClass, "get");
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(resourceClass, "resource class must not be null");
Objects.requireNonNull(methodName, "method name must not be null");

Type guard

static boolean readyForPath(Class<?> c, String m) {
    return c != null && m != null;
}

Try / catch

try {
    builder.path(resourceClass, methodName);
} catch (IllegalArgumentException e) {
    if (e.getMessage().equals("resource is null")) {
        throw new IllegalStateException("Resource class not resolved for " + methodName, e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Invoking path(null, "methodName"), typically when the class is obtained from a variable, map lookup, or config value that resolved to null.

Common situations: Class.forName with a misspelled class name caught and swallowed, leaving a null Class; reflection-based client generation where the resource type is missing from a registry; conditional code paths that skip class assignment.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/efffc0ca14eef74b. Report an issue: GitHub.