Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-2335

RestEasy Microprofile Client has a immutable template problem/bug

    Details

    • Steps to Reproduce:
      Hide

      In the attachment you can find a sample project.
      You don't need to run the quarkus server. Just execute the test. You gonna get the error immediately. Btw. I use maven.

      Show
      In the attachment you can find a sample project. You don't need to run the quarkus server. Just execute the test. You gonna get the error immediately. Btw. I use maven.

      Description

      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.

        Gliffy Diagrams

          Attachments

          1. issue-resteasy-mp-client.zip
            21 kB
          2. screenshot-1.png
            screenshot-1.png
            601 kB
          3. screenshot-2.png
            screenshot-2.png
            802 kB
          4. screenshot-3.png
            screenshot-3.png
            2.32 MB
          5. screenshot-4.png
            screenshot-4.png
            1.08 MB

            Activity

              People

              • Assignee:
                weinanli Weinan Li
                Reporter:
                isikemre Emre Isik
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: