Semantics of an empty PermittedSubtypes attribute for the VM

Brian Goetz brian.goetz at oracle.com
Thu Apr 2 21:31:23 UTC 2020



>> At the language level, we won’t let you define a class with an empty set of
>> permitted types; you should define a final class instead.
>>
>> But, having the VM treat an empty PS attribute as if it were not there seems
>> wrong; I would think an empty PS attribute would be a class file error.
> For comparison, i believe the VM also allows attribute NestMembers or BootstrapMethods to be empty.
>

True.  But the semantics of these are not ambiguous, as they are with 
PS.   An empty "NestMembers" attribute, and no "NestMembers" attribute, 
have the same effect -- no nest members.  But an empty PermittedSubtypes 
attribute means (in the absence of ACC_FINAL) anything goes.  So we have 
two things to be "consistent" with:

  - No PS means no restriction.  And an empty PS should be like no PS, 
right?  So empty PS is "no restrictions."
  - PS == list of permited subtypes, so empty PS is "no permitted subtypes."

Given that these things are on a collision course, and there's no need 
to have an empty PS, better to make an empty PS illegal.


More information about the amber-spec-experts mailing list