Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Redundant NPE in DefaultHttpDestination#equals and #hashCode #368

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public final class DefaultHttpDestination implements HttpDestination
@Delegate
private final DestinationProperties baseProperties;

@Nullable
private final KeyStore keyStore;

@Nullable
private final KeyStore trustStore;

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Enumeration;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

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

Expand All @@ -29,7 +30,7 @@ class DestinationKeyStoreComparator
* The KeyStore to calculate the hash code for.
* @return The key-store hash code dynamically computed on behalf of stored certificates.
*/
static int resolveKeyStoreHashCode( @Nonnull final KeyStore ks )
static int resolveKeyStoreHashCode( @Nullable final KeyStore ks )
{
final HashCodeBuilder out = new HashCodeBuilder(INITIAL_HASH_CODE, 37);
final Certificate[] certificates = resolveCertificatesOnly(ks);
Expand All @@ -45,8 +46,12 @@ static int resolveKeyStoreHashCode( @Nonnull final KeyStore ks )
* @return An array with certificates, or empty in case of error or non-certificate based keystore entries.
*/
@Nonnull
static Certificate[] resolveCertificatesOnly( @Nonnull final KeyStore ks )
static Certificate[] resolveCertificatesOnly( @Nullable final KeyStore ks )
{
if( ks == null ) {
return new Certificate[0];
}

final ArrayList<Certificate> out = new ArrayList<>();
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) for which cases do we actually need the try here? Is there any legitimate failure case we need to handle?

Copy link
Contributor Author

@newtork newtork Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Everything" on KeyStore is prone to exceptions being thrown, especially since we never know what kind of implementation is running internally. That's why we need a try.

Example (independent from implementation)

  • KeyStoreException("Uninitialized keystore") if KeyStore was not load-ed.

final Enumeration<String> aliases = ks.aliases();
Expand Down
Loading