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

XMLInputFactoryImpl.getProperty() returns null

    XMLWordPrintable

Details

    • b17
    • generic
    • generic
    • Verified

    Description

      ADDITIONAL SYSTEM INFORMATION :
      windows OS, JAVA 10.0.1

      A DESCRIPTION OF THE PROBLEM :
      XMLInputFactoryImpl method getProperty(String) can return null in some cases even though the property has been declared earlier.
      It will happen when the property is part of the secure properties. The method containsProperty() that is called in the 'if' term supports a few cases that have not supported within the if statement and then null will be returned.
      We can see below that containsProperty() method has an additional OR for fSecurityPropertyMgr but the getProperty() method itself does not support this case:


      public Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException {
          if(name == null){
              throw new IllegalArgumentException("Property not supported");
          }
          if(fPropertyManager.containsProperty(name))
              return fPropertyManager.getProperty(name);
          throw new IllegalArgumentException("Property not supported");
      }


      public boolean containsProperty(String property){
          return supportedProps.containsKey(property) ||
                  (fSecurityManager != null && fSecurityManager.getIndex(property) > -1) ||
                  (fSecurityPropertyMgr!=null && fSecurityPropertyMgr.getIndex(property) > -1) ;
      }


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      XMLInputFactory xif = XMLInputFactory.newInstance();
      xif.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
      xif.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD);

      we create an xmlInputFactory and set a secure property against external entity definition.
      when we call getProperty() it will return null

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      expected result : an empty string ("")

      ACTUAL -
      actual result: null

      ---------- BEGIN SOURCE ----------
      public class main {
          public static void main(String[] args) throws IOException {
              try {
                  XMLInputFactory xif = XMLInputFactory.newInstance();
                  xif.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
                  xif.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
                  xif.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD);
                  xif.getProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA);
              } catch (Exception e) {
                  System.out.println("An error occurred.");
                  e.printStackTrace();
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      public Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException {
          if(name == null){
              throw new IllegalArgumentException("Property not supported");
          }
          if(fPropertyManager.containsProperty(name))
              return fPropertyManager.getProperty(name);
          throw new IllegalArgumentException("Property not supported");
      }


      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              joehw Joe Wang
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: