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

(prop) Properties.storeToXML creates invalid XML if form-feed character present

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4
    • None
    • 5.0
    • core-libs
    • Cause Known
    • x86
    • windows_2000

    Description

      Name: gm110360 Date: 09/14/2004


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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      The storeToXML method, if passed a key and/or value that contains a form-feed character outputs invalid XML. Even though the  entity reference is output, this is illegal in XML 1.0.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached program.

      ACTUAL -
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
      <properties>
      <entry key="key">This is a value with a form-feed &#12; character in it.</entry>
      </properties>


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.util.InvalidPropertiesFormatException: org.xml.sax.SAXParseException: Character reference "&#12" is an invalid XML character.
      at java.util.XMLUtils.load(XMLUtils.java:59)
      at java.util.Properties.loadFromXML(Properties.java:700)
      at XMLPropertiesFormFeedTest.main(XMLPropertiesFormFeedTest.java:14)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:494)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
      Caused by: org.xml.sax.SAXParseException: Character reference "&#12" is an invalid XML character.
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:215)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:386)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
      at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1413)
      at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanCharReferenceValue(XMLScanner.java:1294)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanCharReference(XMLDocumentFragmentScannerImpl.java:1118)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1605)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:345)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:827)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:757)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:252)
      at java.util.XMLUtils.getLoadingDoc(XMLUtils.java:85)
      at java.util.XMLUtils.load(XMLUtils.java:57)
      ... 7 more
      Exception in thread "main"
      Process finished with exit code 1

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class XMLPropertiesFormFeedTest {

          public static void main(String[] args) throws Exception {
              Properties properties = new Properties();
              properties.put("key", "This is a value with a form-feed \f character in it.");
              properties.storeToXML(new FileOutputStream("xmlproperties.txt"), null);
              properties = new Properties();
              properties.loadFromXML(new FileInputStream("xmlproperties.txt"));
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There is no workaround short of sanitizing the keys and values inserted into the properties object.
      (Incident Review ID: 310698)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              sherman Xueming Shen
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: