[
https://jira.jboss.org/jira/browse/JBSEAM-3851?page=com.atlassian.jira.pl...
]
Norman Richards closed JBSEAM-3851.
-----------------------------------
Fix Version/s: 2.1.2.CR1
Resolution: Done
Assignee: Norman Richards
It took a while to convince myself this was a necessary change. I was not as concerned
about setAccessible() access as I was that the proxies will fail on legitimate package
protected access. Since we do similar things elsewhere, so it should be ok to assume that
anyone who has successfully called into the proxy should be able to call the same method
on the proxied object.
Seam reflection has lower access than Java reflection
-----------------------------------------------------
Key: JBSEAM-3851
URL:
https://jira.jboss.org/jira/browse/JBSEAM-3851
Project: Seam
Issue Type: Bug
Affects Versions: 2.0.2.SP1
Environment: Jboss Embedded, Java 5
Reporter: Gabriel Goïc
Assignee: Norman Richards
Fix For: 2.1.2.CR1
This simple class is to be unit-tested, the SeamTest way:
@Name("hibean")
public class HiSayerBean {
public HiSayerBean () {
}
protected void sayHi(){
System.out.println("hello");
}
}
All tests occur in the SeamTest framework:
new ComponentTest() {
@Override
protected void testComponents() throws Exception {
//test code
}
}.run();
Using Java Reflection - works:
HiSayerBean impl = new HiSayerBean();
Method m = impl.getClass().getDeclaredMethod("sayHi");
m.setAccessible(true);
m.invoke(impl);
Using Java Reflection with Seam - fails:
HiSayerBean impl = (HiSayerBean) getInstance("hibean");
Method m = impl.getClass().getDeclaredMethod("sayHi");
m.setAccessible(true);
m.invoke(impl);
Error log:
java.lang.reflect.InvocationTargetException
(...)
Caused by: java.lang.IllegalAccessException: Class org.jboss.seam.util.Reflections can
not access a member of class HiSayerBean with modifiers "protected"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.reflect.Method.invoke(Method.java:578)
at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
at
org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at
org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at
org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
at
org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
at HiSayerBean_$$_javassist_0.sayHi(HiSayerBean_$$_javassist_0.java)
... 29 more
So, using Seam gives me a lower capacity to access methods in a reflected class than
with raw Java. I'm not sure if it's a bug or a feature request though. But it
would be nice to be granted to do this in unit-testing.
Please note that access to a private method in the same way than above works with Java
but produces a java.lang.NoSuchMethodException with Seam.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira