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

org.jboss.resteasy.util.Types#getActualTypeArgumentsOfAnInterface not working for lambda's.

    Details

    • Steps to Reproduce:
      Hide

      Run the code as given in the description.

      Show
      Run the code as given in the description.
    • Affects:
      Compatibility/Configuration
    • Workaround:
      Workaround Exists
    • Workaround Description:
      Hide

      Don't use lambda's. The point is that IDE's may suggest changing your code in a lambda, and the error message given by Resteasy is not very helpful.

      Show
      Don't use lambda's. The point is that IDE's may suggest changing your code in a lambda, and the error message given by Resteasy is not very helpful.

      Description

       package org.jboss.resteasy.spi;
      
      import org.junit.Test;
      
      import javax.ws.rs.ext.ContextResolver;
      
      public class ResteasyProviderFactoryTest  {
      @Test
      	public void testRegisterProviderAsLambda() throws Exception {
      
      		ResteasyProviderFactory factory = new ResteasyProviderFactory();
      		factory.register((ContextResolver<String>) type -> "foo bar");
      
      	}
      }
      

      Then it doesn't work:

      java.lang.RuntimeException: Unable to instantiate ContextResolver
      	at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProviderInstance(ResteasyProviderFactory.java:1814)
      	at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProviderInstance(ResteasyProviderFactory.java:1728)
      	at org.jboss.resteasy.spi.ResteasyProviderFactory.register(ResteasyProviderFactory.java:2410)
      	at org.jboss.resteasy.spi.ResteasyProviderFactoryTest.testRegisterProviderAsLambda(ResteasyProviderFactoryTest.java:27)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
      	at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
      	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
      	at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
      	at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
      	at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
      	at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
      	at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
      	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
      	at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:130)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
      Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
      	at org.jboss.resteasy.spi.ResteasyProviderFactory.addContextResolver(ResteasyProviderFactory.java:1124)
      	at org.jboss.resteasy.spi.ResteasyProviderFactory.addContextResolver(ResteasyProviderFactory.java:1119)
      	at org.jboss.resteasy.spi.ResteasyProviderFactory.addContextResolver(ResteasyProviderFactory.java:1114)
      	at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProviderInstance(ResteasyProviderFactory.java:1808)
      	... 26 more
      

      This seems to be because org.jboss.resteasy.util.Types#findInterfaceParameterizedTypes
      doesnt work with lambdas.

      I would have liked to submit a patch too, but that doesn't seem very trivial.

      E.g. https://github.com/jhalterman/typetools/blob/master/src/main/java/net/jodah/typetools/TypeResolver.java

      tries to resolve the generic type argument of a lambda.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  ron_sigal Ronald Sigal
                  Reporter:
                  mihxil Michiel Meeuwissen
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated: