Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8313085

NPE in com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFImpl#getAttribute

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Problem for all systems.

      A DESCRIPTION OF THE PROBLEM :
      The opening lines of `DocumentBuilderFactoryImpl#getAttribute` are:
      ```
          public Object getAttribute(String name)
              throws IllegalArgumentException
          {

              //check if the property is managed by security manager
              String pName;
              if ((pName = fSecurityManager.find(name)) != null) {
                  return attributes.get(pName);
              } else if ((pName = fSecurityPropertyMgr.find(name)) != null) {
                  return attributes.get(pName);
              }

              // See if it's in the attributes Map
              if (attributes != null) {
                  Object val = attributes.get(name);
                  if (val != null) {
                      return val;
                  }
              }
      ```

      The security check appears to have been added in 2021. It attempts to check the `attributes` attribute *before checking to see if `attributes` is null`.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Bug discovered when using Eclipse & XText.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should not be a null pointer exception
      ACTUAL -
      NullPointerException occurs because `attributes` is null.

      CUSTOMER SUBMITTED WORKAROUND :
      The fix is to change the opening code to this:
      ```
          public Object getAttribute(String name)
              throws IllegalArgumentException
          {
              if (attributes != null) {

                //check if the property is managed by security manager
                String pName;
                if ((pName = fSecurityManager.find(name)) != null) {
                    return attributes.get(pName);
                } else if ((pName = fSecurityPropertyMgr.find(name)) != null) {
                    return attributes.get(pName);
              }

                // See if it's in the attributes Map
                  Object val = attributes.get(name);
                  if (val != null) {
                      return val;
                  }
              }
      ```

      FREQUENCY : occasionally


            tongwan Andrew Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: