JDK14 spec query : MethodHandles:dropLookupMode(int)

Chris Hegarty chris.hegarty at oracle.com
Fri Feb 28 13:06:50 UTC 2020


> On 28 Feb 2020, at 12:55, Andrew Leonard <andrew_m_leonard at uk.ibm.com> wrote:
> Hi,
> I'm hoping to get some clarification please on understanding the updated 
> JDK14 spec for MethodHandles:dropLookupMode(int) :
> http://cr.openjdk.java.net/~iris/se/14/build/latest/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#dropLookupMode(int)
> the following two testcases seem inconsistent with the spec, but do pass 
> currently with the RI:
> https://hg.openjdk.java.net/jdk/jdk14/file/e568ce785bdf/test/jdk/java/lang/invoke/DropLookupModeTest.java#l69
> lookup = fullPowerLookup.dropLookupMode(UNCONDITIONAL);
>        assertTrue(lookup.lookupClass() == lc);
>        assertTrue(lookup.lookupModes() == 
> jdk14 spec has changed to say:
> If UNCONDITIONAL is dropped then the resulting lookup has no access. <----
> https://hg.openjdk.java.net/jdk/jdk14/file/e568ce785bdf/test/jdk/java/lang/invoke/DropLookupModeTest.java#l131
>        assertPublicLookup(unconditionalLookup.dropLookupMode(PUBLIC), 
> expected); <-------
> jdk14 spec states:
> If PUBLIC is dropped then the resulting lookup has no access
> Which is correct the code/testcase or the jdk14 spec ?

I had the same observation recently when reading the updated Java 14
version of this spec. The wording is not strictly incorrect, but could
benefit from a little clarification.

The reason I say that it is not _strictly_ incorrect is that it says
"is dropped". For a lookup mode to actually be dropped then it must
first be held by the lookup. In your examples the lookup does not hold
the access mode that is passed to be dropped, so the mode is not
actually dropped, hence a _no access_ lookup is not returned.

I think that the implementation is behaving as desired, but I do think
that the spec wording could be improved a little ( since I had similar
initial confusion about this point, just as you had ).


More information about the jdk-dev mailing list