-
Bug
-
Resolution: Done
-
Major
-
4.2.0.Final
The problem here is that, when I use a Interface (Rest Interface) for ex. here:
@Path("/{realm-id}/tags") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) public interface TagsApi { @GET Map<String, Collection<Tag>> getAll(@PathParam("realm-id") String realmId); @GET @Path("/taggable/{id}") Collection<Tag> getTaggable(@PathParam("realm-id") String realmId, @PathParam("id") String taggableId); @POST @Path("/taggable/get-all") Map<String, Collection<Tag>> getAllTaggable(@PathParam("realm-id") String realmId, List<String> taggableIds); @GET @Path("/{id}") Tag get(@PathParam("realm-id") String realmId, @PathParam("id") String tagId); @POST Response create(@PathParam("realm-id") String realmId, Tag tag); @PUT Response update(@PathParam("realm-id") String realmId, Tag tag); @DELETE @Path("/{tag-id}") Response delete(@PathParam("realm-id") String realmId, @PathParam("tag-id") String tagId); @PUT @Path("/taggable/{id}") Response updateTaggable(@PathParam("realm-id") String realmId, @PathParam("id") String taggableId, Collection<String> tagIds); }
You see the interface itself has a @Path and some methods have a path too and some of them doesn't have a path annotation so they referencing to the classPathAnnotation above. So now when you want to create a RestClient with:
TagsApi tagsApi = RestClientBuilder.newBuilder().baseUri(URI.create("http://localhost:8080")).build(TagsApi.class);
I get this error:
org.eclipse.microprofile.rest.client.RestClientDefinitionException: Parameters and variables don't match on interface dev.isikemre.test.irmc.TagsApi::create
Now, I debuged and reverse-engineered the code and I found this code below:
https://github.com/resteasy/Resteasy/blob/b652a4f41831e54e44a5a0093c3453d75e9c468e/resteasy-client-microprofile/src/main/java/org/jboss/resteasy/microprofile/client/RestClientBuilderImpl.java#L410
The main problem is that the variable classTemplate is not immutable.
At line 381 on the same file you see a assignment to template (a temporary variable) later in the code at 410 (like the github link above) you see that there is method call on the template variable. This mutates it and then the former classTemplate is now mutated.
The former classTemplate's path was
"/{realms-id}/tags"
after the line 410 the path becomes
"/foobar/tags"
and the second iteration in this for-loop (Line 392) got an error on line 406 because the method template.getPathParamNamesInDeclarationOrder() on line 390 returns a empty list because it cant find any pathparams, because it was mutated before.
I hope I could explain it, well. It is a small and hidden bug.