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

Transformer doesn't create an empty Document and throws IllegalArgumentException

    XMLWordPrintable

Details

    • b16
    • generic
    • generic
    • Verified

    Description



      Name: eaR10174 Date: 10/16/2001


        javax.xml.transform.Transformer throws IllegalArgumentException while processing
      DOMSource object created with zero-argument default constructor (See test.java, case #1
      below), but instead of throwing the exception the Transformer should create an empty
      Document source and transform it. The javadoc description (jdk1.4.0beta-b83) of the
      constructor DOMSource() reads:
        
          "public DOMSource()

           ...
           If this is used, and no DOM source is set, then the Transformer will create an empty
      source Document using DocumentBuilder.newDocument()."
           
        Note that the DOMSource with the manually set empty Document source is transformed
      without any exceptions (See test.java, case #2 below)

        This bug is found in the builds jdk1.4.0-beta3-b83, jaxp-1.1.3 and affects a new JCK1.4
      test

      api/javax_xml/transform/dom/DOMSource/index.html#Ctor[Ctor004]

      ------------------------------------test.java-----------------------------
      import javax.xml.transform.dom.DOMSource;
      import javax.xml.transform.TransformerFactory;
      import javax.xml.transform.Transformer;
      import javax.xml.transform.stream.StreamResult;
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.DocumentBuilder;

      public class test {

          public static void main (String[] args) {
              Transformer transformer = null;
              try {
                  transformer = TransformerFactory.newInstance().newTransformer();
              } catch (Exception e) {
                  System.out.println(e);
                  System.exit(1);
              }
               
              StreamResult result = new StreamResult(System.out);
              DOMSource source = new DOMSource();
              
              /* case #1 */
              System.out.println("case #1:");
              try {
                  transformer.transform(source, result);
              } catch (Exception e) {
                  System.out.println(e);
              }
              
              /* case #2 */
              System.out.println("\n\ncase #2:");
              try {
                  source.setNode(DocumentBuilderFactory.newInstance().
                          newDocumentBuilder().newDocument());

                  transformer.transform(source, result);
              } catch (Exception e) {
                  System.out.println(e);
              }
          }
      }
      ---------------------------------------------------------------------------
      ---------------------------------------------------------------------------
      % java -showversion test
      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b83)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b83, mixed mode)

      case #1:
      java.lang.IllegalArgumentException: The input node can not be null for a DOMSource for
      newTemplates!


      case #2:
      <?xml version="1.0" encoding="UTF-8"?>
      ---------------------------------------------------------------------------

      ======================================================================

      Attachments

        Activity

          People

            ayadavsunw Arun Yadav (Inactive)
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: