quarkusio/quarkus · error · IllegalArgumentException

Method not annotated with @Path

Error message

Method not annotated with @Path

What it means

UriBuilderImpl.path(Method) builds the segment from the method's @Path annotation value; if the reflective Method has no @Path annotation the builder cannot derive a path and throws this IllegalArgumentException. Note the null-Method case has its own distinct message ('method is null'), so this one means a real Method was supplied but is not an annotated endpoint.

Source

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

                }
                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 {
        if (method == null) {
            throw new IllegalArgumentException("method is null");
        }
        Path ann = method.getAnnotation(Path.class);
        if (ann != null) {
            path = paths(encode, path, ann.value());
        } else {
            throw new IllegalArgumentException("Method not annotated with @Path");
        }
        return this;
    }

    public UriBuilder replaceMatrix(String matrix) throws IllegalArgumentException {
        if (matrix == null)
            matrix = "";
        if (!matrix.startsWith(";"))
            matrix = ";" + matrix;
        matrix = Encode.encodePath(matrix);
        if (path == null) {
            path = matrix;
        } else {
            int start = path.lastIndexOf('/');
            if (start < 0)
                start = 0;
            int matrixIndex = path.indexOf(';', start);
            if (matrixIndex > -1)

View on GitHub (pinned to e1c734241f)

Solutions

  1. Only pass methods annotated with @Path to path(Method).
  2. Add @Path to the method if it is genuinely an endpoint.
  3. Use path(Class) for the class-level segment and skip methods without @Path.
  4. Pre-check method.isAnnotationPresent(Path.class) before calling.

Example fix

// before
Method m = OrderResource.class.getMethod("toString");
builder.path(m); // throws
// after
Method m = OrderResource.class.getMethod("get"); // has @Path
builder.path(m);
Defensive patterns

Strategy: validation

Validate before calling

if (method != null && !method.isAnnotationPresent(jakarta.ws.rs.Path.class)) {
    throw new IllegalArgumentException(method + " is not a @Path-annotated endpoint");
}

Type guard

static boolean isPathAnnotated(Method m) {
    return m != null && m.isAnnotationPresent(jakarta.ws.rs.Path.class);
}

Try / catch

try {
    builder.path(method);
} catch (IllegalArgumentException e) {
    if (e.getMessage().equals("Method not annotated with @Path")) {
        throw new IllegalStateException("Non-endpoint method passed to path(): " + method, e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Passing a Method that is a plain helper, getter, or lifecycle method (no @Path) — e.g. from path(Resource.class, "helperName") resolution or a random reflective method.

Common situations: Mistakenly treating non-endpoint methods as endpoints in client/link generation; the @Path annotation moved to the class only, leaving methods unannotated; annotation processing or Lombok-related setups where the annotation is not visible on the resolved Method.

Related errors


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