Uploaded image for project: 'Axis'
  1. Axis
  2. AXIS-2518

Problem overriding ThreadLocal's initialValue method in ThreadLocalDocumentBuilder

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.4
    • None
    • Basic Architecture
    • None
    • Windows XP, jdk 1.4.1_7 build 1.4.2_07-b05, mixed mode

    Description

      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?

      Attachments

        Activity

          People

            Unassigned Unassigned
            r0jkumar Rajkumar Kothapa
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: