码头启动时抛出奇怪的 java.lang.ArrayIndexOutOfBoundsException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26496338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:37:58  来源:igfitidea点击:

Strange java.lang.ArrayIndexOutOfBoundsException thrown on jetty startup

javajettymaven-jetty-plugin

提问by Jakozaur

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

每当我部署码头应用程序时,我都会遇到这个问题。看起来有些jar或类坏了。

  • Colleagues compiling exactly same code, doesn't hit the issue. Even if the deploy to the same computer. (we use gitand maven)
  • Deleting local maven repository ~/.m2and rebuilding doesn't help.
  • Can run same jetty app locally without any issues.
  • My initial suspect was that some jaris broken. Tried jar tvf $every_jarand haven't found anything.
  • 编译完全相同的代码的同事没有遇到问题。即使部署到同一台计算机。(我们使用gitmaven
  • 删除本地 Maven 存储库~/.m2并重建无济于事。
  • 可以在本地运行相同的码头应用程序,没有任何问题。
  • 我最初的怀疑是有些jar坏了。尝试过jar tvf $every_jar并没有找到任何东西。

Any ideas how can I debug this? Looks really mysterious and I suspect is that some file get corrupted.

任何想法我该如何调试?看起来真的很神秘,我怀疑是某些文件损坏了。

Stack trace:
2014-10-21 13:29:25.123:WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext{/,file:/XYZ/},/XYZ/webapps/root
javax.servlet.ServletException: jersey-serlvet
        at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:553)
        at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:344)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:791)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:39)
        at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
        at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:494)
        at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:141)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:145)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:56)
        at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:615)
        at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:540)
        at org.eclipse.jetty.util.Scanner.scan(Scanner.java:403)
        at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:337)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:121)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:555)
        at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:230)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:81)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
        at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:96)
        at org.eclipse.jetty.server.Server.doStart(Server.java:282)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.xml.XmlConfiguration.run(XmlConfiguration.java:1274)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1197)
        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:606)
        at org.eclipse.jetty.start.Main.invokeMain(Main.java:473)
        at org.eclipse.jetty.start.Main.start(Main.java:615)
        at org.eclipse.jetty.start.Main.main(Main.java:96)

followed by

其次是

Caused by:
java.lang.ArrayIndexOutOfBoundsException: 6241
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:133)
        at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.f(FileSchemeScanner.java:86)
        at com.sun.jersey.core.util.Closing.f(Closing.java:71)
        at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:83)
        at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:80)
        at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:80)
        at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scan(FileSchemeScanner.java:71)
        at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:223)
        at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:139)
        at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80)
        at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
        at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
        at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
        at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:700)

回答by Joakim Erdfelt

For your 2 errors ..

对于您的 2 个错误..

javax.servlet.ServletException: jersey-serlvet

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

这意味着您的输入有错别字 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.jarwith newer compiled Java bytecode.

在使用asm.jar较新编译的 Java 字节码的旧版本时,我见过类似的。

  • 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.1if you must, but know that asm 5.xis also going to work here too)
  • 对于 Java 11 字节码,使用asm 7.0+
  • 对于 Java 10 字节码,使用asm 6.1+
  • 对于 Java 9 字节码,使用asm 6.0+
  • 对于 Java 8 字节码,使用asm 5.0.1+
  • 对于 Java 6 或 Java 7 字节码,(如果必须,请使用asm 3.1,但要知道asm 5.x也可以在这里工作)

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

确保您的asm.jar(或org.objectweb.asm.jar)是最新的。

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).

有一个不太常见的问题是类本身不好。有时会看到在一个 JDK(例如 IBM)中编译然后在另一个 Java(例如 Sun/Oracle)上运行的类。

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

这方面的一个现实世界的例子是icu4j-2.6.1.jar和它的com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.classJAR条目

回答by vv314

Use newer version of jetty-maven-plugin.

使用较新版本的 jetty-maven-plugin。

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

更多信息 -->错误 419801 - 升级到 asm5 for jdk8

So, edit your pom.xmllike this:

所以,pom.xml像这样编辑你的:

<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".

注意 groupId 是“ org.eclipse.jetty”。

回答by Popeye

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.

我通过减少 web.xml 中的包扫描范围来修复它。例如,删除 param-value 标签下面的 package_with_too_many_classes 修复了这个问题。

<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.Hymanson.jaxrs</param-value>
   </init-param>
   <load-on-startup>2</load-on-startup>
 </servlet>

回答by Gaurav Deshmukh

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.

就我而言,我使用的是 ASM 库版本并且不支持 java 8 lambda 表达式,因此您要么更改 ASM 库以支持 java 8,要么更改您的代码。

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

就我而言,我使用 java 8 lambda 表达式进行迭代,并将其替换为 for 循环