Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-1416

NPE creating (invalid) duration

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.9.1
    • 2.10.0
    • None
    • any

    Description

      creating a duration from "PT1D1H30M" (that is invalid since the 'T' should be after the 'D') causes a NullPointer in (DurationImpl.java:588),
      invalid values passed to DatatypeFactory.newDuration(String) should cause an IllegalArgumentException

      Test case:

      javax.xml.datatype.DatatypeFactory.newInstance().newDuration("PT1D1H30M");

      or, to be sure, of getting the right factory

      new org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl().newDuration("PT1D1H30M");

      the cause is in line 586:

      int nidx = tokens.lastIndexOf(parts[i].charAt(parts[i].length() - 1), idx - 1);

      parts[i] is null in this case, so I propose the change:

      final String part = parts[i];
      if (part == null) throw new IllegalArgumentException(whole);
      int nidx = tokens.lastIndexOf(part.charAt(part.length() - 1), idx - 1);

      I tried to check out the reason of the bug, it looks like the '1D' part is put in the day parts while parsing, but then I gave up,
      I think this fix is safer because cannot influence other test cases.

      the bug affects also the internal Xerces of java5 and 6

      Attachments

        1. Test.java
          0.7 kB
          Michele Vivoda

        Activity

          People

            mrglavas@ca.ibm.com Michael Glavassevich
            vivodamichele@hotmail.com Michele Vivoda
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified