Geir,
I assumed you got my last mail(see below) about the reflection problem that
arises with private class. What is your current position about this ?
I definitely agree that the workaround (this is a workaround) I sent is bad,
but what do you think about changing the method invocation by keeping the
class of the return type instead of the object class ?
Is that feasible without breaking too many things ?
--
Stephane Bailliez
Software Engineer, Paris - France
iMediation - http://www.imediation.com
Disclaimer: All the opinions expressed above are mine and not those from my
company.
> -----Original Message-----
> From: Stephane Bailliez [mailto:[EMAIL PROTECTED]]
> Sent: Friday, July 27, 2001 10:09 AM
> To: [EMAIL PROTECTED]
> Subject: RE: [PATCH] ASTMethod / IllegalAccessException
>
>
> > -----Original Message-----
> > From: Geir Magnusson Jr. [mailto:[EMAIL PROTECTED]]
> >
> > Eh. Before making the statement "Velocity shouldn't change
> > modifiers of
> > methods in the context", I am interested to see what classes you are
> > working with, and why the problem occurrs....
>
> The below sample should give you an idea, it is more precise
> than my last
> post. (and it compiles :) It should print:
>
> Call via return type class: SUCCESS
> Call via base class: FAILED
>
> The problem is that the current Velocity code will perform
> reflection on the
> base class of an object (o.getClass()). Thus my point to
> 'save' the return
> type of the object from a method call each time there is a
> reflection call,
> otherwise we are unable to know which object we are working
> on the next time
> we will use it and we will incorrectly use the base class to
> perform the
> call. Base class that might perfectly be of private access
> and expose its
> public interface to a caller (ie, for example Itr is a
> private class of
> AbstractList that implements Iterator and that is sent back via the
> iterator() call)
>
> I'm not familiar yet with the velocity code since I have only
> been using it
> for eval for less than 2 weeks so I cannot give you a patch
> to do this which
> is to me the ideal solution rather than the ugly hack I did.
>
> --- Test.java
>
> import java.util.*;
> import java.lang.reflect.*;
>
> public class Test {
>
> public static void main(String[] args) throws Exception {
> ArrayList list = new ArrayList();
> Object o = list.iterator();
>
> try {
> Class clazz =
> list.getClass().getMethod("iterator",
> new Class[0]).getReturnType();
> Method method = clazz.getMethod("hasNext", new
> Class[0]);
> method.invoke(o, null);
> System.out.println("Call via return type class:
> SUCCESS");
> } catch (Exception e){
> System.out.println("Call via return type class:
> FAILED");
> }
>
> try {
> Class clazz = o.getClass();
> Method method = clazz.getMethod("hasNext", new
> Class[0]);
> method.invoke(o, null);
> System.out.println("Call via base
> class: SUCCESS");
> } catch (Exception e){
> System.out.println("Call via base
> class: FAILED");
> }
> }
>
> }
>
>
>
> --
> Stephane Bailliez
> Software Engineer, Paris - France
> iMediation - http://www.imediation.com
> Disclaimer: All the opinions expressed above are mine and
> not those from my
> company.
>
>