{"record":{"id":"866077548efe107a","repo":"quarkusio/quarkus","slug":"two-methods-with-the-same-path","errorCode":null,"errorMessage":"Two methods with the same path ","messagePattern":"Two methods with the same 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":422,"sourceCode":"        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            }\n        }\n        if (theMethod == null)\n            throw new IllegalArgumentException(\"No public method annotated with @Path \" + resource.getName() + \" \" + method);\n        return path(theMethod);\n    }\n\n    public UriBuilder path(Method method) throws IllegalArgumentException {\n        if (method == null) {\n            throw new IllegalArgumentException(\"method is null\");\n        }\n        Path ann = method.getAnnotation(Path.class);\n        if (ann != null) {\n            path = paths(encode, path, ann.value());\n        } else {","sourceCodeStart":404,"sourceCodeEnd":440,"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#L404-L440","documentation":"When resolving path(Class, String) the builder scans public methods for the given name and keeps the last one annotated with @Path. If it encounters a second @Path-annotated method with the same name it cannot disambiguate which path to use, so it throws this IllegalArgumentException naming the ambiguous method.","triggerScenarios":"A resource class has two public methods with the same name where more than one carries @Path — e.g. overloaded resource methods both annotated @Path(\"/{id}\") with different signatures, then calling path(Resource.class, \"name\").","commonSituations":"Overloaded REST endpoints differing only in parameter types (e.g. @GET @Path(\"/x\") versions taking String vs UUID); accidental copy-paste duplication of an endpoint method; inheritance bringing in a same-name @Path method from a superclass.","solutions":["Rename one of the overloaded methods so each @Path-annotated name is unique in the class.","Make sure only one same-named method is annotated with @Path (overloads without @Path are fine for this API).","Call path(Method) with the specific resolved Method object instead of path(Class, name).","Check superclass/interface methods pulled in by getMethods() that also carry @Path."],"exampleFix":"// before\n@Path(\"/{id}\") public Order get(String id) {...}\n@Path(\"/{id}\") public Order get(UUID id) {...}\nbuilder.path(OrderResource.class, \"get\"); // ambiguous\n// after\n@Path(\"/{id}\") public Order get(String id) {...}\n@Path(\"/{id}\") public Order getByUuid(UUID id) {...}\nbuilder.path(OrderResource.class, \"get\");","handlingStrategy":"validation","validationCode":"long count = Arrays.stream(OrderResource.class.getMethods())\n    .filter(m -> m.getName().equals(methodName) && m.isAnnotationPresent(Path.class))\n    .count();\nif (count > 1) throw new IllegalStateException(\"Ambiguous @Path methods named \" + methodName);","typeGuard":"static boolean unambiguousPathMethod(Class<?> c, String name) {\n    return Arrays.stream(c.getMethods())\n        .filter(m -> m.getName().equals(name) && m.isAnnotationPresent(Path.class))\n        .count() == 1;\n}","tryCatchPattern":"try {\n    uri = builder.path(OrderResource.class, methodName).build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Two methods with the same path\")) {\n        throw new IllegalStateException(\"Rename one of the overloaded @Path methods: \" + methodName, e);\n    }\n    throw e;\n}","preventionTips":["Do not overload @Path-annotated resource methods with the same name","Give overloaded endpoints distinct Java method names","Resolve and pass an explicit Method via path(Method) when overloads exist","Watch inherited @Path methods from superclasses/interfaces"],"tags":["jaxrs","resteasy-reactive","uribuilder","ambiguous-overload"],"backgroundTag":"ambiguous-resource-method","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"}