Problem overriding ThreadLocal's initialValue method in ThreadLocalDocumentBuilder -----------------------------------------------------------------------------------
Key: AXIS-2518 URL: http://issues.apache.org/jira/browse/AXIS-2518 Project: Apache Axis Type: Bug Components: Basic Architecture Versions: 1.4 Environment: Windows XP, jdk 1.4.1_7 build 1.4.2_07-b05, mixed mode Reporter: Rajkumar Kothapa I am using Axis 1.4 and jvm version "build 1.4.2_07-b05, mixed mode" and i am getting the following exception under heavy loads. java.lang.NullPointerException at java.lang.ThreadLocal$ThreadLocalMap$Entry.access$502(ThreadLocal.java:229) at java.lang.ThreadLocal$ThreadLocalMap.replaceStaleEntry(ThreadLocal.java:509) at java.lang.ThreadLocal$ThreadLocalMap.getAfterMiss(ThreadLocal.java:362) at java.lang.ThreadLocal$ThreadLocalMap.get(ThreadLocal.java:341) at java.lang.ThreadLocal$ThreadLocalMap.access$000(ThreadLocal.java:219) at java.lang.ThreadLocal.get(ThreadLocal.java:121) at org.apache.axis.utils.XMLUtils.getDocumentBuilder(XMLUtils.java:237) at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:337) at org.apache.axis.message.SOAPDocumentImpl.<init>(SOAPDocumentImpl.java:70) at org.apache.axis.SOAPPart.<init>(SOAPPart.java:1020) at org.apache.axis.Message.setup(Message.java:377) at org.apache.axis.Message.<init>(Message.java:235) at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:628) at javax.servlet.http.HttpServlet.service(HttpServlet.java:709) at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327) We are facing this issue because: XMLUtils.getDocumentBuilder calls ThreadLocal.get ThreadLocal.get calls ThreadLocalDocumentBuilder.initialValue ThreadLocalDocumentBuilder.initialValue calls DocumentBuilderFactory.newInstance() While creating an instance of DocumentBuilderFactory the classLoader is creating a ThreadLocal. This re-entrant call to the ThreadLocalMap results in the NPE. This is a known issue according to Sun which has been fixed in Java SE 6. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5025230. We had a discussion regarding this on the JSR 166 concurrency list (http://altair.cs.oswego.edu/mailman/private/concurrency-interest/2006-June/002789.html) and the only work-around for this to work on JDK 1.4 and JDK 5 is NOT to override ThreadLocal.initialValue. The current code is: private static class ThreadLocalDocumentBuilder extends ThreadLocal { protected Object initialValue() { try { return getDOMFactory().newDocumentBuilder(); } catch (ParserConfigurationException e) { log.error(Messages.getMessage("parserConfigurationException00"), e); } return null; } } Recommended code: private static class ThreadLocalDocumentBuilder extends ThreadLocal { public Object get() { Object result = super.get(); if(result == null){ try { result = getDOMFactory().newDocumentBuilder(); set(result); } catch (ParserConfigurationException e) { log.error(Messages.getMessage("parserConfigurationException00"), e); } } return result; } } Would it be possible to checkin this change? -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]