Search code examples
javamacosstack-overflow

StackOverFlowError when using SAXReader after Java security update


Running a Mac (OS X 10.8.1). We were upgraded to the latest Java security update 1.6.0_35-b10-428 and since then our main app doesn't launch in Eclipse.

The Exception below is thrown when starting up Openfire 3.6.4. Pretty much where the openfire.xml config is parsed is when the error occurs:

 private void buildDoc(Reader in) throws IOException {
    try {
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
        document = xmlReader.read(in);
    }
    catch (Exception e) {
        Log.error("Error reading XML properties", e);
        System.out.println("NOOO");
        e.printStackTrace();
        throw new IOException(e.getMessage());
    }
    finally {
        if (in != null) {
            in.close();
        }
    }
}

Exception thrown:

Exception in thread "main" java.lang.StackOverflowError
at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:52)
at java.nio.ByteBuffer.wrap(ByteBuffer.java:350)
at java.nio.ByteBuffer.wrap(ByteBuffer.java:373)
at java.lang.StringCoding$StringEncoder.encode(StringCoding.java:237)
at java.lang.StringCoding.encode(StringCoding.java:272)
at java.lang.String.getBytes(String.java:946)
at java.io.UnixFileSystem.getBooleanAttributes0(Native Method)
at java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:228)
at java.io.File.exists(File.java:733)
at sun.misc.URLClassPath$FileLoader.getResource(URLClassPath.java:999)
at sun.misc.URLClassPath.getResource(URLClassPath.java:169)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.dom4j.DocumentFactory.createDocument(DocumentFactory.java:102)
at org.dom4j.DocumentFactory.createDocument(DocumentFactory.java:122)
at org.dom4j.io.SAXContentHandler.createDocument(SAXContentHandler.java:830)
at org.dom4j.io.SAXContentHandler.getDocument(SAXContentHandler.java:164)
at org.dom4j.io.SAXContentHandler.comment(SAXContentHandler.java:428)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.comment(AbstractSAXParser.java:667)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.comment(XMLDTDValidator.java:978)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:479)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.dom4j.io.SAXReader.read(SAXReader.java:365)
at org.jivesoftware.util.XMLProperties.buildDoc(XMLProperties.java:471)
at org.jivesoftware.util.XMLProperties.<init>(XMLProperties.java:114)
at org.jivesoftware.util.XMLProperties.<init>(XMLProperties.java:63)
at org.jivesoftware.util.JiveGlobals.loadSetupProperties(JiveGlobals.java:832)
at org.jivesoftware.util.JiveGlobals.getXMLProperty(JiveGlobals.java:282)
at org.jivesoftware.util.JiveGlobals.isSetupMode(JiveGlobals.java:791)
at org.jivesoftware.util.JiveGlobals.getProperty(JiveGlobals.java:529)
at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:300)
at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:419)
at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:163)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:106)
at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:51)

Edit: Added Xss1m as suggested, but whilst the application got further I'm seeing the same error. Here's my startup args:

here's my startup args:

-DopenfireHome="${workspace_loc:openfire}/target/openfire" -Djava.net.preferIPv4Stack=true -Xms32m -Xmx512m -Xss1m -XX:ThreadStackSize=128 -XX:PermSize=72m -XX:MaxPermSize=96m -XX:+PrintGCDetails -Xloggc:/tmp/gc.log -XX:+HeapDumpOnOutOfMemoryError

Edit2:

Seems the below amendments work: amending -Xss128k to -Xss1m and removing -XX:ThreadStackSize=128


Solution

  • Did you try increasing stack size? You can do it by specifying -Xss1m when starting JVM. In the example JVM will allocate 1 Megabyte for stack for each thread. Be careful not to use too big a value as it will be multiplied by the number of threads in your application.

    To change configuration in Eclipse, please follow these steps (copied from here).


    Open the Run Configuration for your application (Run/Run Configurations..., then look for the applications entry in 'Java application').

    The arguments tab has a text box Vm arguments, enter -Xss1m (or a bigger parameter for the maximum stack size). The default value is 512 kByte.


    EDIT:

    It looks like it's a common issue. Security patch probably introduced another method call to the chain and all projects that used to fit into the stack don't fit anymore.