On Sunday 23 January 2005 15:58, Shinobu Kawai Yoshida wrote:
> > I made a test for my problem and it works very well in java but not in
> > velocity. I can't even imagine how it could not work in velocity. I'll
> > check out the sources...
>
> You might want to file a new bugzilla issue while you're at it.  ;)

I first want to make sure it's not supposed to have weird behavior (which 
wouldn't be the first time.. *ahem*#set(...)*ahem*). Also, the jakarta 
bugzilla isn't among the fiftyeleven ones I have an account on. ;-)

Anyway, it seems to make some weird assumptions about accessibility. Check 
out this program and tell me if it's supposed to do this:
----8<------------------------------------------------------------------
import org.apache.velocity.util.introspection.*;
import java.lang.reflect.*;

public class Test1 {
    public static void main( String[] args ) throws Exception {
        Test2 t=new Test2();
        Object[] objs={
            t.pubStaticInner(),
            t.pubInner(),
            t.privStaticInner(),
            t.privInner(),
            t.anonymous(),
            t.privInnerPrivMethod()
        };
        for (int i=0; i<objs.length; i++) {
            Class c=objs[i].getClass();
            ClassMap map=new ClassMap(c);
            Method vm=map.findMethod("test", new Object[0]);
            Method jm=findMethod(c);
            System.out.println(c.getName()+":");
            System.out.println("- velocity finds method:   "+
                               (vm==null?"NO":"YES"));
            System.out.println("- java finds mehod:        "+
                               (jm==null?"NO":"YES"));
            System.out.println("- java can execute method: "+
                               canExec(objs[i], jm) );
        }
    }
    static Method findMethod(Class c) {
        try {
            return c.getMethod("test", new Class[0]);
        }catch (Exception ex) {
            return null;
        }
    }
    static String canExec(Object o, Method m) {
        if (m==null) return "n/a";
        try {
            m.invoke(o, new Object[0]);
            return "YES";
        }catch (Exception ex) {
            return "NO";
        }
    }
}
---->8------------------------------------------------------------------

and the helper-class:
----8<------------------------------------------------------------------
public class Test2 {
    public Object pubStaticInner() {
        return new PubStaticInner();
    }
    public Object pubInner() {
        return new PubInner();
    }
    public Object privStaticInner() {
        return new PrivStaticInner();
    }
    public Object privInner() {
        return new PrivInner();
    }
    public Object anonymous() {
        return new Object() {
            public String test() {
                return "anonymous";
            }
        };
    }
    public Object privInnerPrivMethod() {
        return new PrivInnerPrivMethod();
    }
    public static class PubStaticInner {
        public String test() {
            return "pub-static-inner";
        }
    }
    public class PubInner {
        public String test() {
            return "pub-inner";
        }
    }
    private static class PrivStaticInner {
        public String test() {
            return "priv-static-inner";
        }
    }
    private class PrivInner {
        public String test() {
            return "priv-inner";
        }
    }
    private class PrivInnerPrivMethod {
        private String test() {
            return "priv-inner-priv-method";
        }
    }
}
---->8------------------------------------------------------------------

I get the following output:
----8<------------------------------------------------------------------
Test2$PubStaticInner:
- velocity finds method:   YES
- java finds mehod:        YES
- java can execute method: YES
Test2$PubInner:
- velocity finds method:   YES
- java finds mehod:        YES
- java can execute method: YES
Test2$PrivStaticInner:
- velocity finds method:   NO
- java finds mehod:        YES
- java can execute method: YES
Test2$PrivInner:
- velocity finds method:   NO
- java finds mehod:        YES
- java can execute method: YES
Test2$1:
- velocity finds method:   NO
- java finds mehod:        YES
- java can execute method: YES
Test2$PrivInnerPrivMethod:
- velocity finds method:   NO
- java finds mehod:        NO
- java can execute method: n/a
---->8------------------------------------------------------------------

It's those cases where java can execute a method but velocity can't see it 
that I'm worried about. Apparently velocity ignores all methods in a 
private classes, even if the methods themselves are public.


- Marcus Sundman

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to