JDK14 spec query : MethodHandles:dropLookupMode(int)
Mandy Chung
mandy.chung at oracle.com
Fri Feb 28 20:48:49 UTC 2020
Hi Andrew,
I see the confusion and we should improve the documentation. I have
created JDK-8240242 to improve the javadoc.
I also recommend to check out the Access modes section added in 14 that
gives detail examples on the lookup object resulting from Lookup::in and
dropLookupModes.
https://download.java.net/java/early_access/jdk15/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#access-modes
Mandy
On 2/28/20 6:02 AM, Andrew Leonard wrote:
> Thanks for your thoughts Chris,
> I see what you mean... about strictly..
> I'll see if anyone else has any thoughts, then raise a "doc bug" to have
> the wording improved...
> Cheers
> Andrew
>
> Andrew Leonard
> Java Runtimes Development
> IBM Hursley
> IBM United Kingdom Ltd
> internet email: andrew_m_leonard at uk.ibm.com
>
>
>
>
> From: Chris Hegarty <chris.hegarty at oracle.com>
> To: Andrew Leonard <andrew_m_leonard at uk.ibm.com>
> Cc: jdk-dev at openjdk.java.net
> Date: 28/02/2020 13:06
> Subject: [EXTERNAL] Re: JDK14 spec query :
> MethodHandles:dropLookupMode(int)
>
>
>
> Andrew,
>
>> 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) :
>>
>>
> https://urldefense.proofpoint.com/v2/url?u=http-3A__cr.openjdk.java.net_-7Eiris_se_14_build_latest_api_java.base_java_lang_invoke_MethodHandles.Lookup.html-23dropLookupMode-28int-29&d=DwIFAg&c=jf_iaSHvJObTbx-siA1ZOg&r=NaV8Iy8Ld-vjpXZFDdTbgGlRTghGHnwM75wUPd5_NUQ&m=mRSrsYGfY1YUyCB_rN4p5AyvOVo2DaP73X3_k65v66Q&s=gN4EcdDPjnY4FZVt1iIiftF7YFX0kfaRf4NBu25TztI&e=
>
>> the following two testcases seem inconsistent with the spec, but do pass
>> currently with the RI:
>>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__hg.openjdk.java.net_jdk_jdk14_file_e568ce785bdf_test_jdk_java_lang_invoke_DropLookupModeTest.java-23l69&d=DwIFAg&c=jf_iaSHvJObTbx-siA1ZOg&r=NaV8Iy8Ld-vjpXZFDdTbgGlRTghGHnwM75wUPd5_NUQ&m=mRSrsYGfY1YUyCB_rN4p5AyvOVo2DaP73X3_k65v66Q&s=bUInxyf6XhG1_6ixRJ85_ulskXmPGU40NkKCAsXSrqs&e=
>
>> 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.
> <----
>>
>>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__hg.openjdk.java.net_jdk_jdk14_file_e568ce785bdf_test_jdk_java_lang_invoke_DropLookupModeTest.java-23l131&d=DwIFAg&c=jf_iaSHvJObTbx-siA1ZOg&r=NaV8Iy8Ld-vjpXZFDdTbgGlRTghGHnwM75wUPd5_NUQ&m=mRSrsYGfY1YUyCB_rN4p5AyvOVo2DaP73X3_k65v66Q&s=j8FS0CtuTcPXXBNxSnG-_pdmL3DILhHWZ6jTbwJY0_A&e=
>
>> 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 ).
>
> -Chris.
>
>
>
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number
> 741598.
> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
>
More information about the jdk-dev
mailing list