mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8289274: Cleanup unnecessary null comparison before instanceof check in security modules
Reviewed-by: mullan
This commit is contained in:
parent
81ee7d28f8
commit
87aa3ce03e
14 changed files with 54 additions and 94 deletions
|
@ -300,7 +300,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
|
|||
Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
|
||||
Key key = null;
|
||||
|
||||
if (entry == null || (!(entry instanceof KeyEntry))) {
|
||||
if (!(entry instanceof KeyEntry)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -471,18 +471,18 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
|
|||
*/
|
||||
public Certificate[] engineGetCertificateChain(String alias) {
|
||||
Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
|
||||
if (entry != null && entry instanceof PrivateKeyEntry) {
|
||||
if (((PrivateKeyEntry) entry).chain == null) {
|
||||
if (entry instanceof PrivateKeyEntry privateKeyEntry) {
|
||||
if (privateKeyEntry.chain == null) {
|
||||
return null;
|
||||
} else {
|
||||
|
||||
if (debug != null) {
|
||||
debug.println("Retrieved a " +
|
||||
((PrivateKeyEntry) entry).chain.length +
|
||||
privateKeyEntry.chain.length +
|
||||
"-certificate chain at alias '" + alias + "'");
|
||||
}
|
||||
|
||||
return ((PrivateKeyEntry) entry).chain.clone();
|
||||
return privateKeyEntry.chain.clone();
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
|
@ -1012,7 +1012,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
|
|||
}
|
||||
|
||||
Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
|
||||
if (entry != null && entry instanceof KeyEntry) {
|
||||
if (entry instanceof KeyEntry) {
|
||||
throw new KeyStoreException("Cannot overwrite own certificate");
|
||||
}
|
||||
|
||||
|
@ -1095,11 +1095,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
|
|||
*/
|
||||
public boolean engineIsKeyEntry(String alias) {
|
||||
Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
|
||||
if (entry != null && entry instanceof KeyEntry) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return entry instanceof KeyEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1111,8 +1107,8 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
|
|||
*/
|
||||
public boolean engineIsCertificateEntry(String alias) {
|
||||
Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
|
||||
if (entry != null && entry instanceof CertEntry &&
|
||||
((CertEntry) entry).trustedKeyUsage != null) {
|
||||
if (entry instanceof CertEntry certEntry &&
|
||||
certEntry.trustedKeyUsage != null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -1144,10 +1140,10 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
|
|||
|
||||
Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
|
||||
if (entryClass == KeyStore.PrivateKeyEntry.class) {
|
||||
return (entry != null && entry instanceof PrivateKeyEntry);
|
||||
return (entry instanceof PrivateKeyEntry);
|
||||
}
|
||||
if (entryClass == KeyStore.SecretKeyEntry.class) {
|
||||
return (entry != null && entry instanceof SecretKeyEntry);
|
||||
return (entry instanceof SecretKeyEntry);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1827,11 +1823,10 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
|
|||
|
||||
String alias = e.nextElement();
|
||||
Entry entry = entries.get(alias);
|
||||
if (entry == null || (!(entry instanceof KeyEntry))) {
|
||||
if (!(entry instanceof KeyEntry keyEntry)) {
|
||||
continue;
|
||||
}
|
||||
DerOutputStream safeBag = new DerOutputStream();
|
||||
KeyEntry keyEntry = (KeyEntry) entry;
|
||||
|
||||
// DER encode the private key
|
||||
if (keyEntry instanceof PrivateKeyEntry) {
|
||||
|
|
|
@ -146,7 +146,7 @@ public abstract sealed class JavaKeyStore extends KeyStoreSpi {
|
|||
{
|
||||
Object entry = entries.get(convertAlias(alias));
|
||||
|
||||
if (entry == null || !(entry instanceof KeyEntry)) {
|
||||
if (!(entry instanceof KeyEntry keyEntry)) {
|
||||
return null;
|
||||
}
|
||||
if (password == null) {
|
||||
|
@ -155,7 +155,7 @@ public abstract sealed class JavaKeyStore extends KeyStoreSpi {
|
|||
|
||||
byte[] passwordBytes = convertToBytes(password);
|
||||
KeyProtector keyProtector = new KeyProtector(passwordBytes);
|
||||
byte[] encrBytes = ((KeyEntry)entry).protectedPrivKey;
|
||||
byte[] encrBytes = keyEntry.protectedPrivKey;
|
||||
EncryptedPrivateKeyInfo encrInfo;
|
||||
try {
|
||||
encrInfo = new EncryptedPrivateKeyInfo(encrBytes);
|
||||
|
@ -183,11 +183,11 @@ public abstract sealed class JavaKeyStore extends KeyStoreSpi {
|
|||
public Certificate[] engineGetCertificateChain(String alias) {
|
||||
Object entry = entries.get(convertAlias(alias));
|
||||
|
||||
if (entry != null && entry instanceof KeyEntry) {
|
||||
if (((KeyEntry)entry).chain == null) {
|
||||
if (entry instanceof KeyEntry keyEntry) {
|
||||
if (keyEntry.chain == null) {
|
||||
return null;
|
||||
} else {
|
||||
return ((KeyEntry)entry).chain.clone();
|
||||
return keyEntry.chain.clone();
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
|
@ -384,7 +384,7 @@ public abstract sealed class JavaKeyStore extends KeyStoreSpi {
|
|||
synchronized(entries) {
|
||||
|
||||
Object entry = entries.get(convertAlias(alias));
|
||||
if ((entry != null) && (entry instanceof KeyEntry)) {
|
||||
if (entry instanceof KeyEntry) {
|
||||
throw new KeyStoreException
|
||||
("Cannot overwrite own certificate");
|
||||
}
|
||||
|
@ -449,11 +449,7 @@ public abstract sealed class JavaKeyStore extends KeyStoreSpi {
|
|||
*/
|
||||
public boolean engineIsKeyEntry(String alias) {
|
||||
Object entry = entries.get(convertAlias(alias));
|
||||
if ((entry != null) && (entry instanceof KeyEntry)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return entry instanceof KeyEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -465,11 +461,7 @@ public abstract sealed class JavaKeyStore extends KeyStoreSpi {
|
|||
*/
|
||||
public boolean engineIsCertificateEntry(String alias) {
|
||||
Object entry = entries.get(convertAlias(alias));
|
||||
if ((entry != null) && (entry instanceof TrustedCertEntry)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return entry instanceof TrustedCertEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1819,7 +1819,7 @@ public class PolicyFile extends java.security.Policy {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (cert == null || !(cert instanceof X509Certificate)) {
|
||||
if (!(cert instanceof X509Certificate x509Cert)) {
|
||||
if (debug != null) {
|
||||
debug.println(" -- No certificate for '" +
|
||||
alias +
|
||||
|
@ -1827,8 +1827,6 @@ public class PolicyFile extends java.security.Policy {
|
|||
}
|
||||
return null;
|
||||
} else {
|
||||
X509Certificate x509Cert = (X509Certificate)cert;
|
||||
|
||||
// 4702543: X500 names with an EmailAddress
|
||||
// were encoded incorrectly. create new
|
||||
// X500Principal name with correct encoding
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -164,17 +164,14 @@ class SubjectCodeSource extends CodeSource implements java.io.Serializable {
|
|||
|
||||
LinkedList<PrincipalEntry> subjectList = null;
|
||||
|
||||
if (codesource == null ||
|
||||
!(codesource instanceof SubjectCodeSource) ||
|
||||
!(super.implies(codesource))) {
|
||||
if (!(codesource instanceof SubjectCodeSource that) ||
|
||||
!super.implies(codesource)) {
|
||||
|
||||
if (debug != null)
|
||||
debug.println("\tSubjectCodeSource.implies: FAILURE 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
SubjectCodeSource that = (SubjectCodeSource)codesource;
|
||||
|
||||
// if the principal list in the policy "implies"
|
||||
// the Subject associated with the current AccessControlContext,
|
||||
// then return true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -202,11 +202,10 @@ public class CertId {
|
|||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (other == null || (!(other instanceof CertId))) {
|
||||
if (!(other instanceof CertId that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CertId that = (CertId) other;
|
||||
if (hashAlgId.equals(that.getHashAlgorithm()) &&
|
||||
Arrays.equals(issuerNameHash, that.getIssuerNameHash()) &&
|
||||
Arrays.equals(issuerKeyHash, that.getIssuerKeyHash()) &&
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -488,10 +488,10 @@ class RevocationChecker extends PKIXRevocationChecker {
|
|||
}
|
||||
break;
|
||||
case "SSLServer":
|
||||
result = (t != null && t instanceof IOException);
|
||||
result = (t instanceof IOException);
|
||||
break;
|
||||
case "URI":
|
||||
result = (t != null && t instanceof IOException);
|
||||
result = (t instanceof IOException);
|
||||
break;
|
||||
default:
|
||||
// we don't know about any other remote CertStore types
|
||||
|
|
|
@ -170,9 +170,7 @@ public class BitArray {
|
|||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) return true;
|
||||
if (obj == null || !(obj instanceof BitArray)) return false;
|
||||
|
||||
BitArray ba = (BitArray) obj;
|
||||
if (!(obj instanceof BitArray ba)) return false;
|
||||
|
||||
if (ba.length != length) return false;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -87,10 +87,9 @@ public final class AccessDescription {
|
|||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || (!(obj instanceof AccessDescription))) {
|
||||
if (!(obj instanceof AccessDescription that)) {
|
||||
return false;
|
||||
}
|
||||
AccessDescription that = (AccessDescription)obj;
|
||||
|
||||
if (this == that) {
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue