Skip to content

Commit ce0d362

Browse files
authored
fix: Redundant NPE in DefaultHttpDestination#equals and #hashCode (#368)
1 parent e81722a commit ce0d362

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

cloudplatform/cloudplatform-connectivity/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DefaultHttpDestination.java

+3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public final class DefaultHttpDestination implements HttpDestination
5555
@Delegate
5656
private final DestinationProperties baseProperties;
5757

58+
@Nullable
5859
private final KeyStore keyStore;
60+
61+
@Nullable
5962
private final KeyStore trustStore;
6063

6164
@Nonnull

cloudplatform/cloudplatform-connectivity/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationKeyStoreComparator.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Enumeration;
1111

1212
import javax.annotation.Nonnull;
13+
import javax.annotation.Nullable;
1314

1415
import org.apache.commons.lang3.builder.HashCodeBuilder;
1516

@@ -29,7 +30,7 @@ class DestinationKeyStoreComparator
2930
* The KeyStore to calculate the hash code for.
3031
* @return The key-store hash code dynamically computed on behalf of stored certificates.
3132
*/
32-
static int resolveKeyStoreHashCode( @Nonnull final KeyStore ks )
33+
static int resolveKeyStoreHashCode( @Nullable final KeyStore ks )
3334
{
3435
final HashCodeBuilder out = new HashCodeBuilder(INITIAL_HASH_CODE, 37);
3536
final Certificate[] certificates = resolveCertificatesOnly(ks);
@@ -45,8 +46,12 @@ static int resolveKeyStoreHashCode( @Nonnull final KeyStore ks )
4546
* @return An array with certificates, or empty in case of error or non-certificate based keystore entries.
4647
*/
4748
@Nonnull
48-
static Certificate[] resolveCertificatesOnly( @Nonnull final KeyStore ks )
49+
static Certificate[] resolveCertificatesOnly( @Nullable final KeyStore ks )
4950
{
51+
if( ks == null ) {
52+
return new Certificate[0];
53+
}
54+
5055
final ArrayList<Certificate> out = new ArrayList<>();
5156
try {
5257
final Enumeration<String> aliases = ks.aliases();

release_notes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020

2121
### 🐛 Fixed Issues
2222

23-
-
23+
- Stop unnecessarily throwing and catching `NullPointerException` when interacting with `DefaultHttpDestination#equals(...)` and `#hashCode()`.

0 commit comments

Comments
 (0)