Commons JXPath
  1. Commons JXPath
  2. JXPATH-43

JXPathContext.createPath() does work for field of multiplicity > 1

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0 Final
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: PC

      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)

      { // same as before .... }

      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)

        Activity

        Hide
        Andrew Beveridge added a comment -

        oops-- context.createPath("foo[3]") is supposed to be context.createPath("names
        [3]"). sorry about the typo

        Show
        Andrew Beveridge added a comment - oops-- context.createPath("foo [3] ") is supposed to be context.createPath("names [3] "). sorry about the typo
        Hide
        Dmitri Plotnikov added a comment -

        Fixed the bug basically as suggested, except I applied the fix directly to
        getNodeValue() instead of createPath()

        Show
        Dmitri Plotnikov added a comment - Fixed the bug basically as suggested, except I applied the fix directly to getNodeValue() instead of createPath()

          People

          • Assignee:
            Unassigned
            Reporter:
            Andrew Beveridge
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development