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.

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

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023