Inspectopedia
 
2024.3

MethodHandle/VarHandle type mismatch

Warning
New
Last modified: 03 December 2024

Reports MethodHandle and VarHandle factory method calls that don't match any method or field.

Also reports arguments to MethodHandle.invoke() and similar methods, that don't match the MethodHandle signature and arguments to VarHandle.set() that don't match the VarHandle type.

Examples:

MethodHandle mh = MethodHandles.lookup().findVirtual( MyClass.class, "foo", MethodType.methodType(void.class, int.class)); // the argument should be an int value mh.invoke(myObj, "abc");

// the argument should be String .class VarHandle vh = MethodHandles.lookup().findVarHandle( MyClass.class, "text", int .class);

VarHandle vh = MethodHandles.lookup().findVarHandle( MyClass.class, "text", String.class); // the argument should be a String value vh.set(myObj, 42);

New in 2017.2