Uploaded image for project: 'Commons JXPath'
  1. Commons JXPath
  2. JXPATH-73

ValueUtils should catch IndexOutOfBoundsException instead of ArrayIndexOutOfBoundsException (for XmlBeans support)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.2 Final
    • 1.3
    • None
    • XmlBeans with JDK 1.4.2 and JXpath 1.2

    Description

      Basically, I want to do createPathAndSetValue on an XmlBean . But, my xpath statement inlcudes a collection (an array, actually), so the missing elements in the array need to be created.

      JXPath checks for this condition (ie. that array elements are missing and need to be created) by catching an ArrayIndexOutOfBoundsException.

      Unfortunately, XmlBeans does not throw that type of exception. It throws an IndexOutOfBoundsException exception instead. So, instead of detecting that the array is too small and needs to be grown (by calling my AbstractFactory), it just propogates the exception up the chain.

      The fix is quite simple: on line 423 of ValueUtils, just change the "catch" clause to catch a "IndexOutOfBoundsException" instead. This should not break any existing code since ArrayIndexOutOfBoundsException is actually a subclass of IndexOutOfBoundsException anyway.

      I made this fix to my local source tree, and everything works perfectly (ie. existing code did not break, but now I can also use JXPath on top of my XmlBeans beans too with my own custom AbstractFactory).

      Thanks!
      James

      Attachments

        1. jxpath-73.patch.txt
          0.6 kB
          Matthew Jason Benson

        Activity

          People

            Unassigned Unassigned
            jamesschopp James Schopp
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: