RFR: JDK-8245432: Lookup::defineHiddenClass should throw UnsupportedClassVersionError if the given bytes are of an unsupported major or minor version

David Holmes david.holmes at oracle.com
Sat May 30 13:30:14 UTC 2020


On 30/05/2020 6:03 am, Mandy Chung wrote:
> 
> 
> On 5/28/20 9:18 PM, David Holmes wrote:
>> On 29/05/2020 1:52 pm, Mandy Chung wrote:
>>> On 5/28/20 5:44 PM, David Holmes wrote:
>>>>>
>>>>> This is to validate the given version.  The runtime will check if 
>>>>> preview feature is enabled when such class file is loaded. I will 
>>>>> make a comment to make it clear.
>>>>
>>>> Okay but I thought the intent here was to pre-validate the version 
>>>> information so that when these bytes get passed to ASM you don't 
>>>> have to worry about the IAE that will be thrown by ASM if there is 
>>>> actually a problem.
>>>
>>> Yes it is.  ASM does not check if preview features are enabled or not 
>>> neither.  When a class file depending preview features is passed to 
>>> VM, the VM will throw an exception if preview features are not enabled.
>>
>> Yes but will that VM exception propagate as-is, or will ASM catch it 
>> and turn it into IAE? If the latter then your original problem still 
>> exists.
>>
> 
> I think you may be confused with the code path.  ASM is used only to 
> extract the class name from the bytes.  Once it verifies the class file 
> version and name in the bytes, the next step is to pass the name and 
> bytes to the VM to create the class where it checks if preview features 
> are used and enabled.  If VM will throw an exception, it just gets 
> propagated to the user (no ASM frame on the stack at that point).  See 
> the new PreviewHiddenClass test.

I see. That wasn't clear to me. I thought ASM was doing something that 
would trigger the VM checks.

Thanks,
David
-----

> Updated webrev:
> http://cr.openjdk.java.net/~mchung/jdk15/webrevs/8245432/webrev.02/index.html
> 
> This patch has a behavioral change to `Lookup::defineClass` if the bytes 
> is not a class or interface.
> 
> Lookup::defineClass does not specify what exception to throw if the 
> given bytes has ACC_MODULE flag set in the access_flags item. The 
> current implementation throws NoClassDefFoundError (which is the 
> behavior specified in JVMS 5.3.5).
> 
> I propose Lookup::defineClass to specify and throw 
> IllegalArgumentException if the bytes has ACC_MODULE flag set in its 
> access_flags item to be consistent with Lookup::defineHiddenClass.
> 
> CSR: https://bugs.openjdk.java.net/browse/JDK-8246108
> 
> Mandy
> 


More information about the core-libs-dev mailing list