Setter generation (incorrectly) assumes that Method return type is void
Closed this issue · 2 comments
stevenschlansker commented
There are a number of places in Afterburner where the code generation assumes void return types. This assumption is bad, for example in the case of Builder-type objects it is common to "return this" so that method invocations may be chained.
For eexample, the PropertyMutatorCollector does the following both in _addSettersUsingIf
and _addSettersUsingSwitch
:
Method method = (Method) (props.get(i).getMember().getMember());
Type type = Type.getType(method.getParameterTypes()[0]);
if (mustCast) {
mv.visitTypeInsn(CHECKCAST, type.getInternalName());
}
mv.visitMethodInsn(INVOKEVIRTUAL, beanClass, method.getName(), "("+type.getDescriptor()+")V");
mv.visitInsn(RETURN);
This blindly assumes that the method returns void
. This causes NoSuchMethodError
at runtime, which sucks.
stevenschlansker commented
It looks like issue #5 covered this partially, fixing one of three invocation sites. I see two more places that should have the same fix, at lines 382 and 409
cowtowncoder commented
Fixed.