Issue Details (XML | Word | Printable)

Key: AXIS-2518
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Rajkumar Kothapa
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Axis

Problem overriding ThreadLocal's initialValue method in ThreadLocalDocumentBuilder

Created: 06/Jul/06 09:27 PM   Updated: 06/Jul/06 09:27 PM
Return to search
Component/s: Basic Architecture
Affects Version/s: 1.4
Fix Version/s: None

Time Tracking:
Not Specified

Environment: Windows XP, jdk 1.4.1_7 build 1.4.2_07-b05, mixed mode


 Description  « Hide
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?


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
There are no entries against this issue.