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

Method QName.valueOf() accepts illegal names

XMLWordPrintable

    • b26
    • generic
    • generic
    • Verified

      Name: eaR10174 Date: 10/07/2003


        The method QName.valueOf() accepts the following illegal names (see test.java below):
        
            {test://jaxp13}ts:p001
            test://jaxp13:p001
            [test://jaxp13]p001
            {}p001
            
      According to the method javadoc:

         If the String is null or does not conform to QName.toString() formatting, an
         IllegalArgumentException is thrown.
         
         The String MUST be in the form returned by QName.toString().
         
         The commonly accepted way of representing a QName as a String was defined by James
         Clark. Although this is not a standard specification, it is in common use, e.g.
         Transformer.setParameter(String name, Object value). This implementation parses a
         String formatted as: "{" + Namespace URI + "}" + local part. If the Namespace URI
         .equals(XMLConstants.NULL_NS_URI), only the local part should be provided.

      the method should throw IllegalArgumentException.
        
        The bug appears in jdk1.5.0beta-b22 and affects new JCK1.5 tests:
        
           api/javax_xml/namespace/QName/index.html#QName[ValueOf003]
           api/javax_xml/namespace/QName/index.html#QName[ValueOf004]
           api/javax_xml/namespace/QName/index.html#QName[ValueOf005]
           api/javax_xml/namespace/QName/index.html#QName[ValueOf007]

      ------------------------------------test.java-----------------------------
      import javax.xml.namespace.QName;

      public class test {

          public static void main(String [] args) {
              run("{test://jaxp13}ts:p001");
              run("test://jaxp13:p001");
              run("[test://jaxp13]p001");
              run("{}p001");
          }
          
          private static void run(String qName) {
              System.out.print(qName + " - ");
              try {
                  QName.valueOf(qName);
                  
                  System.out.println("IllegalArgumentException not thrown");
              } catch (IllegalArgumentException e) {
                  System.out.println("IllegalArgumentException thrown");
              }
          }
      }
      --------------------------------------------------------------------------
      % java -showversion test
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b22)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b22, mixed mode)

      {test://jaxp13}ts:p001 - IllegalArgumentException not thrown
      test://jaxp13:p001 - IllegalArgumentException not thrown
      [test://jaxp13]p001 - IllegalArgumentException not thrown
      {}p001 - IllegalArgumentException not thrown
      --------------------------------------------------------------------------

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

            jsuttorsunw Jeff Suttor (Inactive)
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: