Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
1.0 Final
-
None
-
None
-
Operating System: All
Platform: PC
-
11049
Description
When attempting to create a new indexed path (corresponding to a multiple
field), I get a JXPathException that is ultimately caused by an
IndexOutOfBounds exception.
For example, if Names is an array/Collection of size 3, then context.createPath
("foo[3]") will throw a JXPathException (before getting to my implementation of
AbstractFactory).
I chased the bug down in the latest codebase to the
org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.createPath
(JXPathContext context) method.
The first thing this method does is to attempt to check
(getNodeValue() != null)
but in the case that the path does not yet exist, and the exception is thrown.
My suggested fix: this method needs a bit more logic in the intial check, such
as:
Object nv = (index < getLength()) ? getNodeValue() : null;
if (nv == null)
Can you let me know whether you condone this change? (abeveridge@12.com).
Finally, here is the stack trace that I get:
org.apache.commons.jxpath.JXPathException: Exception trying to create xpath
names[3]; Cannot access property: names;
java.lang.reflect.InvocationTargetException
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.createPath
(JXPathContextReferenceImpl.java:309)
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.createPath
(JXPathContextReferenceImpl.java:287)
at com.oxygen.object.BusinessObject.setProperty(BusinessObject.j
ava:233)
at com.oxygen.object.BusinessObjectXpathTest.testMomAndDad(Busin
essObjectXpathTest.java:214)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:166)
at junit.framework.TestCase.runBare(TestCase.java:140)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:131)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run
(JUnitTestRunner.java:231)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main
(JUnitTestRunner.java:409)
=====NESTED EXCEPTION=====
org.apache.commons.jxpath.JXPathException: Cannot access property: names;
java.lang.reflect.InvocationTargetException
at org.apache.commons.jxpath.util.ValueUtils.getValue(ValueUtils
.java:346)
at org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getNodeValue
(BeanPropertyPointer.java:190)
at org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.createPath
(BeanPropertyPointer.java:223)
at org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer.createChild
(PropertyOwnerPointer.java:169)
at org.apache.commons.jxpath.ri.model.beans.NullElementPointer.createChild
(NullElementPointer.java:164)
at org.apache.commons.jxpath.ri.model.beans.NullPointer.createPath
(NullPointer.java:142)
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.createPath
(JXPathContextReferenceImpl.java:306)
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.createPath
(JXPathContextReferenceImpl.java:287)
at com.oxygen.object.BusinessObject.setProperty(BusinessObject.java:233)
at com.oxygen.object.BusinessObjectXpathTest.testMomAndDad
(BusinessObjectXpathTest.java:214)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:166)
at junit.framework.TestCase.runBare(TestCase.java:140)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:131)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run
(JUnitTestRunner.java:231)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main
(JUnitTestRunner.java:409)
====NESTED EXCEPTION=====
java.lang.reflect.InvocationTargetException:
java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.RangeCheck(ArrayList.java:486)
at java.util.ArrayList.get(ArrayList.java:302)
at com.oxygen.object.Dad.getNames(Dad.java:210)
at java.lang.reflect.Method.invoke(Native Method)
at org.apache.commons.jxpath.util.ValueUtils.getValue(ValueUtils.java:342)
at org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getNodeValue
(BeanPropertyPointer.java:190)
at org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.createPath
(BeanPropertyPointer.java:223)
at org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer.createChild
(PropertyOwnerPointer.java:169)
at org.apache.commons.jxpath.ri.model.beans.NullElementPointer.createChild
(NullElementPointer.java:164)
at org.apache.commons.jxpath.ri.model.beans.NullPointer.createPath
(NullPointer.java:142)
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.createPath
(JXPathContextReferenceImpl.java:306)
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.createPath
(JXPathContextReferenceImpl.java:287)
at com.oxygen.object.BusinessObject.setProperty(BusinessObject.java:233)
at com.oxygen.object.BusinessObjectXpathTest.testMomAndDad
(BusinessObjectXpathTest.java:214)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:166)
at junit.framework.TestCase.runBare(TestCase.java:140)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:131)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run
(JUnitTestRunner.java:231)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main
(JUnitTestRunner.java:409)