Inspectopedia Help

MethodHandle/VarHandle type mismatch

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.


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

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.16690

Last modified: 29 April 2024