hk2
  1. hk2
  2. HK2-136

Dependency asm can not read Java 8 source files

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.0
    • Fix Version/s: 2.2.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Mac OS X 10.8, Java 1.8.0-ea-b105, Jersey-server 2.2, Jetty 9.0.5.v20130815

      Description

      In your dependency stack, Jersey-sever 2.2 has asm-all-repackaged-2.2.0-b14 from org.glassfish.hk2.external which does not work with Java 8 source code files if you use lambda expressions.

      I have tested this both with the glassfish/grizzly embedded HttpServer and latest Jetty. Jetty provides it's own asm, 4.1.0, but it neither support Java 8. There is a alpha version, asm 5_ALPHA, that however support Java 8.

      Steps to reproduce

      ~/ $ mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false -DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example -DarchetypeVersion=2.2 && cd simple-service
      ~/simple-service $ vim src/main/java/com/example/MyResource.java
      

      Insert Java 8 code into MyResource

          @GET
          @Produces(MediaType.TEXT_PLAIN)
          public String getIt() {
      	    new ArrayList<String>().stream().filter((str) -> str.length() > 0);
              return "Got it!";
          }
      

      Change maven compile level

                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>2.5.1</version>
                      <inherited>true</inherited>
                      <configuration>
                          <source>1.8</source>
                          <target>1.8</target>
                      </configuration>
                  </plugin>
      

      Which the following stack trace:

      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 52264
      	at org.objectweb.asm.ClassReader.readClass(ClassReader.java:2015)
      	at org.objectweb.asm.ClassReader.accept(ClassReader.java:469)
      	at org.objectweb.asm.ClassReader.accept(ClassReader.java:425)
      	at org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener.process(AnnotationAcceptingListener.java:169)
      	at org.glassfish.jersey.server.ResourceConfig.scanClasses(ResourceConfig.java:879)
      	at org.glassfish.jersey.server.ResourceConfig._getClasses(ResourceConfig.java:837)
      	at org.glassfish.jersey.server.ResourceConfig.getClasses(ResourceConfig.java:752)
      	at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1159)
      	at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1132)
      	at org.glassfish.jersey.server.ResourceConfig.createRuntimeConfig(ResourceConfig.java:1128)
      	at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:281)
      	at org.glassfish.jersey.server.ContainerFactory.createContainer(ContainerFactory.java:79)
      	at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:110)
      	at com.example.Main.startServer(Main.java:29)
      	at com.example.Main.main(Main.java:38)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:491)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
      

        Issue Links

          Activity

          Hide
          jwells added a comment - - edited

          Here is the problem. We use cglib in order to proxy classes. But the latest version of cglib (3.0) will only work with asm 4.0 (it won't even work with asm 4.2!).

          So I can update hk2 to be using asm 4.0, but I can't move any further if we are going to continue to use cglib in order to proxy classes.

          Show
          jwells added a comment - - edited Here is the problem. We use cglib in order to proxy classes. But the latest version of cglib (3.0) will only work with asm 4.0 (it won't even work with asm 4.2!). So I can update hk2 to be using asm 4.0, but I can't move any further if we are going to continue to use cglib in order to proxy classes.
          Hide
          jwells added a comment -

          I have created this support request at source-forge:

          https://sourceforge.net/p/cglib/support-requests/4/

          If we need this sooner we may need to branch off of the existing cglib source code or roll our own (which would be a bad idea imo)

          Show
          jwells added a comment - I have created this support request at source-forge: https://sourceforge.net/p/cglib/support-requests/4/ If we need this sooner we may need to branch off of the existing cglib source code or roll our own (which would be a bad idea imo)
          Hide
          cowwoc added a comment -

          Last I checked (a few years ago) cglib was a dead or dying project whereas ASM was well-maintained. Consider replacing or removing the dependency on cglib.

          Show
          cowwoc added a comment - Last I checked (a few years ago) cglib was a dead or dying project whereas ASM was well-maintained. Consider replacing or removing the dependency on cglib.
          Hide
          jwells added a comment -

          Yes, we are currently moving hk2 to use javassist and getting rid of cglib

          Show
          jwells added a comment - Yes, we are currently moving hk2 to use javassist and getting rid of cglib
          Hide
          jwells added a comment -

          This should have been fixed when we moved hk2 to asm 5.0_BETA.

          Show
          jwells added a comment - This should have been fixed when we moved hk2 to asm 5.0_BETA.

            People

            • Assignee:
              jwells
              Reporter:
              tnorgaard
            • Votes:
              5 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: