获取 java.lang.VerifyError 的原因

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/100107/
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 08:17:35  来源:igfitidea点击:

Causes of getting a java.lang.VerifyError

javaexceptiondeploymentverifyerror

提问by Jeroen Wyseur

I'm investigating the following java.lang.VerifyError

我正在调查以下内容 java.lang.VerifyError

java.lang.VerifyError: (class: be/post/ehr/wfm/application/serviceorganization/report/DisplayReportServlet, method: getMonthData signature: (IILjava/util/Collection;Ljava/util/Collection;Ljava/util/HashMap;Ljava/util/Collection;Ljava/util/Locale;Lorg/apache/struts/util/MessageRe??ì′Mtì′M??w?m?§w?mp:?”M????
                at java.lang.Class.getDeclaredConstructors0(Native Method)
                at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
                at java.lang.Class.getConstructor0(Class.java:2671)

It occurs when the jboss server in which the servlet is deployed is started. It is compiled with jdk-1.5.0_11 and I tried to recompile it with jdk-1.5.0_15 without succes. That is the compilation runs fine but when deployed, the java.lang.VerifyError occurs.

它发生在部署 servlet 的 jboss 服务器启动时。它是用 jdk-1.5.0_11 编译的,我尝试用 jdk-1.5.0_15 重新编译它,但没有成功。那是编译运行良好,但在部署时,会发生 java.lang.VerifyError。

When I changed the method name and got the following error:

当我更改方法名称并收到以下错误时:

java.lang.VerifyError: (class: be/post/ehr/wfm/application/serviceorganization/report/DisplayReportServlet, method: getMD signature: (IILjava/util/Collection;Lj    ava/util/Collection;Ljava/util/HashMap;Ljava/util/Collection;Ljava/util/Locale;Lorg/apache/struts/util/MessageResources┬á├?├àN|├?├àN├üw┬?m├ow┬?mX#├?M|X├?M
            at java.lang.Class.getDeclaredConstructors0(Native Method)
            at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357
            at java.lang.Class.getConstructor0(Class.java:2671)
            at java.lang.Class.newInstance0(Class.java:321)
            at java.lang.Class.newInstance(Class.java:303)

You can see that more of the method signature is shown.

您可以看到显示了更多的方法签名。

The actual method signature is

实际的方法签名是

  private PgasePdfTable getMonthData(int month, int year, Collection dayTypes,
                          Collection calendarDays,
                          HashMap bcSpecialDays,
                          Collection activityPeriods,
                          Locale locale, MessageResources resources) throws   Exception {

I already tried looking at it with javapand that gives the method signature as it should be.

我已经试过用它来查看它,javap这给出了它应该的方法签名。

When my other colleagues check out the code, compile it and deploy it, they have the same problem. When the build server picks up the code and deploys it on development or testing environments (HPUX), the same error occurs. Also an automated testing machine running Ubuntu shows the same error during server startup.

当我的其他同事检查代码,编译它并部署它时,他们遇到了同样的问题。当构建服务器获取代码并将其部署到开发或测试环境 (HPUX) 时,会发生同样的错误。在服务器启动期间,运行 Ubuntu 的自动测试机也显示相同的错误。

The rest of the application runs okay, only that one servlet is out of order. Any ideas where to look would be helpful.

应用程序的其余部分运行正常,只有一个 servlet 出现故障。任何去哪里寻找的想法都会有所帮助。

采纳答案by Kevin Panko

java.lang.VerifyErrorcan be the result when you have compiled against a different library than you are using at runtime.

java.lang.VerifyError当您针对与运行时使用的库不同的库进行编译时,可能会产生这种结果。

For example, this happened to me when trying to run a program that was compiled against Xerces 1, but Xerces 2 was found on the classpath. The required classes (in org.apache.*namespace) were found at runtime, so ClassNotFoundExceptionwas notthe result. There had been changes to the classes and methods, so that the method signatures found at runtime did not match what was there at compile-time.

例如,当我尝试运行针对 Xerces 1 编译的程序时,就发生了这种情况,但在类路径中发现了 Xerces 2。所需的类(在org.apache.*命名空间)在运行时被发现,所以ClassNotFoundException没有结果。类和方法发生了变化,因此在运行时发现的方法签名与编译时存在的方法签名不匹配。

Normally, the compiler will flag problems where method signatures do not match. The JVM will verify the bytecode again when the class is loaded, and throws VerifyErrorwhen the bytecode is trying to do something that should not be allowed -- e.g. calling a method that returns Stringand then stores that return value in a field that holds a List.

通常,编译器会标记方法签名不匹配的问题。JVM 将在类加载时再次验证字节码,并VerifyError在字节码尝试做一些不应被允许的事情时抛出- 例如调用一个返回的方法,String然后将该返回值存储在一个包含List.

回答by Lars Westergren

This page may give you some hints - http://www.zanthan.com/itymbi/archives/000337.html

这个页面可能会给你一些提示 - http://www.zanthan.com/itymbi/archives/000337.html

There may be a subtle bug in the body of that method that javac fails to spot. Difficult to diagnose unless you post the whole method here.

该方法的主体中可能存在 javac 未能发现的细微错误。除非您在此处发布整个方法,否则很难诊断。

You could start by declaring as many variables as possible as final... that would have caught the bug mentioned on the zanthan site, and is often a good practice anyways.

您可以首先声明尽可能多的变量作为最终变量......这会发现 zanthan 站点上提到的错误,并且无论如何通常是一个很好的做法。

回答by p3t0r

java.lang.VerifyErrorare the worst.

java.lang.VerifyError是最糟糕的。

You would get this error if the bytecode size of your method exceeds the 64kb limit; but you would probably have noticed that.

如果您的方法的字节码大小超过 64kb 限制,您将收到此错误;但你可能已经注意到了。

Are you 100% sure this class isn't present in the classpath elsewhere in your application, maybe in another jar?

您是否 100% 确定此类不存在于应用程序其他地方的类路径中,也许在另一个 jar 中?

Also, from your stacktrace, is the character encoding of the source file (utf-8?) Is that correct?

另外,从您的堆栈跟踪中,源文件的字符编码(utf-8?)是否正确?

回答by Alex Miller

One thing you might try is using -Xverify:allwhich will verify bytecode on load and sometimes gives helpful error messages if the bytecode is invalid.

您可能会尝试的一件事是使用-Xverify:all它将在加载时验证字节码,如果字节码无效,有时会提供有用的错误消息。

回答by Mike Miller

I was getting this problem due to pack200 mangling a class file. A bit of searching turned this java bugup. Basically, setting --effort=4caused the problem to go away.

由于 pack200 修改了类文件,我遇到了这个问题。稍微搜索一下就发现了这个java 错误。基本上,设置--effort=4导致问题消失。

Using java 1.5.0_17 (though it cropped up in every single variant of java 1.5 I tried it in).

使用 java 1.5.0_17(尽管它出现在我尝试过的每个 java 1.5 变体中)。

回答by Michael Borgwardt

VerifyError means that the class file contains bytecode that is syntactically correct but violates some semantic restriction e.g. a jump target that crosses method boundaries.

VerifyError 意味着类文件包含语法正确但违反某些语义限制的字节码,例如跨越方法边界的跳转目标。

Basically, a VerifyError can only occur when there is a compiler bug, or when the class file gets corrupted in some other way (e.g. through faulty RAM or a failing HD).

基本上,VerifyError 只会在存在编译器错误或类文件以某种其他方式损坏时(例如,由于 RAM 故障或 HD 故障)发生。

Try compiling with a different JDK version and on a different machine.

尝试使用不同的 JDK 版本在不同的机器上进行编译。

回答by Flow

As Kevin Panko said, it's mostly because of library change. So in some cases a "clean" of the project (directory) followed by a build does the trick.

正如 Kevin Panko 所说,这主要是因为图书馆的变化。因此,在某些情况下,对项目(目录)进行“清理”,然后进行构建即可解决问题。

回答by Tiago

I fixed this error on Android by making the project I was importing a library, as described here http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject

我通过制作我正在导入库的项目来修复了 Android 上的此错误,如此处所述http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject

Previously, I was just referencing the project (not making it a library) and I was getting this strange VerifyError.

以前,我只是在引用该项目(而不是将其作为库),并且遇到了这个奇怪的 VerifyError。

Hope it helps someone.

希望它可以帮助某人。

回答by 18446744073709551615

I have fixed a similar java.lang.VerifyError issue by replacing

我通过替换修复了一个类似的 java.lang.VerifyError 问题

        catch (MagickException e)

with

        catch (Exception e)

where MagickExceptionwas defined in a library project (on which my project has a dependency).

whereMagickException是在库项目中定义的(我的项目依赖于此)。

After that I have got a java.lang.NoClassDefFoundErrorabout a class from the same library (fixed according to https://stackoverflow.com/a/9898820/755804).

之后,我java.lang.NoClassDefFoundError从同一个库中获得了一个类(根据https://stackoverflow.com/a/9898820/755804修复)。

回答by Martin Konicek

This can happen on Android when you're trying to load a library that was compiled against Oracle's JDK.

当您尝试加载针对 Oracle 的 JDK 编译的库时,这可能会在 Android 上发生。

Here is the problemfor Ning Async HTTP client.

这是Ning Async HTTP 客户端的问题