Hi Nate, Everyone:
Given target method setName( String s ), I was surprised this throw a NPE:
methodAccess.invoke( instance, index, null );
Looking at ReflectASM unit tests, I saw that this does work:
methodAccess.invoke( instance, index, (Object) null );
I sorta grasp the Java Lang Spec on this: target method is resolved at compile time, exact match takes precedent. But I still don't grasp why "(Object) null" and "null" are treated differently. (I could look at the byte codes...)
Regardless.
Here's a gist to show how Java handles varargs invocation with variations of null:
It occurs to me, performance crazy microtweakers that we are, that adding zero and single param invoke methods to MethodAccess would prevent the creation of temp object arrays.
abstract public Object invoke (Object object, int methodIndex, Object... args);
abstract public Object invoke (Object object, int methodIndex, Object args);
abstract public Object invoke (Object object, int methodIndex);
I scanned your ASM ClassWriter code generation magic. Ummm. Any chance you have the plain Java version captured some where?
I must confess that I just use the ASMify feature of the Bytecode Outline plugin to jumpstart my ASM efforts.
My backup plan is to capture the resulting class (byte array) and use JAD to show me what the generated code looks like.
Cheers, Jason