Re: [jboss-user] [JBoss Microcontainer Development] - Issues using Javassist TypeInfoFactory in other projects
by Kabir Khan
Kabir Khan [http://community.jboss.org/people/kabir.khan%40jboss.com] replied to the discussion
"Issues using Javassist TypeInfoFactory in other projects"
To view the discussion, visit: http://community.jboss.org/message/534604#534604
--------------------------------------------------------------
I am also seeing this
java.lang.IllegalArgumentException: Cannot set accessible on method info: JavassistMethodInfo@5578920a{name=privMain}
at org.jboss.test.kernel.deployment.support.StaticInjector.injectToMethod(StaticInjector.java:76)
at org.jboss.test.kernel.deployment.support.StaticInjector.injectToNonPublicMethod(StaticInjector.java:59)
at org.jboss.test.kernel.deployment.test.BeanContainerStaticTestCase.testStaticInjection(BeanContainerStaticTestCase.java:53)
private void injectToMethod(Class<?> clazz, String method, Object value, Class<?> signature, boolean isPublic) throws Throwable
{
ClassInfo classInfo = configurator.getClassInfo(clazz);
MethodInfo mi = Config.findMethodInfo(classInfo, method, new String[]{signature.getName()}, true, isPublic);
if (isPublic == false)
{
// TODO - move this into Reflection?
if (mi instanceof ReflectMethodInfoImpl)
{
ReflectMethodInfoImpl rmi = (ReflectMethodInfoImpl)mi;
Method m = rmi.getMethod();
m.setAccessible(true);
}
else
throw new IllegalArgumentException("Cannot set accessible on method info: " + mi);
}
mi.invoke(null, new Object[]{value});
}
If we moved the setAccessible() stuff to jboss-reflect as indicated in the comment, we could manage the accessibility of members there?
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/534604#534604]
Start a new discussion in JBoss Microcontainer Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
14 years, 8 months
Re: [jboss-user] [JBoss Microcontainer Development] - Issues using Javassist TypeInfoFactory in other projects
by Kabir Khan
Kabir Khan [http://community.jboss.org/people/kabir.khan%40jboss.com] replied to the discussion
"Issues using Javassist TypeInfoFactory in other projects"
To view the discussion, visit: http://community.jboss.org/message/534602#534602
--------------------------------------------------------------
Another issue is that dynamically created classes are not found in the classpools.
Dynamic proxies are not found at all:
0 DEBUG [JDKLazyInstantiationTestCase] ==== setUp org.jboss.test.kernel.lazy.test.JDKLazyInstantiationTestCase ====
5 DEBUG [JDKLazyInstantiationTestCase] ==== Starting testLazy ====
20 DEBUG [KernelFactory] Starting JBoss Kernel construction...
53 WARN [PropertyConfiguration] Factory: org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory@4393722c
466 DEBUG [KernelFactory] Completed JBoss Kernel construction. Duration: 446 milliseconds
568 ERROR [AbstractKernelController] Error installing to Instantiated: name=beanProxy state=Described
java.lang.RuntimeException: Class not found: $Proxy0
at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.get(JavassistTypeInfoFactoryImpl.java:311)
at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.getTypeInfo(JavassistTypeInfoFactoryImpl.java:519)
at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory.getTypeInfo(JavassistTypeInfoFactory.java:51)
at org.jboss.classadapter.plugins.BasicClassAdapterFactory.getClassAdapter(BasicClassAdapterFactory.java:54)
Neither are the javassist ProxyFactory proxies, since they just define the class in the classloader with no way to find them from the pools:
0 DEBUG [JavassistLazyInstantiationTestCase] ==== setUp org.jboss.test.kernel.lazy.test.JavassistLazyInstantiationTestCase ====
3 DEBUG [JavassistLazyInstantiationTestCase] ==== Starting testLazy ====
18 DEBUG [KernelFactory] Starting JBoss Kernel construction...
47 WARN [PropertyConfiguration] Factory: org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory@4393722c
514 DEBUG [KernelFactory] Completed JBoss Kernel construction. Duration: 496 milliseconds
618 ERROR [AbstractKernelController] Error installing to Instantiated: name=beanProxy state=Described
java.lang.RuntimeException: Class not found: org.jboss.test.kernel.lazy.support.IRare_$$_javassist_0
at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.get(JavassistTypeInfoFactoryImpl.java:311)
at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.getTypeInfo(JavassistTypeInfoFactoryImpl.java:519)
at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory.getTypeInfo(JavassistTypeInfoFactory.java:51)
at org.jboss.classadapter.plugins.BasicClassAdapterFactory.getClassAdapter(BasicClassAdapterFactory.java:54)
In AOP what we did was to write the class bytes to the in memory vfs location from the aop classpools, so that when trying to look up the CtClass later there is a resource path for the class bytes:
URL outputURL = new URL(tempURL.toString() + "/" + classFileName);
//Write the classfile to the temporary url
synchronized (tmplock)
{
if (trace) logger.trace(this + " " + pool + ".toClass() myloader:" + myloader + " writing bytes to " + tempURL);
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
BufferedOutputStream out = new BufferedOutputStream(byteout);
out.write(cc.toBytecode());
out.flush();
out.close();
byte[] classBytes = byteout.toByteArray();
MemoryContextFactory factory = MemoryContextFactory.getInstance();
factory.putFile(outputURL, classBytes);
Going to check with Chiba, but I'll see if I can modify javassist to allow ProxyFactory and ProxyFactoryHelper to accept an interface like
interface ByteRecorder{
void writeBytes(String classname, byte[]) throws IOException
}
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/534602#534602]
Start a new discussion in JBoss Microcontainer Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
14 years, 8 months