javassist icon indicating copy to clipboard operation
javassist copied to clipboard

Abstract methods breaks ClassFile.getMethods() and CtClass.getDeclaredBehaviors()

Open Ultimanecat opened this issue 3 years ago • 1 comments

I'm using javassist for bytecode instrumentation, and I want all methods (declared in some class file) instrumented. However, I found ClassFile.getMethods() and CtClass.getDeclaredBehaviors() failed to give me all methods when an abstract method is present. The code is as follows(from Apache Lang, with some abbreviation)

public abstract class CharSequenceTranslator {
    public abstract int translate(CharSequence input, int index, Writer out) throws IOException;
    public final String translate(CharSequence input) {...}
    public final void translate(CharSequence input, Writer out) throws IOException {...}
    ...(other method declarations)
}

These two methods only return me with the default constructor and the very first abstract method declaration. When I remove the abstract keyword from the method (with naive implementation added), those two methods work perfectly well (though the class is still an abstract class).

Is this my API misuse (If so, it would be very appreciated if someone tells me the correct usage) or a bug?

Ultimanecat avatar Apr 12 '21 11:04 Ultimanecat

Version is 3.27.0-GA.

Ultimanecat avatar Apr 12 '21 11:04 Ultimanecat