RFR: 8344943: Mark not subclassable classes final in java.base exported classes

Chen Liang liach at openjdk.org
Thu Jan 16 20:42:52 UTC 2025


On Tue, 26 Nov 2024 13:04:41 GMT, Eirik Bjørsnøs <eirbjo at openjdk.org> wrote:

> Please review this PR which adds the `final` modifier to non-subclassable classes in `java.base`.
> 
> The classes were identified using an automated analysis. See CSR for details.
> 
> Besides simply adding the `final` access modifier, the PR:
> 
> * Updates a note in `java.lang.constant.DynamicCallSiteDesc` to not reference subtypes. See CSR for discussion.
> * Removes the class `java.lang.Runtime` from the test `test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java`
> * Updates the copyright year of affected source files

Changes requested by liach (Reviewer).

Looks good for 25.

src/java.base/share/classes/java/lang/constant/DynamicCallSiteDesc.java line 44:

> 42:  * {@code invokedynamic} call site.
> 43:  *
> 44:  * <p>This class is immutable and its behavior does not rely on object identity

Suggestion:

 * <p>A {@code DynamicCallSiteDesc} is immutable and its behavior does not
 * rely on object identity.

This describes an object, not a class, and please close sentences with a period.
(We use fragments for param and return block tags instead)

src/java.base/share/classes/java/lang/constant/DynamicCallSiteDesc.java line 45:

> 43:  *
> 44:  * <p>Concrete subtypes of {@linkplain DynamicCallSiteDesc} should be immutable
> 45:  * and their behavior should not rely on object identity.

Please reword this to something like:

{@code DynamicCallSiteDesc} is immutable and its behavior does not rely on object identity.

This is given in `ConstantDesc`, but `DynamicCallSiteDesc` does not extend `ConstantDesc` so the removal is dubious.

src/java.base/share/classes/java/net/InterfaceAddress.java line 45:

> 43: 
> 44:     /*
> 45:      * Package private constructor. Can't be built directly, instances are

The comment is outdated.  This constructor is actually called via JNI like `(*env)->NewObject(env, ni_ibcls, ni_ibctrID)` in `NetworkInterface.c`.  I think we need to consult a network engineer to decide what is the best way to comment on this constructor.

-------------

PR Review: https://git.openjdk.org/jdk/pull/22389#pullrequestreview-2462343034
Marked as reviewed by liach (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/22389#pullrequestreview-2500067616
PR Review Comment: https://git.openjdk.org/jdk/pull/22389#discussion_r1859112730
PR Review Comment: https://git.openjdk.org/jdk/pull/22389#discussion_r1859019019
PR Review Comment: https://git.openjdk.org/jdk/pull/22389#discussion_r1859157909


More information about the net-dev mailing list