Preparing for Java Interview?

My books Grokking the Java Interview and Grokking the Spring Boot Interview can help

Download PDF

How to Fix java.lang.VerifyError: Expecting a stack map frame at branch target 14 in method at offset JDK 7 [Solved]

Hello guys, today, we'll take a look at the not-so-common error for Java applications. If you have been working in Java for a couple of years then you might have seen this dreaded "java.lang.VerifyError: Expecting a stack map frame at branch target 14 in method at offset JDK 7" error in your application log or in Eclipse, particularly if you are running your Java application in Java 7. The main cause of this error, "java.lang.VerifyError: Expecting a stack map frame at branch target ... in the method ... at offset 0 error comes when you have some library, JAR file which is only compatible with Java 1.6 or below and you are running your program in JDK 1.7.

Explanation

Java 7 introduced a stricter verification and changed the class format a bit to contain a stack map, used to verify that code is correct. The exception you see means that some method doesn't have a valid stack map.

Java version or bytecode instrumentation could both be blame. Usually, this means that a library that the application uses generates invalid bytecode that doesn't pass the stricter verification. So nothing else than reporting it as a bug to the library can be done by the developer.

As a workaround, you can also add -noverify to the JVM arguments in order to disable verification. 

In Java 7 it was also possible to use -XX:-UseSplitVerifier to use the less strict verification method of the previous version which can handle these missing stack map frames, but that option is also removed in Java 8.

Solution

If you are running in Java 7 then there are two solutions:

1) Just use JDK 1.6, it will not do strict bytecode verification as JDK 7 but hey we have been running it for a long time, so no issue.

2) If you don't want to downgrade on Java 1.6 and are rather happy running with Java 1.7 then add -XX:-UseSplitVerifier into your list of JVM arguments which you are passing to your Java program. Did you notice the "-" sign in front of UseSplitVerifier? This is actually telling JVM to don't use that bytecode verifier.

If you are using Eclipse, you can add this JVM argument as follows :

Windows, Preferences, Java, Installed JREs, Edit, Default VM arguments

java.lang.VerifyError: Expecting a stack map frame at branch target 14 in method at offset JDK 7 [Solved]

If you are new to Eclipse and want to learn more about it, you can also check out Eclipse Tutorial For Beginners: Learn Java IDE in 10 Steps, another free Eclipse course on Udemy. It's also a good course to start learning Eclipse from scratch.


See stack trace here :

java.lang.VerifyError: Expecting a stackmap frame at branch target 14 in method 
gwtone.server.TestServlet.doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet
/http/HttpServletResponse;)V at offset 0
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
    at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)



That's all about how to fix java.lang.VerifyError in Java, particularly the "java.lang.VerifyError: Expecting a stack map frame at branch target 14 in method at offset JDK 7" error.



Other Java troubleshooting articles you may like:
  • java.sql.SQLException: No suitable driver found for 'jdbc:mysql://localhost:3306/mysql [Solution]
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver error? (hint)
  • How to solve java.lang.OutOfMemoryError: Java Heap Space in Eclipse, Tomcat? (solution)
  • How to fix "Error: Could not find or load main class" in Eclipse? (guide)
  • How to solve java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver? (solution)
  • java.sql.SQLServerException: The index 58 is out of range - JDBC (solution)
  • How to fix Caused By: java.lang.NoClassDefFoundError: org/apache/log4j/Logger (solution)
  • How to fix 'javac' is not recognized as an internal or external command (solution)
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory error (solution)
  • Common reasons of java.lang.ArrayIndexOutOfBoundsException in Java? (solution)
  • java.lang.ClassNotFoundException : 
  • How to avoid ConcurrentModificationException in Java? (tutorial)
  • org.Springframework.Web.Context.ContextLoaderListener (solution)
  • How to connect to MySQL database in Java? (tutorial)
  • Fixing java.lang.UnsupportedClassVersionError Unsupported major.minor version 50.0 (solution)
  • How to solve "could not create the Java virtual machine" error in Java? (solution)
  • 10 common reasons for java.lang.NumberFormatException in Java? (tutorial)
  • How to fix the "illegal start of expression" compile-time error in Java? (tutorial)
  • Cause and solution of "class, interface, or enum expected" compiler error in Java? (fix)
  • How to solve "variable might not have initialized" compile-time error in Java? (answer)

Thanks for reading this article, if you like this article then please share it with your friends and colleagues too. If you have any doubt or questions then please drop a comment.

No comments:

Post a Comment

Feel free to comment, ask questions if you have any doubt.