Table of Contents
示例
输出
结论
Home Java javaTutorial Why does Java.lang.VerifyError error occur in Java and how to solve this problem?

Why does Java.lang.VerifyError error occur in Java and how to solve this problem?

Sep 23, 2023 pm 10:13 PM
mistake Solve the problem programmingjavalangverifyerror

Why does Java.lang.VerifyError error occur in Java and how to solve this problem?

Java.lang.VerifyError 是由 JVM(Java 虚拟机)引发的运行时错误。在运行时,验证过程会检查加载的有效性。 class 文件,如果 .class 文件违反任何约束,那么 JVM 将给出 Java.lang.VerifyError 错误。 Java 1.0 版本及更高版本中存在以下错误。

java.lang.LinkageError 扩展了 Java.lang.VerifyError,它指的是程序的链接过程出现问题时。

Java.lang.VerifyError在输出中的样子将会是:

Exception in thread "main" java.lang.VerifyError: (class: com/example/Way2Class, method: myMethod signature: ()V) Incompatible argument to function
   at com.example.MyClass.main(MyClass.java:10)
Copy after login

此输出包含导致错误的类的名称 (Way2class)、类路径 (com/example/Way2Class)、错误行 (10)、方法名称 (myMethod) 和错误消息(线程“main”java 中的异常) .lang.VerifyError)

出现此错误的原因有多种,如下所示:

  • 版本不匹配:需要注意的是,如果类文件是使用与执行代码所使用的Java编译器版本不同的版本进行编译的话,可能会导致VerifyError。

示例

public class VerifyErrorVersionExample {
   public static void main(String[] args) {
      System.out.println("Hello, program!");
   }
}
Copy after login

在该特定程序使用 Java 9 编译并在早期版本(例如 Java 8)上运行的情况下,输出将显示后续错误解释:

输出

Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
   Location:
      VerifyErrorVersionExample.main([Ljava/lang/String;)V @2: invokestatic
   Reason:
      Type 'java/lang/invoke/StringConcatFactory' (current frame, stack[0]) is not assignable to 'java/lang/invoke/MethodHandle'
   Current Frame:
      bci: @2
      flags: { }
      locals: { '[Ljava/lang/String;' }
      stack: { 'java/lang/invoke/StringConcatFactory' }
   Bytecode:
      0x0000000:  getstatic    #2   // Field java/lang/System.out:Ljava/io/PrintStream;
      0x0000003:  ldc          #3   // String Hello, world!
      0x0000005:  invokestatic #4   // Method java/lang/invoke/StringConcatFactory.makeConcatWithConstants:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/MethodHandle;
      0x000000a:  ldc          #5   // String 
      0x000000c:  iconst_1
      0x000000d:  anewarray   #6   // class java/lang/Object
      0x0000010:  dup
      0x0000011:  iconst_0
      0x0000012:  ldc          #7   // String !!!
      0x0000014:  aastore
      0x0000015:  invokevirtual #8   // Method java/lang/invoke/MethodHandle.invokeExact:([Ljava/lang/Object;)Ljava/lang/Object;
      0x000001a:  checkcast   #9   // class java/lang/String
      0x000001d:  invokevirtual #10  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      0x0000020:  return  
Copy after login
  • 字节码损坏:如果对类文件的字节码进行修改或损坏,可能会出现错误。

示例

public class VerifyErrorBytecodeExample {
   public static void main(String[] args) {
      int a = 10;
      int b = 20;
      int c = a + b;
      System.out.println("The sum of " + a + " and " + b + " is " + c);
   }
}
Copy after login

输出

Exception in thread "main" java.lang.VerifyError: (class: VerifyErrorBytecodeExample, method: main signature: ([Ljava/lang/String;)V) Illegal target of jump or branch
      at java.lang.Class.getDeclaredMethods0(Native Method)
      at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
      at java.lang.Class.getDeclaredMethod(Class.java:2128)
      at java.io.ObjectStreamClass.getPrivateMethod(ObjectStreamClass.java:1743)
      at java.io.ObjectStreamClass.access$1700(ObjectStreamClass.java:72)
      at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:513)
      at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:492)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:492)
      at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:389)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1134)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
      at VerifyErrorBytecodeExample.main(VerifyErrorBytecodeExample.java:6)
Copy after login
  • 类文件不一致:如果类文件违反了Java虚拟机规范所强制的某些约束条件。

示例

public class VerifyErrorExample {
   public static void main(String[] args) {
      Animal animal = new Cat();
      animal.speak();
   }
}
interface Animal {
   void speak();
}
class Dog implements Animal {
   public void speak() {
      System.out.println("Woof!");
   }
}
class Cat extends Dog {
   public void speak() {
      System.out.println("Meow!");
   }
}
Copy after login

这个程序定义了一个‘Animal’接口和两个实现它的具体类:Dog和Cat。Cat继承了Dog并重写了它的speak方法。在主方法中,我们创建了一个Cat实例并调用了它的speak方法。

假设我们选择从当前类路径中取出 Dog 类,然后重新编译并运行我们的程序,将会显示 java.lang。验证错误。此错误将显示如下错误消息:

输出

Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
   Location:
      VerifyErrorExample.main([Ljava/lang/String;)V @2: invokevirtual
   Reason:
      Type 'Cat' (current frame, stack[0]) is not assignable to 'Dog'
   Current Frame:
      bci: @2
      flags: { }
      locals: { '[Ljava/lang/String;' }
      stack: { 'Cat' }
   Bytecode:
      0000000:  new           #2                  // class Cat
      0000003:  dup
      0000004:  invokespecial #3                  // Method Cat."":()V
      0000007:  astore_1
      0000008:  aload_1
      0000009:  invokevirtual #4                  // Method Animal.speak:()V
      000000c:  return
Copy after login

结论

总之,遇到java.lang.VerifyError错误可能是由于各种原因引起的,包括字节码波动、安全计算实践中的限制,以及代码库中包含的Java组件的不一致互相依赖版本等等。在运行时,确保所有使用的库与您的系统和其他依赖库兼容是避免此问题的一种非常重要的方式。遵守这些要求将确保遵守Java的字节码规定,避免出现问题的编码实践,例如不符合安全协议或提交具有类文件不一致性的代码,这可能导致后续出现错误。每当java.lang.VerifyError出现时,必须仔细检查相关的错误消息以及您可以获取的堆栈跟踪,以确定正在发生的确切问题并采取必要的纠正措施。

The above is the detailed content of Why does Java.lang.VerifyError error occur in Java and how to solve this problem?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Unable to complete operation (Error 0x0000771) Printer error Unable to complete operation (Error 0x0000771) Printer error Mar 16, 2024 pm 03:50 PM

If you encounter an error message when using your printer, such as the operation could not be completed (error 0x00000771), it may be because the printer has been disconnected. In this case, you can solve the problem through the following methods. In this article, we will discuss how to fix this issue on Windows 11/10 PC. The entire error message says: The operation could not be completed (error 0x0000771). The specified printer has been deleted. Fix 0x00000771 Printer Error on Windows PC To fix Printer Error the operation could not be completed (Error 0x0000771), the specified printer has been deleted on Windows 11/10 PC, follow this solution: Restart Print Spool

Windows Sandbox startup failed - Access Denied Windows Sandbox startup failed - Access Denied Feb 19, 2024 pm 01:00 PM

Does Windows Sandbox terminate with Windows Sandbox Unable to Start, Error 0x80070005, Access Denied message? Some users reported that Windows Sandbox cannot be opened. If you also encounter this error, you can follow this guide to fix it. Windows Sandbox failed to start - Access Denied If Windows Sandbox terminates with Windows Sandbox Unable to Start, Error 0x80070005, Access Denied message, make sure you are logged in as an administrator. This type of error is usually caused by insufficient permissions. So try logging in as an administrator and see if that resolves the issue. If the problem persists, you can try the following solutions: Run the Wi-Fi as administrator

Revealing the causes of HTTP status code 460 Revealing the causes of HTTP status code 460 Feb 19, 2024 pm 08:30 PM

Decrypting HTTP status code 460: Why does this error occur? Introduction: In daily network use, we often encounter various error prompts, including HTTP status codes. These status codes are a mechanism defined by the HTTP protocol to indicate the processing of a request. Among these status codes, there is a relatively rare error code, namely 460. This article will delve into this error code and explain why this error occurs. Definition of HTTP status code 460: First, we need to understand the basics of HTTP status code

Solution to Windows Update prompt Error 0x8024401c error Solution to Windows Update prompt Error 0x8024401c error Jun 08, 2024 pm 12:18 PM

Table of Contents Solution 1 Solution 21. Delete the temporary files of Windows update 2. Repair damaged system files 3. View and modify registry entries 4. Turn off the network card IPv6 5. Run the WindowsUpdateTroubleshooter tool to repair 6. Turn off the firewall and other related anti-virus software. 7. Close the WidowsUpdate service. Solution 3 Solution 4 "0x8024401c" error occurs during Windows update on Huawei computers Symptom Problem Cause Solution Still not solved? Recently, the web server needs to be updated due to system vulnerabilities. After logging in to the server, the update prompts error code 0x8024401c. Solution 1

The server encountered an error, 0x80070003, while creating a new virtual machine. The server encountered an error, 0x80070003, while creating a new virtual machine. Feb 19, 2024 pm 02:30 PM

If you encounter error code 0x80070003 when using Hyper-V to create or start a virtual machine, it may be caused by permission issues, file corruption, or configuration errors. Solutions include checking file permissions, repairing damaged files, ensuring correct configuration, and more. This problem can be solved by ruling out the different possibilities one by one. The entire error message looks like this: The server encountered an error while creating [virtual machine name]. Unable to create new virtual machine. Unable to access configuration store: The system cannot find the path specified. (0x80070003). Some possible causes of this error include: The virtual machine file is corrupted. This can happen due to malware, virus or adware attacks. Although the likelihood of this happening is low, you can't completely

Fix Pioneer Error Code Kadena-Keesler Fix Pioneer Error Code Kadena-Keesler Feb 19, 2024 pm 02:20 PM

If you encounter the Kadena-Keesler error while playing Call of Duty: Vanguard, this article may be helpful to you. According to feedback from some players, the game has this problem on Windows PC, Xbox, PlayStation and other platforms. When triggered, you may receive the following error message: Connection failed No network connection failed. You must have an active internet connection to play online or over a local network. [Reason: Kadena-Keesler] You may also receive the following error message: Connection failed Unable to access online services. [Reason: Kadena-Keesler] Another instance of this error on Xbox is as follows: You must have an active network connection

Interpreting Oracle error 3114: causes and solutions Interpreting Oracle error 3114: causes and solutions Mar 08, 2024 pm 03:42 PM

Title: Analysis of Oracle Error 3114: Causes and Solutions When using Oracle database, you often encounter various error codes, among which error 3114 is a relatively common one. This error generally involves database link problems, which may cause exceptions when accessing the database. This article will interpret Oracle error 3114, discuss its causes, and give specific methods to solve the error and related code examples. 1. Definition of error 3114 Oracle error 3114 pass

Resolve code 0xc000007b error Resolve code 0xc000007b error Feb 18, 2024 pm 07:34 PM

Termination Code 0xc000007b While using your computer, you sometimes encounter various problems and error codes. Among them, the termination code is the most disturbing, especially the termination code 0xc000007b. This code indicates that an application cannot start properly, causing inconvenience to the user. First, let’s understand the meaning of termination code 0xc000007b. This code is a Windows operating system error code that usually occurs when a 32-bit application tries to run on a 64-bit operating system. It means it should

See all articles