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

NPE while loading an "empty" property thru Properties.loadFromXML

    Details

    • Subcomponent:
    • Resolved In Build:
      b56
    • CPU:
      x86
    • OS:
      windows_xp

      Description



      Name: gm110360 Date: 06/01/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The following Code causes a NPE while loading the properties from an XML file.

      Cause is the "empty" property which is not property checked in line 99 in java.util.XMLUtils#importProperties.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the above code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The result should probably be the same, if as the property instance had been saved to a plain properties file, i.e. an empty string returned for the property "empty".
      ACTUAL -
      the file does not even load

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.NullPointerException
      at java.util.XMLUtils.importProperties(XMLUtils.java:99)
      at java.util.XMLUtils.load(XMLUtils.java:69)
      at java.util.Properties.loadFromXML(Properties.java:700)
      at Test1.main(Test1.java:21)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.util.Properties;

      public class Test1 {
          public static void main(String[] args) {
              Properties props = new Properties();
              props.setProperty("empty", "");
              props.setProperty("foo", "bar");
              try {
                  FileOutputStream out = new FileOutputStream("Foo.dat");
                  props.storeToXML(out, null);
                  out.flush();
                  out.close();
              } catch (Exception e) {
                  e.printStackTrace();
              }
              Properties props2 = new Properties();
              try {
                  props2.loadFromXML(new FileInputStream("Foo.dat"));
                  props2.list(System.out);
              } catch (Exception e1) {
                  e1.printStackTrace();
              }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't store empty strings in a Property instance which gets saved to XML.
      (Incident Review ID: 275480)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              mmcclosksunw Michael Mccloskey (Inactive)
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: