RFR: 8289274: Cleanup unnecessary null comparison before instanceof check in security modules

Attila Szegedi attila at openjdk.org
Sun Jul 3 20:22:29 UTC 2022


On Fri, 24 Jun 2022 18:27:05 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

> Update code checks both non-null and instance of a class in security classes.
> The checks and explicit casts could also be replaced with pattern matching for the instanceof operator.
> 
> See similar cleanup in java.base - [JDK-8258422](https://bugs.openjdk.java.net/browse/JDK-8258422)

Changes requested by attila (Reviewer).

src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java line 1143:

> 1141:         Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
> 1142:         if (entryClass == KeyStore.PrivateKeyEntry.class) {
> 1143:             return (entry instanceof PrivateKeyEntry);

Suggestion:

            return entry instanceof PrivateKeyEntry;

src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java line 1146:

> 1144:         }
> 1145:         if (entryClass == KeyStore.SecretKeyEntry.class) {
> 1146:             return (entry instanceof SecretKeyEntry);

Suggestion:

            return entry instanceof SecretKeyEntry;

src/java.base/share/classes/sun/security/provider/certpath/RevocationChecker.java line 491:

> 489:                 break;
> 490:             case "SSLServer":
> 491:                 result = (t instanceof IOException);

Suggestion:

                result = t instanceof IOException;

src/java.base/share/classes/sun/security/provider/certpath/RevocationChecker.java line 494:

> 492:                 break;
> 493:             case "URI":
> 494:                 result = (t instanceof IOException);

Suggestion:

                result = t instanceof IOException;

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

PR: https://git.openjdk.org/jdk/pull/9284


More information about the security-dev mailing list