Commons JXPath
  1. Commons JXPath
  2. JXPATH-26

pointers obtained from iteratePointers() fails to setValue()

    Details

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

      Operating System: Linux
      Platform: PC

      Description

      I'm trying to iterate pointers, and set values. However any values I set using
      this method are ignored. This sounds similar to COM-72

      Note: It would be great if you like this test to add it to the suite.

      Thanks!

      To see the bug, add this function to NestedTestbean :

      public void setName(String name)

      { this.name = name; }

      Then, add this function to JXPathTestCase:

      public void testIteratePointerSetValue() {
      JXPathContext context = JXPathContext.newContext(bean);

      testGetValue(context, "/beans[1]/name", "Name 1");
      testGetValue(context, "/beans[2]/name", "Name 2");

      // Test setting via context
      context.setValue("/beans[2]/name", "Name 2 set");
      testGetValue(context, "/beans[2]/name", "Name 2 set");

      // Restore original value
      context.setValue("/beans[2]/name", "Name 2");
      testGetValue(context, "/beans[2]/name", "Name 2");

      int iter_count = 0;
      Iterator iter = context.iteratePointers("/beans/name");
      while (iter.hasNext())

      { iter_count++; Pointer pointer = (Pointer) iter.next(); String s = (String) pointer.getValue(); s = s + "suffix"; pointer.setValue(s); assertEquals("pointer.getValue", s, pointer.getValue()); // fails right here, the value isn't getting set in the bean. assertEquals("context.getValue", s, context.getValue(pointer.asPath())); }

      assertEquals("Iteration count", 2, iter_count);

      testGetValue(context, "/beans[1]/name", "Name 1suffix");
      testGetValue(context, "/beans[2]/name", "Name 2suffix");
      }

        Activity

        Hide
        Dmitri Plotnikov added a comment -

        Fixed. The crux of the problem was in PredicateContext, which had this logic:
        compute the predicate expression. If it is a number, jump to the n-th element
        of the parent context. Otherwise, convert the predicate value to boolean and
        if true, include the current node in the context. The thing is that the
        computation of the expression may return an EvalContext or a Pointer. What
        PredicateContext neglected to do, was first extract the value from the
        EvalContext or Pointer and only then check its type.

        Show
        Dmitri Plotnikov added a comment - Fixed. The crux of the problem was in PredicateContext, which had this logic: compute the predicate expression. If it is a number, jump to the n-th element of the parent context. Otherwise, convert the predicate value to boolean and if true, include the current node in the context. The thing is that the computation of the expression may return an EvalContext or a Pointer. What PredicateContext neglected to do, was first extract the value from the EvalContext or Pointer and only then check its type.

          People

          • Assignee:
            Unassigned
            Reporter:
            Scott Schram
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development