RFR: 8315974: Make fields final in 'com.sun.crypto.provider' package

Valerie Peng valeriep at openjdk.org
Mon Oct 9 22:40:02 UTC 2023


On Thu, 24 Aug 2023 08:53:53 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

> A few classes in `com.sun.crypto.provider` package have non-final fields which could easily be marked `final`.

src/java.base/share/classes/com/sun/crypto/provider/DHPrivateKey.java line 276:

> 274:     }
> 275: 
> 276:     private void parseKeyBits() throws InvalidKeyException {

This method is only called once inside the constructor, considering that this method is kind of trivial, maybe you can just move the impl to the constructor and remove this method.

src/java.base/share/classes/com/sun/crypto/provider/DHPublicKey.java line 57:

> 55: 
> 56:     // the key bytes, without the algorithm information
> 57:     private final byte[] key;

Same comment about re-assignment, please don't add the final keyword to this field.

src/java.base/share/classes/com/sun/crypto/provider/DHPublicKey.java line 268:

> 266:     }
> 267: 
> 268:     private void parseKeyBits() throws InvalidKeyException {

Same comment about moving this code block to constructor since it's only used once and the small size.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15412#discussion_r1350892266
PR Review Comment: https://git.openjdk.org/jdk/pull/15412#discussion_r1350902339
PR Review Comment: https://git.openjdk.org/jdk/pull/15412#discussion_r1350909325



More information about the security-dev mailing list