Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.9.1
-
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