RFR: 8177276: MethodHandles.insertArguments doesn't specify IllegalArgumentException on index mismatch

Paul Sandoz paul.sandoz at oracle.com
Mon May 21 16:49:12 UTC 2018



> On May 19, 2018, at 7:14 AM, Nadeesh TV <nadeesh.thatathil.valappu at mdcpartners.be> wrote:
> 
> Hi Vivek,
> 
> IMHO, assigning back to methodHandle on  line 109, 115, 122,123 is confusing
> 

MethodHandlesInsertArgumentsTest.java
—

Yes, not just confusing but incorrect, the updated static field will affect what is tested so you are dependent on the order of test method execution. Make the field final and use the convention for static field names, and drop the assignment for the insertArgument calls.


 118     @Test
 119     public void testInsertArgumentsPosZero() {
 120         countTest();
 121         try {
 122             methodHandle = MethodHandles.insertArguments(methodHandle, 0, "First");
 123             methodHandle = MethodHandles.insertArguments(methodHandle, 1, "First", new Object());
 124             Assert.fail("ClassCastException not thrown");
 125         }
 126         catch(ClassCastException cce) {
 127         }
 128     }

You can split this out into multiple try/catch, one for each MethodHandles.insertArguments call so the assertion directly captures the failure point, otherwise declare the exception in the @Test.


MethodHandles.java
—

3489      * @throws ClassCastException If an argument does not mach the corresponding bound parameter

Lower case the “If”

Paul.


More information about the core-libs-dev mailing list