Strange java.lang.ArrayIndexOutOfBoundsException thrown on jetty startup

后端 未结 4 1217
予麋鹿
予麋鹿 2020-12-03 08:36

Whenever I deploy jetty application I hit this issue. Looks like some jar or class is broken.

  • Colleagues compiling exactly same code, doesn\'t hit
相关标签:
4条回答
  • 2020-12-03 08:38

    For your 2 errors ..

    javax.servlet.ServletException: jersey-serlvet
    

    This means you have a typo in your WEB-INF/web.xml

    As for this one ..

    java.lang.ArrayIndexOutOfBoundsException: 6241
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    

    I've seen similar ones when using an old version of asm.jar with newer compiled Java bytecode.

    • For Java 15 bytecode, use asm 7.3.1+
    • For Java 14 bytecode, use asm 7.2+
    • For Java 13 bytecode, use asm 7.1+
    • For Java 12 bytecode, use asm 7.1+
    • For Java 11 bytecode, use asm 7.0+
    • For Java 10 bytecode, use asm 6.1+
    • For Java 9 bytecode, use asm 6.0+
    • For Java 8 bytecode, use asm 5.0.1+
    • For Java 6 or Java 7 bytecode, (Use asm 3.1 if you must, but know that asm 5.x is also going to work here too)

    Ensure that your asm.jar (or org.objectweb.asm.jar) is current.

    There is a slightly less common issue where the class itself is bad. Sometimes seen with classes that are compiled in one JDK (such as IBM) and then run on another Java (like Sun/Oracle).

    A real world example of this would be the icu4j-2.6.1.jar and its com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class jar entry.

    0 讨论(0)
  • 2020-12-03 08:45

    Use newer version of jetty-maven-plugin.

    More information --> Bug 419801 - Upgrade to asm5 for jdk8

    So, edit your pom.xml like this:

    <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.3.0.M2</version>
    </plugin>
    

    Note the groupId is "org.eclipse.jetty".

    0 讨论(0)
  • 2020-12-03 08:49

    In my case, I am using ASM library version and that not support java 8 lambda expression, so either you change ASM library to support java 8 or change your code.

    In my case I am using java 8 lambda expression for iterating and I replaced it with for loop

    0 讨论(0)
  • 2020-12-03 08:53

    I came across similar issue when maintaining legacy code.

    Servlet.init() for servlet JerseyServlet threw exception
    
    type Exception report
    
    message Servlet.init() for servlet JerseyServlet threw exception
    
    description The server encountered an internal error that prevented it from fulfilling this request.
    
    exception
    
    javax.servlet.ServletException: Servlet.init() for servlet JerseyServlet threw exception
        org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
        org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
        org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
        org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
        org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        java.lang.Thread.run(Thread.java:745)
    root cause
    
    java.lang.ArrayIndexOutOfBoundsException
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.65 logs.
    

    I fixed it with reducing the package scanning scope in web.xml. E.g., removing the package_with_too_many_classes below in param-value tag fixed the issue.

    <servlet>
       <servlet-name>JerseyServlet</servlet-name>
       <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
       <init-param>
           <param-name>com.sun.jersey.config.property.packages</param-name>
           <param-value>package_with_too_many_classes;package_with_approciate_number_of_classes;org.codehaus.jackson.jaxrs</param-value>
       </init-param>
       <load-on-startup>2</load-on-startup>
     </servlet>
    
    0 讨论(0)
提交回复
热议问题