More Java posts
March 28, 2002
java.lang.VerifyError

I've recently spent some time dealing with a java.lang.VerifyError exception that turned out to be due to a simple typo. In the interests of helping others, and revealing my own bad typing, I'm posting the results here.

Here's a simple class that demonstrates the problem. The one I originally found it in was more complex and it took me a while to track down the simple mistake.

public class Test {

    public static void main(String[] args) {

        for (int i = 1; i < 3; ++i) {
            System.out.println("2 i = " + i);
        }
    }
}

If you compile and run it it simply prints

2 i = 1
2 i = 2

Now what happens if you make a typo and put for (int i = i... instead of for (int i = i..? Well, you get a compile error just like you should.

Test.java:5: variable i might not have been initialized
        for (int i = i; i < 3; ++i) {
                     ^
1 error

But if you have another variable called i referenced before this one the code compiles correctly. So, the program below will compile even though it also makes reference to an uninitialized variable as the two variables called i are different variables.

public class Test {

    public static void main(String[] args) {

        for (int i = 1; i < 3; ++i) {
            System.out.println("1 i = " + i);
        }
        for (int i = i; i < 3; ++i) {
            System.out.println("2 i = " + i);
        }
    }
}

However, when you try and execute the code you get this error message.

Exception in thread "main" java.lang.VerifyError: (class: Test, method: main sig
nature: ([Ljava/lang/String;)V) Accessing value from uninitialized register 2

It took me some time to go from this message to the actual problem. In my defense I'd like to say that the actual code also includes a whole bunch of XML and JDBC processing and was trying to access a database though a JDBC connection provided by Weblogic. With all of the third party jar files that had to be present for compiling and running I was sure for a while that it was some version mismatch somewhere.

Posted by Alex at March 28, 2002 10:29 AM
Comments
Hi We got java.lang.verifyError,we are using jakarta-tomcat-4.0,jboss-3.0.0 and jdk1.3 for our EJB Project.if this is for version problem,pls give some advice, Regards Rajesh.B Posted by: Rajesh on October 20, 2002 11:19 PM
Wish I'd found you before I spent a few hours arriving at the same conclusion.. This _has_ to be an error in javac!? Posted by: steve on February 6, 2003 08:27 AM
Got this problem with jdk1.2.2. It turned out that in (view source code of this page to see formatted java-sourcecode): protected void testVerifyError() { String id = null; Statement stmt = null; StringBuffer sqlstat = new StringBuffer("select s_startseite_proto.nextval from dual"); int res = 0; try { stmt = con.createStatement(); synchronized (this) { if (stmt == null) { //return; } } } catch (SQLException e) { } finally { try { if (stmt != null) { stmt.close(); } } catch (SQLException e) { ShopServlet.writeLog( "DataBase:registerStart->SQLException (" + e + ") at closing statement"); } } return; } the return within the synchronized is a problem. if I comment out the sychronized block and uncomment the "return"statement, it works. Posted by: Erik Pischel on November 17, 2003 10:06 AM
Hi, I am getting the fallowing exception in jre1.3. But same program is running in jre1.4. The program is reading a xml file using jasper reports E:\Jasper>java Report Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/parsers/Par serConfigurationException at Report.main(Report.java:18) E:\Jasper>set classpath=%classpath%;e:\xerces.jar; E:\Jasper>java Report Exception in thread "main" java.lang.VerifyError: (class: org/apache/xerces/util /SecuritySupport12$1, method: signature: (Lorg/apache/xerces/util/Securit ySupport12;)V) Expecting to find object/array on stack at org.apache.xerces.util.SecuritySupport12.getContextClassLoader(Securi tySupport12.java:73) at org.apache.xerces.util.ObjectFactory.findClassLoader(ObjectFactory.ja va:227) at org.apache.xerces.util.ObjectFactory.createObject(ObjectFactory.java: 156) at org.apache.xerces.util.ObjectFactory.createObject(ObjectFactory.java: 123) at org.apache.xerces.parsers.SAXParser.(SAXParser.java) at org.apache.xerces.parsers.SAXParser.(SAXParser.java) at org.apache.xerces.jaxp.SAXParserImpl.(SAXParserImpl.java:102) at org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParserImpl(SAXParse rFactoryImpl.java:112) at org.apache.xerces.jaxp.SAXParserFactoryImpl.setFeature(SAXParserFacto ryImpl.java:140) at org.apache.commons.digester.Digester.setFeature(Digester.java:570) at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.configureDigeste r(JRXmlDigesterFactory.java:88) at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(J RXmlDigesterFactory.java:296) at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:330 ) at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:295 ) at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:279 ) at Report.main(Report.java:18) Posted by: Venkaiah on May 13, 2005 01:58 AM
Interesting problem, but it took me a while to spot the typo, due to the typo in the explanation! I guess it should read: "..make a typo and put for (int i = i... instead of for (int i = 1..?" Posted by: Neil on February 15, 2006 08:43 AM
public class Test { public static void main(String[] args) { for (int i = 1; i < 3; ++i) { System.out.println("1 i = " + i); } for (int i = i; i < 3; ++i) { System.out.println("2 i = " + i); } } } This will never compile on jdk 1.4.2_10. Posted by: Balkrishna on May 4, 2006 08:18 AM
I am getting this error while executing a java program,please help me to sort out this problem. Exception in thread "main" java.lang.NoClassDefFoundError: org.apache.axis.encoding.ser.BeanDeserializer at java.lang.Class.initializeClass (libgcj.so.7) at java.lang.Class.forName (libgcj.so.7) at java.lang.Class.forName (libgcj.so.7) at org.apache.axis.encoding.ser.BeanDeserializerFactory.class$ (BeanDeserializerFactory.java:42) at org.apache.axis.encoding.ser.BeanDeserializerFactory. (BeanDeserializerFactory.java:42) at org.apache.axis.encoding.DefaultTypeMappingImpl. (DefaultTypeMappingImpl.java:496) at org.apache.axis.encoding.DefaultTypeMappingImpl.getSingleton (DefaultTypeMappingImpl.java:88) at org.apache.axis.encoding.TypeMappingRegistryImpl. (TypeMappingRegistryImpl.java:140) at org.apache.axis.deployment.wsdd.WSDDDeployment. (WSDDDeployment.java:503) at org.apache.axis.deployment.wsdd.WSDDDocument.setDocument (WSDDDocument.java:139) at org.apache.axis.deployment.wsdd.WSDDDocument. (WSDDDocument.java:66) at org.apache.axis.configuration.FileProvider.configureEngine (FileProvider.java:179) at org.apache.axis.AxisEngine.init (AxisEngine.java:187) at org.apache.axis.AxisEngine. (AxisEngine.java:169) at org.apache.axis.client.AxisClient. (AxisClient.java:49) at org.apache.axis.client.Service.getAxisClient (Service.java:104) at org.apache.axis.client.Service. (Service.java:113) at org.oasis.wsrf.properties.WSResourcePropertiesServiceLocator. (WSResourcePropertiesServiceLocator.java:25) at org.oasis.wsrf.properties.WSResourcePropertiesServiceAddressingLocator. (WSResourcePropertiesServiceAddressingLocator.java:10) at QueryMds. (QueryMds.java:27) at java.lang.Class.initializeClass (libgcj.so.7) at java.lang.Class.forName (libgcj.so.7) at gnu.java.lang.MainThread.run (libgcj.so.7) Caused by: java.lang.VerifyError: verification failed at PC 104 in org.apache.axis.encoding.ser.BeanDeserializer:handleMixedContent(()V): incompatible type on stack at java.lang.Class.initializeClass (libgcj.so.7) ...22 more Posted by: vivek on November 13, 2006 01:12 AM
package com.pgs.tma; import org.apache.xerces.parsers.SAXParser; import java.io.*; import java.io.IOException; import org.xml.sax.*; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; public class try4c { public void validateSchema(String SchemaUrl, String XmlDocumentUrl) { System.out.println("inside"); SAXParser parser = new SAXParser(); try { parser.setFeature("http://xml.org/sax/features/validation",true); parser.setFeature("http://apache.org/xml/features/validation/schema",true); parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", SchemaUrl ); Validator handler=new Validator(); parser.setErrorHandler(handler); parser.parse(XmlDocumentUrl); if(handler.validationError==true) System.out.println("XML Document has Error:"+handler.validationError+""+handler.saxParseException.getMessage()); else System.out.println("XML Document is valid"); } catch(java.io.IOException ioe){ System.out.println("IOException"+ioe.getMessage()); }catch (SAXException e) { System.out.println("SAXException"+e.getMessage()); } } class Validator extends DefaultHandler { public boolean validationError = false; public SAXParseException saxParseException=null; public void error(SAXParseException exception) throws SAXException { validationError=true; saxParseException=exception; } public void fatalError(SAXParseException exception) throws SAXException { validationError = true; saxParseException=exception; } public void warning(SAXParseException exception) throws SAXException {} } /*} public class try4a {*/ public static void main(String[] argv) { //System.out.println(argv.length); String SchemaUrl=argv[0]; String XmlDocumentUrl=argv[1]; System.out.println(SchemaUrl); System.out.println(XmlDocumentUrl); try{ // try4c validator=new try4c(); } catch(Exception e){ e.printStackTrace(); } System.out.println("oc"); // validator.validateSchema(SchemaUrl, XmlDocumentUrl); // validateSchema(SchemaUrl, XmlDocumentUrl); } } hii All.... do anybody have any idea why its showing this error: java.lang.VerifyError: (class: com/pgs/tma/try3, method: process signature: ()V) Incompatible object argument for method call at com.pgs.tma.try3demo.main(try3demo.java:74) Exception in thread "main" ...... can i do something to remove this error Posted by: Navneet on November 22, 2006 12:41 AM
Hi! I am unable to compile the code. The code posted never complies. It throws a error stating that variable i is is not initialized. So how can this ever be a typo error. Or I am missing something here. Kanu Posted by: Kanu on January 13, 2007 01:51 AM
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?