Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-858

Class org.apache.velocity.util.introspection.UberspectImpl can not access a member of class com.google.common.collect.Iterables$8 with modifiers "public"

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7
    • Fix Version/s: 2.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      Java 8, guava

      Description

      Probably related issue:
      https://issues.apache.org/jira/browse/VELOCITY-579

      I am passing result of guava's Iterables.transform() to velocity.
      Attempt to iterate over it throws access exception, as UberspectImpl tries to access method iterator on object's class

      Class type = obj.getClass();
      ...
      Method iter = type.getMethod("iterator", null);

      Problem is, that while iterator() method is public, class com.google.common.collect.Iterables$8 is private, so velocity can't access it's method through reflection.

      I suggest call Iterable::iterator() for classes implementing Iterable, instead of trying to access method through reflection, as you already do for Collection implementations.

      Basically, replace (in UberspectImpl::getIterator(Object, Info))

      else if (obj instanceof Collection)

      { return ((Collection) obj).iterator(); }

      with

      else if (obj instanceof Iterable)

      { return ((Iterable) obj).iterator(); }

        Attachments

          Activity

            People

            • Assignee:
              cbrisson Claude Brisson
              Reporter:
              andll Andrey Chursin
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: