{"record":{"id":"db518c6b409a5837","repo":"quarkusio/quarkus","slug":"class-must-be-annotated-with-path","errorCode":null,"errorMessage":"class must be annotated with @Path","messagePattern":"class must be annotated with @Path","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java","lineNumber":408,"sourceCode":"    }\n\n    public UriBuilder path(String segment) throws IllegalArgumentException {\n        if (segment == null)\n            throw new IllegalArgumentException(\"path is null\");\n        path = paths(encode, path, segment);\n        return this;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public UriBuilder path(Class resource) throws IllegalArgumentException {\n        if (resource == null)\n            throw new IllegalArgumentException(\"path is null\");\n        Path ann = (Path) resource.getAnnotation(Path.class);\n        if (ann != null) {\n            String[] segments = new String[] { ann.value() };\n            path = paths(true, path, segments);\n        } else {\n            throw new IllegalArgumentException(\"class must be annotated with @Path\");\n        }\n        return this;\n    }\n\n    public UriBuilder path(Class resource, String method) throws IllegalArgumentException {\n        if (resource == null)\n            throw new IllegalArgumentException(\"resource is null\");\n        if (method == null)\n            throw new IllegalArgumentException(\"method is null\");\n        Method theMethod = null;\n        for (Method m : resource.getMethods()) {\n            if (m.getName().equals(method)) {\n                if (theMethod != null && m.isAnnotationPresent(Path.class)) {\n                    throw new IllegalArgumentException(\"Two methods with the same path \" + method);\n                }\n                if (m.isAnnotationPresent(Path.class))\n                    theMethod = m;\n            }","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java#L390-L426","documentation":"UriBuilderImpl.path(Class) requires the given resource class to carry a JAX-RS @Path annotation, because it derives the URI path segment from ann.value(). When the class has no @Path annotation the builder cannot compute a segment, so it throws this IllegalArgumentException. This mirrors the JAX-RS UriBuilder contract that path(Class) only accepts annotated resource classes.","triggerScenarios":"Calling uriBuilder.path(SomeClass.class) where SomeClass is a plain class (no @jakarta.ws.rs.Path annotation), or passing the wrong class (e.g. a model/DTO or the wrong end of a resource hierarchy) that lacks @Path.","commonSituations":"Programmatically building client proxies or links from reflection; a refactor renamed/moved the resource class and lost its @Path; using a base interface without @Path; passing an arbitrary class instead of the JAX-RS resource class.","solutions":["Annotate the class you pass to path(Class) with @Path(\"/...\") and give it a valid path value.","Pass the correct JAX-RS resource class that actually has @Path.","If you only want a literal segment, use path(String) instead of path(Class).","Pre-check the class with resource.isAnnotationPresent(Path.class) before calling path(Class)."],"exampleFix":"// before\nURI uri = UriBuilder.fromUri(base).path(NotAResource.class).build();\n// after\n@Path(\"/orders\")\nclass OrderResource { }\n\nURI uri = UriBuilder.fromUri(base).path(OrderResource.class).build();","handlingStrategy":"validation","validationCode":"if (resource == null || !resource.isAnnotationPresent(jakarta.ws.rs.Path.class)) {\n    throw new IllegalArgumentException(resource + \" is not a @Path-annotated JAX-RS resource\");\n}\nbuilder.path(resource);","typeGuard":"static boolean isPathResource(Class<?> c) {\n    return c != null && c.isAnnotationPresent(jakarta.ws.rs.Path.class);\n}","tryCatchPattern":"try {\n    uri = UriBuilder.fromUri(base).path(resourceClass).build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"annotated with @Path\")) {\n        throw new IllegalStateException(\"Class \" + resourceClass + \" lacks @Path\", e);\n    }\n    throw e;\n}","preventionTips":["Only pass classes from your JAX-RS resource packages to path(Class)","Assert resource classes are annotated in an architecture/unit test","Prefer path(String) for literal segments","Run reflection checks (isAnnotationPresent) before building"],"tags":["jaxrs","resteasy-reactive","uribuilder","illegal-argument"],"backgroundTag":"missing-path-annotation","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}