Velocity
  1. Velocity
  2. VELOCITY-70

public members inherted from non-public classes are not valid references

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.5
    • Fix Version/s: 1.6
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      Operating System: All
      Platform: PC

      Description

      Hi there,
      I encountered a problem with Velocity when invoking inherited methods of a Java
      class. I get the
      error "org.apache.velocity.runtime.exception.ReferenceException: reference :
      template = screens/Details.vm [line 48,column 1] : $class.getFullName() is not
      a valid reference" if I want to invoke the "FullName" method of the "class"
      object. This method is inherited from a superior class. If I call a method
      defined directly in this class, everything works fine. If I obtain the name of
      the "class" object, I get the correct name.
      It would be nice, if anyone could help me on this.

        Activity

        Hide
        Geir Magnusson Jr added a comment -

        I am marking this as invalid, as there is no clear bug here yet -

        According to this bug report, you are using version 1.0 (which I doubt so
        if you could try the latest CVS HEAD, as it contains the latest code and
        fixes for introspection, that would be great.

        If there is no problem there, try backing down to the 1.3-rc1 release.

        If there still is a problem, just reopen this bug report.

        And don't hesitate to bring this directly to the user list if you want

        Show
        Geir Magnusson Jr added a comment - I am marking this as invalid, as there is no clear bug here yet - According to this bug report, you are using version 1.0 (which I doubt so if you could try the latest CVS HEAD, as it contains the latest code and fixes for introspection, that would be great. If there is no problem there, try backing down to the 1.3-rc1 release. If there still is a problem, just reopen this bug report. And don't hesitate to bring this directly to the user list if you want
        Hide
        jeff292 added a comment -

        Hi,
        I now used the latest version of Velocity. I used the Nightly build from the
        1st of May 2002 as well as the velocity-1.3-rc1 version and I'm always
        encountering the same error as I decribed in this message.
        As mentioned, this happens every time, I want to call a method, which is not
        locally defined, but inherited from a superclass.
        It seems as if there is a problem of mapping the methods from the Velocity
        macros to the referenced Java classes. If I'm using this methods in Java (e.g.
        in a Servlet, evrything works fine with the methods, I want to call)

        Show
        jeff292 added a comment - Hi, I now used the latest version of Velocity. I used the Nightly build from the 1st of May 2002 as well as the velocity-1.3-rc1 version and I'm always encountering the same error as I decribed in this message. As mentioned, this happens every time, I want to call a method, which is not locally defined, but inherited from a superclass. It seems as if there is a problem of mapping the methods from the Velocity macros to the referenced Java classes. If I'm using this methods in Java (e.g. in a Servlet, evrything works fine with the methods, I want to call)
        Hide
        Daniel Rall added a comment -

        Hiya Jeff. Please attach sample code to reproduce the bug.

        Show
        Daniel Rall added a comment - Hiya Jeff. Please attach sample code to reproduce the bug.
        Hide
        jeff292 added a comment -

        Hi,
        here is some sample code of the classes, I use:
        This is the class, I want to use:

        public class OW_Class extends OWB_Class implements OWI_Class {
        /**

        • OW_Class - Konstruktorkommentar.
          */
          public OW_Class() { super(); }

          .
          .
          .
          }

        which is inherited by this Class:

        abstract class OWB_Class extends OWB_AttributedObject {
        private static java.util.Hashtable LookUpTable = new java.util.Hashtable();

        public OWB_Class()

        { super(); }
        .
        .
        .
        }

        Which is inerited by:
        abstract class OWB_AttributedObject extends OWB_Object {
        public OWB_AttributedObject() { super(); }

        public String getFullName()

        { Instance po = (Instance)getApplicationObject(); if (po == null) return; return po.getName(); }

        .
        .
        .
        }

        If I now want to invoke the "getFullName" method with an "OW_Class" Object, I
        get the error I described. If I inspect the class with Java Reflection inside
        the Velocity Macro, I get all the method names, including this sample method's
        name above.

        Show
        jeff292 added a comment - Hi, here is some sample code of the classes, I use: This is the class, I want to use: public class OW_Class extends OWB_Class implements OWI_Class { /** OW_Class - Konstruktorkommentar. */ public OW_Class() { super(); } . . . } which is inherited by this Class: abstract class OWB_Class extends OWB_AttributedObject { private static java.util.Hashtable LookUpTable = new java.util.Hashtable(); public OWB_Class() { super(); } . . . } Which is inerited by: abstract class OWB_AttributedObject extends OWB_Object { public OWB_AttributedObject() { super(); } public String getFullName() { Instance po = (Instance)getApplicationObject(); if (po == null) return; return po.getName(); } . . . } If I now want to invoke the "getFullName" method with an "OW_Class" Object, I get the error I described. If I inspect the class with Java Reflection inside the Velocity Macro, I get all the method names, including this sample method's name above.
        Hide
        Mark Drew added a comment -

        Created an attachment (id=6233)
        simple example of problem

        Show
        Mark Drew added a comment - Created an attachment (id=6233) simple example of problem
        Hide
        Mark Drew added a comment -

        I just added attachment 6233, which I believe demonstrates this problem clearly.
        (I ran this example with Velocity 1.3.1)

        After writing this example, the problem--which seems to be the same as the one
        described in this bug--appears to be that Velocity fails to recognize a public
        inherited method if the class from which it is inherited is package private (or
        default) visibility.

        Here's my example base and child class definitions (for convenience--use the
        attachment if you want to run it):

        package test;
        class BaseClass {
        private int id;
        public BaseClass(int id)

        { this.id = id; }

        public int getId()

        { return id; }

        }

        ////////////////////////////////////////////

        package test;
        public class ChildClass extends BaseClass {
        private int someAttribute;
        public ChildClass(int id)

        { super(id); }

        public int getSomeAttribute()

        { return someAttribute; }

        public void setSomeAttribute(int attribute)

        { someAttribute = attribute; }

        }

        ////////////////////////////////////////////

        Notice that BaseClass has default visibility, ChildClass is public, and the
        inherited class, getId(), is also public. In Java, the inherited method getId
        is visible from any package when it is called on a ChildClass object. This does
        not appear to be the case in Velocity.

        Show
        Mark Drew added a comment - I just added attachment 6233, which I believe demonstrates this problem clearly. (I ran this example with Velocity 1.3.1) After writing this example, the problem--which seems to be the same as the one described in this bug--appears to be that Velocity fails to recognize a public inherited method if the class from which it is inherited is package private (or default) visibility. Here's my example base and child class definitions (for convenience--use the attachment if you want to run it): package test; class BaseClass { private int id; public BaseClass(int id) { this.id = id; } public int getId() { return id; } } //////////////////////////////////////////// package test; public class ChildClass extends BaseClass { private int someAttribute; public ChildClass(int id) { super(id); } public int getSomeAttribute() { return someAttribute; } public void setSomeAttribute(int attribute) { someAttribute = attribute; } } //////////////////////////////////////////// Notice that BaseClass has default visibility, ChildClass is public, and the inherited class, getId(), is also public. In Java, the inherited method getId is visible from any package when it is called on a ChildClass object. This does not appear to be the case in Velocity.
        Hide
        Shinobu Kawai added a comment -

        Even if it was made valid in Velocity, method invocation will throw an
        IllegalAccessException, due to a bug in JDK.
        http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4283544

        In order to bypass that, some ugly setAccessible(true) will be needed. Even
        that will not work in certain security-managed environments. For now, I
        suggest making a (superfluous) public method in the subclass calling the method
        in the superclass.

        #*
        I also have a feeling this issue will get invalid when the JDK bug gets fixed.
        *#

        Show
        Shinobu Kawai added a comment - Even if it was made valid in Velocity, method invocation will throw an IllegalAccessException, due to a bug in JDK. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4283544 In order to bypass that, some ugly setAccessible(true) will be needed. Even that will not work in certain security-managed environments. For now, I suggest making a (superfluous) public method in the subclass calling the method in the superclass. #* I also have a feeling this issue will get invalid when the JDK bug gets fixed. *#
        Hide
        Shinobu Kawai added a comment -

        Looks like Bug Parade also has a voting system. Please vote if you think this
        bug is significant.

        Show
        Shinobu Kawai added a comment - Looks like Bug Parade also has a voting system. Please vote if you think this bug is significant.
        Hide
        Will Glass-Husain added a comment -

        I'm against using setAccessible within Velocity. It's hard enough to
        configure the security policies for a webapp container as it is. Why add
        another requirement to the mess?

        Show
        Will Glass-Husain added a comment - I'm against using setAccessible within Velocity. It's hard enough to configure the security policies for a webapp container as it is. Why add another requirement to the mess?
        Hide
        Nathan Bubna added a comment -

        Works for me in 1.6-dev.

        Show
        Nathan Bubna added a comment - Works for me in 1.6-dev.
        Hide
        Nathan Bubna added a comment -

        @#%! So, in hopes of creating a beta1 test build, i switch to java 1.4.2 and tried running things. apart from the various 1.5-isms that snuck past me, i also discovered that the test case for this bugger fails in Java 1.4.x.

        Testcase: testPublicMethodInheritedFromPrivateClass took 0.031 sec
        FAILED
        expected:<bar> but was:<$bar.bar()>
        junit.framework.ComparisonFailure: expected:<bar> but was:<$bar.bar()>
        at org.apache.velocity.test.BaseEvalTestCase.assertEvalEquals(BaseEvalTestCase.java:85)
        at org.apache.velocity.test.issues.Velocity579TestCase.testPublicMethodInheritedFromPrivateClass(Velocity579TestCase.java:45)

        Since this appears to a JDK bug that is fixed in later versions, i am leaving this resolved. I'll just adapt the testcase to ignore this when running on a pre 1.5 jdk. I don't see us ever working around this since it works in newer JDKs.

        Show
        Nathan Bubna added a comment - @#%! So, in hopes of creating a beta1 test build, i switch to java 1.4.2 and tried running things. apart from the various 1.5-isms that snuck past me, i also discovered that the test case for this bugger fails in Java 1.4.x. Testcase: testPublicMethodInheritedFromPrivateClass took 0.031 sec FAILED expected:<bar> but was:<$bar.bar()> junit.framework.ComparisonFailure: expected:<bar> but was:<$bar.bar()> at org.apache.velocity.test.BaseEvalTestCase.assertEvalEquals(BaseEvalTestCase.java:85) at org.apache.velocity.test.issues.Velocity579TestCase.testPublicMethodInheritedFromPrivateClass(Velocity579TestCase.java:45) Since this appears to a JDK bug that is fixed in later versions, i am leaving this resolved. I'll just adapt the testcase to ignore this when running on a pre 1.5 jdk. I don't see us ever working around this since it works in newer JDKs.
        Hide
        Nathan Bubna added a comment -

        Correction. This bug still appears to be present in JDK 1.5. It is fixed in 1.6. Adapting the test case to match...

        Show
        Nathan Bubna added a comment - Correction. This bug still appears to be present in JDK 1.5. It is fixed in 1.6. Adapting the test case to match...

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development