Draft JVMS changes for Nestmates
Dan Smith
daniel.smith at oracle.com
Wed Apr 19 21:58:34 UTC 2017
> On Apr 19, 2017, at 1:21 PM, Dan Smith <daniel.smith at oracle.com> wrote:
>
>>
>> 5.4.4 Access Control
>>
>> I don't think you need to restate:
>>
>> "A class with a MemberOfNest attribute belongs to the nest hosted by the referenced host class.
>>
>> A class without a MemberOfNest attribute implicitly belongs to a nest hosted by the class itself. (If the class also lacks a NestMembers attribute, then the nest has only one member.)"
>>
>> The rule is simply stated as is: "belonging to the same nest as D" - belonging to the same nest is, or should be, already defined elsewhere.
>
> My intent is that this *is* the definition. But sounds like you're expecting that definition to be in 4.7.25/4.7.26, which is probably more intuitive. I'll change that.
Okay, here's another attempt at defining the attributes and the "nest" concept.
I've been uneasy about `NestMembers` being presented as the "declaration" of the nest, since it's not validated. Instead, I see `MemberOfNest` as really where nests are defined (as a cumulative result of many class declarations—like packages), and `NestMembers` as just a help for validation.
With that in mind, `MemberOfNest` ought to come first:
~~~~
**4.7.25 The `MemberOfNest` Attribute**
---------------------------------------
**The `MemberOfNest` attribute is a fixed-length attribute in the `attributes` table of a `ClassFile` structure ([4.1]).**
**A _nest_ is a set of classes and interfaces that share access to their `private` members ([5.4.4]).**
**A class or interface with a `MemberOfNest` attribute belongs to the nest hosted by a designated _host class_. The host class authorizes membership in the nest with a corresponding entry in its `NestMembers` attribute ([4.7.26], [4.10]).**
**A class or interface without a `MemberOfNest` attribute belongs to the nest hosted by itself. (Often, this nest is a singleton consisting only of the class itself.)**
**There may be at most one `MemberOfNest` attribute in the `attributes` table of a `ClassFile` structure.**
**The `MemberOfNest` attribute has the following format:**
...
**4.7.26 The `NestMembers` Attribute**
--------------------------------------
**The `NestMembers` attribute is a variable-length attribute in the `attributes` table of a `ClassFile` structure ([4.1]). It authorizes an enumerated set classes and interfaces to claim membership in a nest hosted by the current class or interface.**
**There may be at most one `NestMembers` attribute in the `attributes` table of a `ClassFile` structure.**
**The `attributes` table of a `ClassFile` structure must not contain both a `MemberOfNest` attribute and a `NestMembers` attribute.**
> **This rule prevents a host class from claiming membership in a different nest. It is implicitly a member of the nest that it hosts.**
**The `NestMembers` attribute has the following format:**
...
5.4.4 Access Control
--------------------
A class or interface _C_ is _accessible_ to a class or interface _D_ if and only if either of the following is true:
...
- _R_ is `private` and is declared ~~in _D_~~ **by a class belonging to the same nest as _D_ ([4.7.25])**.
~~~~
And now to the bikeshedding game:
`MemberOfNest`, as the key thing, could just be called `Nest` (imagine a `Package` attribute—we wouldn't call it `MemberOfPackage`). Or, since it's a reference to a class, `NestHost ` / `NestTop` / `NestMother` / `NestWhatever`.
`NestMembers` isn't horrible, but we could highlight its validation role with something like `AuthorizedNestMembers`.
—Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/valhalla-spec-experts/attachments/20170419/e2165acf/attachment.html>
More information about the valhalla-spec-experts
mailing list