javassist
javassist copied to clipboard
CtConstructor.getAvailableParameterAnnotations() returns wrong number of arguments for inner class with annotations
The following snippet shows that CtConstructor.getAvailableParameterAnnotations() returns a wrong number of arguments for inner class with annotations.
Output:
Class OkWithoutParamAnnotation: paramCount=2, annotatedParamCount=2 CtClass ShowBugParameterAnnotationsInnerClass$OkWithoutParamAnnotation: paramCount=2, annotatedParamCount=2 Class ErrorWithParamAnnotation: paramCount=2, annotatedParamCount=2 CtClass ShowBugParameterAnnotationsInnerClass$ErrorWithParamAnnotation: paramCount=2, annotatedParamCount=1
Note the bold highlighted value 1 which should also be 2. This has been tested with org.javassist:javassist:3.28.0-GA.
package eval.javassist;
import java.lang.reflect.Constructor;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.NotFoundException;
public class ShowBugParameterAnnotationsInnerClass {
class OkWithoutParamAnnotation {
OkWithoutParamAnnotation(String str) {
}
}
class ErrorWithParamAnnotation {
ErrorWithParamAnnotation(@Deprecated String str) {
}
}
static final ClassPool classPool = new ClassPool();
{
classPool.appendSystemPath();
}
public static void main(String[] args) throws NotFoundException {
new ShowBugParameterAnnotationsInnerClass().run();
}
void run() throws NotFoundException {
print(OkWithoutParamAnnotation.class);
print(ErrorWithParamAnnotation.class);
}
void print(Class<?> c) throws NotFoundException {
Constructor<?> m = c.getDeclaredConstructors()[0];
System.out.printf("Class %s: paramCount=%s, annotatedParamCount=%s\n", c.getSimpleName(), m.getParameterTypes().length,
m.getAnnotatedParameterTypes().length);
CtClass cc = classPool.get(c.getName());
CtConstructor cm = cc.getDeclaredConstructors()[0];
System.out.printf("CtClass %s: paramCount=%s, annotatedParamCount=%s\n", cc.getSimpleName(), cm.getParameterTypes().length,
cm.getAvailableParameterAnnotations().length);
}
}