JDK14 spec query : MethodHandles:dropLookupMode(int)
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:
> I'm hoping to get some clarification please on understanding the updated
> JDK14 spec for MethodHandles:dropLookupMode(int) :
> the following two testcases seem inconsistent with the spec, but do pass
> currently with the RI:
> lookup = fullPowerLookup.dropLookupMode(UNCONDITIONAL);
> assertTrue(lookup.lookupClass() == lc);
> assertTrue(lookup.lookupModes() ==
> (PUBLIC|MODULE|PACKAGE|PRIVATE)); <---
> jdk14 spec has changed to say:
> If UNCONDITIONAL is dropped then the resulting lookup has no access. <----
> 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