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

Exception displayed when trying to loop over an Iterable private class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7
    • 1.7.x, 1.x, 2.0
    • Engine
    • None

    Description

      Specifically I got the following failure (see also https://java.net/jira/browse/TRUEVFS-158):

      ...
      Caused by: java.lang.IllegalAccessException: Class org.apache.velocity.util.introspection.UberspectImpl can not access a member of class net.java.truevfs.access.TFileSystem$Stream with modifiers "public"
      at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:109)
      at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:261)
      at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:253)
      at java.lang.reflect.Method.invoke(Method.java:599)
      at org.apache.velocity.util.introspection.UberspectImpl.getIterator(UberspectImpl.java:158)
      

      The problem as I understand it is that TrueVFS returns a private class and Velocity shouldn't try to call iterator() on it since it's private.

      Right now the UberspectImpl code does this:

                  Class type = obj.getClass();
                  try
                  {
                      Method iter = type.getMethod("iterator", null);
                      Class returns = iter.getReturnType();
                      if (Iterator.class.isAssignableFrom(returns))
                      {
                          try
                          {
                              return (Iterator)iter.invoke(obj, null);
      ...
      

      Instead, it could continue to do this but if the method is private then it could also fallback to something like the following:

      Class type = Iterable.class;
      if (obj instanceof Iterable) {
        Method iter = type.getMethod("iterator", null);
        return (Iterator) iter.invoke(obj, null);
      }
      

      Attachments

        Issue Links

          Activity

            People

              sdumitriu Sergiu Dumitriu
              vmassol Vincent Massol
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: