xerces-j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michele Vivoda (JIRA)" <xerces-j-...@xml.apache.org>
Subject [jira] Created: (XERCESJ-1416) NPE creating (invalid) duration
Date Tue, 02 Feb 2010 18:48:18 GMT
NPE creating (invalid) duration

                 Key: XERCESJ-1416
                 URL: https://issues.apache.org/jira/browse/XERCESJ-1416
             Project: Xerces2-J
          Issue Type: Bug
          Components: JAXP (javax.xml.datatype)
         Environment: any
            Reporter: Michele Vivoda
            Priority: Minor

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:


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

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org

View raw message