Skip to content

Commit

Permalink
SpotBug P3 Fixes (#2973)
Browse files Browse the repository at this point in the history
* Adding suppression for having named static inner classes from anonymous.

* Add suppression for redundant null check.

* Move SIC_INNER_SHOULD_BE_STATIC suppression

* Make anonymous class in CachingKeyResolver a named inner static.

* Include missing impl classes for auto-rest when it generates a variable with known null value

* Suppressing unconfirmed casts because we know the cast is correct but the APIs weren't designed for it
  • Loading branch information
conniey authored Feb 27, 2019
1 parent c6f701d commit 98fa39a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<FindBugsFilter>
<!-- These existing KeyVault Attribute APIs return their super class rather than the actual type. -->
<Match>
<Class name="~com\.microsoft\.azure\.keyvault\.requests\.\w+Request"/>
<Bug pattern="BC_UNCONFIRMED_CAST_OF_RETURN_VALUE"/>
</Match>

<!-- These keyvault models are already publicly released APIs with name
matching the simple name of superclass -->
<Match>
Expand Down Expand Up @@ -33,6 +39,13 @@
<Bug pattern="UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD"/>
</Match>

<!-- Suppress non-null warning in the case that we change the code and it is possible for
KeyVaultCredentials.getAuthenticationCredentials to return null. -->
<Match>
<Class name="com.microsoft.azure.keyvault.authentication.KeyVaultCredentials"/>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"/>
</Match>

<!-- These KeyVaultClientBase methods are made synchronous by blocking and
waiting for a result. They do not return anything, so it can be ignored. -->
<Match>
Expand All @@ -41,6 +54,13 @@
<Bug pattern="RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT"/>
</Match>

<!-- These autorest generated APIs for existing Azure SDK components supports Java 7.
Suppressing error for using anonymous inner classes. -->
<Match>
<Class name="~com\.microsoft\.azure\.(.+)Impl"/>
<Bug pattern="SIC_INNER_SHOULD_BE_STATIC_ANON"/>
</Match>

<!-- KeyVaultCredential values manipulated do not need to be localised. They
are base64 encoded or URL encoded.-->
<Match>
Expand All @@ -58,7 +78,7 @@
<!-- Known issue in autorest where it will generate a variable with a value of null.
https://github.com/Azure/autorest.java/issues/324 -->
<Match>
<Class name="com.microsoft.azure.keyvault.KeyVaultClientImpl"/>
<Class name="~com\.microsoft\.azure\.(.+)Impl"/>
<Bug pattern="NP_LOAD_OF_KNOWN_NULL_VALUE"/>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ public class CachingKeyResolver implements IKeyResolver {
public CachingKeyResolver(int capacity, final IKeyResolver keyResolver) {
this.keyResolver = keyResolver;
cache = CacheBuilder.newBuilder().maximumSize(capacity)
.build(new CacheLoader<String, ListenableFuture<IKey>>() {

@Override
public ListenableFuture<IKey> load(String kid) {
return keyResolver.resolveKeyAsync(kid);
}
});
.build(new CachingKeyResolverCacheLoader(keyResolver));
}

@Override
Expand All @@ -58,4 +52,18 @@ public void run() {
return cache.getUnchecked(kid);
}
}

private static class CachingKeyResolverCacheLoader extends CacheLoader<String, ListenableFuture<IKey>> {

private final IKeyResolver keyResolver;

CachingKeyResolverCacheLoader(IKeyResolver keyResolver) {
this.keyResolver = keyResolver;
}

@Override
public ListenableFuture<IKey> load(String kid) {
return keyResolver.resolveKeyAsync(kid);
}
}
}

0 comments on commit 98fa39a

Please sign in to comment.