[Design the new POJO MicroContainer] - Re: MDR doesn't work on annotated privates (Repost)
by adrian@jboss.org
"wolfc" wrote : anonymous wrote :
| | My concern would be whether AOP needs to also use annotations on the
| | method during the invocation and so know to use this Signature?
| Not right now, because the EJB3 container sets up a manual interceptor chain. In future this chain should also come from aop.xml, then it might become a problem.
|
| Note that both web container & client container have so far been left out of scope.
|
That's not what I meant. If the method is enhanced using an AOP aspect,
it may want access to the annotations, e.g.
| @PostConstruct
| @LogCalls(level=Leves.TRACE)
| private void postConstruct() {}
|
| @Aspect
| public CallLogging
| {
| public Object invoke(MethodInvocation invocation) throws Throwable
| {
| // This effectively does
| // advisor.getMetaData().getComponentMetaData(new MethodSignature(invocation.getMethod())).getAnnotation(LogCalls.class)
| LogCalls logCalls = invocation.getAnnotation(LogCalls.class);
|
| // Impl
| doLog(logCalls, invocation);
| }
| }
|
Which would kind of work as it currently stands (since it doesn't validate the method).
The "kind of" is because it is not intended to work, and wouldn't work
if you don't use the constructor with the Method in it.
If you don't pass the Method object, it has to search for the Method
and will instead find the one in Sub.class.
anonymous wrote : Is there a Jira for the new method signature?
No JIRA, since we haven't decided what the proper solution is yet.
As I see it there are currently two possible solutions:
1) Your's which is to introduce a new Signature, but this is going to be
non-transparent to users, at least it doesn't interfere with more normal usages.
2) Morph MethodSignature to understand the "optional" class as part of the key.
But this would complicate the equals()/hashCode() used to store
and retrieve component metadata, e.g. Instance level metadata
populated from the xml
It would no longer be a simple get/put() semantic which would make writing
MetaDataLoaders overly complicated and error prone.
Callers who don't use the Method constructor would still have to know/pass the
declaring class when constructing the signature to get the super method.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4170354#4170354
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4170354
17 years, 7 months
[Design the new POJO MicroContainer] - Re: MDR doesn't work on annotated privates
by adrian@jboss.org
"wolfc" wrote : anonymous wrote :
| | My concern would be whether AOP needs to also use annotations on the
| | method during the invocation and so know to use this Signature?
| Not right now, because the EJB3 container sets up a manual interceptor chain. In future this chain should also come from aop.xml, then it might become a problem.
|
| Note that both web container & client container have so far been left out of scope.
|
That's not what I meant. If the method is enhanced using an AOP aspect,
it may want access to the annotations, e.g.
| @PostConstruct
| @LogCalls(level=Leves.TRACE)
| private void postConstruct() {}
|
| @Aspect
| public CallLogging
| {
| public Object invoke(MethodInvocation invocation) throws Throwable
| {
| // This effectively does
| // advisor.getMetaData().getComponentMetaData(new MethodSignature(invocation.getMethod())).getAnnotation(LogCalls.class)
| LogCalls logCalls = invocation.getAnnotation(LogCalls.class);
|
| // Impl
| doLog(logCalls, invocation);
| }
| }
|
Which would kind of work as it currently stands (since it doesn't validate the method).
The "kind of" is because it is not intended to work, and wouldn't work
if you don't use the constructor with the Method in it.
If you don't pass the Method object, it has to search for the Method
and will instead find the one in Sub.class.
Is there a Jira for the new method signature?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4170354#4170354
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4170354
17 years, 7 months
[Design the new POJO MicroContainer] - Re: MDR doesn't work on annotated privates
by wolfc
"adrian(a)jboss.org" wrote : Ok, I understand now. It's not an override.
|
| This isn't even really java since without a setAccessible() it's illegal. :-)
|
|
| | Sub sub = new Sub();
| | Method method = Super.class.getDeclaredMethod("doSomething");
| | // method.setAccessible(true);
| | method.invoke(sub);
| |
| | Exception in thread "main" java.lang.IllegalAccessException: Class Sub can not access a member of class Super with modifiers "private"
| | at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
| | at java.lang.reflect.Method.invoke(Method.java:588)
| | at Sub.main(Sub.java:36)
| |
|
| I guess it's mitigated by the super class having to add the annotation
| that allows it?
Ehr... nope, not really. You're still thinking to cleanly. ;-)
"adrian(a)jboss.org" wrote : Since you don't need to setAccessible() to retrieve annotations from
| the private super method then I don't think we would be introducing a security
| hole by supporting it within the MDR (this prints null).
|
|
| | Method method = Super.class.getDeclaredMethod("doSomething");
| | //method.setAccessible(true);
| | System.out.println(method.getAnnotation(Inherited.class));
| |
|
| I'd say you're idea of a new Signature is probably the easiest way to resolve this.
|
| My concern would be whether AOP needs to also use annotations on the
| method during the invocation and so know to use this Signature?
Not right now, because the EJB3 container sets up a manual interceptor chain. In future this chain should also come from aop.xml, then it might become a problem.
Note that both web container & client container have so far been left out of scope.
Is there a Jira for the new method signature?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4170338#4170338
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4170338
17 years, 7 months
[Design the new POJO MicroContainer] - Re: MDR doesn't work on annotated privates (Repost)
by adrian@jboss.org
"wolfc" wrote : anonymous wrote :
| | So I don't see why you have to look at annotations on overridden methods.
| A private method is considered to be non-overriddable. So I need that declaring class somewhere.
Ok, I understand now. It's not an override.
This isn't even really java since without a setAccessible() it's illegal. :-)
| Sub sub = new Sub();
| Method method = Super.class.getDeclaredMethod("doSomething");
| // method.setAccessible(true);
| method.invoke(sub);
|
| Exception in thread "main" java.lang.IllegalAccessException: Class Sub can not access a member of class Super with modifiers "private"
| at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
| at java.lang.reflect.Method.invoke(Method.java:588)
| at Sub.main(Sub.java:36)
|
I guess it's mitigated by the super class having to add the annotation
that allows it?
Since you don't need to setAccessible() to retrieve annotations from
the private super method then I don't think we would be introducing a security
hole by supporting it within the MDR (this prints null).
| Method method = Super.class.getDeclaredMethod("doSomething");
| //method.setAccessible(true);
| System.out.println(method.getAnnotation(Inherited.class));
|
I'd say you're idea of a new Signature is probably the easiest way to resolve this.
My concern would be whether AOP needs to also use annotations on the
method during the invocation and so know to use this Signature?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4170330#4170330
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4170330
17 years, 7 months
[Design the new POJO MicroContainer] - Re: MDR doesn't work on annotated privates
by adrian@jboss.org
"wolfc" wrote :
| So I don't see why you have to look at annotations on overridden methods.
A private method is considered to be non-overriddable. So I need that declaring class somewhere.
Ok, I understand now. It's not an override.
This isn't even really java since without a setAccessible() it's illegal. :-)
| Sub sub = new Sub();
| Method method = Super.class.getDeclaredMethod("doSomething");
| // method.setAccessible(true);
| method.invoke(sub);
|
| Exception in thread "main" java.lang.IllegalAccessException: Class Sub can not access a member of class Super with modifiers "private"
| at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
| at java.lang.reflect.Method.invoke(Method.java:588)
| at Sub.main(Sub.java:36)
|
I guess it's mitigated by the super class having to add the annotation
that allows it?
Since you don't need to setAccessible() to retrieve annotations from
the private super method then I don't think we would be introducing a security
hole by supporting it within the MDR (this prints null).
| Method method = Super.class.getDeclaredMethod("doSomething");
| //method.setAccessible(true);
| System.out.println(method.getAnnotation(Inherited.class));
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4170330#4170330
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4170330
17 years, 7 months