0
votes

I have a Java project running in Oracle weblogic. We are using apache-commons-chains. We intermittantly get EmptyStackException when trying to parse the XML. Most of the time XML works. But sometimes we get this issue.

I have trying running and debugging code on local machines. Never found an issue there. Here is the log stack

java.util.EmptyStackException at org.apache.commons.collections.ArrayStack.pop(ArrayStack.java:122) at org.apache.commons.digester.Digester.endElement(Digester.java:1208) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609) at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:183) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1343) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648) at weblogic.xml.jaxp.WebLogicXMLReader.parse(WebLogicXMLReader.java:133) at weblogic.xml.jaxp.RegistryXMLReader.parse(RegistryXMLReader.java:173) at org.apache.commons.digester.Digester.parse(Digester.java:1827) at org.apache.commons.chain.config.ConfigParser.parse(ConfigParser.java:190)

public Catalog getCatalog() throws Exception {
        if (catalog == null) {           
 parser.parse(IAFullEngineWorkFlow.class.getClassLoader().getResource("/resource URI/"));
            catalog = CatalogFactoryBase.getInstance().getCatalog();
        }
       return catalog;
    }

Ideally we should get Catalog object out of it. But it throws above error.

1

1 Answers

0
votes

Found the solution. The parser in apache commons is not thread safe. Just needed to use synchronised in the getCatalog function.

`

public synchronised  static Catalog getCatalog() throws Exception {
        if (catalog == null) {           
 parser.parse(SampleClass.class.getClassLoader().getResource("/resource URI/"));
            catalog = CatalogFactoryBase.getInstance().getCatalog();
        }
       return catalog;
    }