-
1. Re: Javassist and Java5's enumerations
gpothier Apr 22, 2005 1:13 AM (in response to gpothier)Sorry, the actual exception is a javassist.NotFoundException. Java's NoClassDefFound doesn't surface its root cause.
Here is the stack trace:
javassist.NotFoundException: [Lreflex.lib.logging.core.api.collector.BehaviourType;
at javassist.ClassPool.get(ClassPool.java:301)
at javassist.expr.MethodCall.getCtClass(MethodCall.java:76)
at javassist.expr.MethodCall.getMethod(MethodCall.java:112)
at reflex.core.model.expr.RMethodCallImpl.getMethod(RMethodCallImpl.java:69)
...
BehaviourType being an enum. -
2. Re: Javassist and Java5's enumerations
gpothier Apr 24, 2005 2:55 PM (in response to gpothier)Ok, I found the problem. It is not specific to enumerations: Javassist doesn't properly handle array classes.
For example, this code poses problems:
String[] theStrings = {"A", "B"};
theStrings = theStrings.clone();
The problem is that in the class file, the method call is represented like that:
16: invokevirtual #5; //Method "[Ljava/lang/String;".clone:()Ljava/lang/Object;
So this is a call to method "clone" in class "[Ljava/lang/String;". And when trying to retrieve the target class, MethodCall.getCtClass passes this classname to ClassPool.get. But ClassPool.get doesn't understand this syntax: it expects something like java.lang.String[]
So I see two ways to fix it:
- Either change MethodCall.getClassName so that it transforms [Ljava.lang.String; to java.lang.String[]
- Change ClassPool.get() so that it accepts [Ljava.lang.String;
PS:
The reason why my original code worked with eclipse is that the eclipse compiler doesn't produce the same bytecode for enums in the values() method: Javac clones an array while eclipse instanciates a new array and does an arraycopy. -
3. Re: Javassist and Java5's enumerations
chiba May 9, 2005 1:13 PM (in response to gpothier)For another request, I'll change ClassPool.get() to
accept [L...;