Skip to content

Commit

Permalink
Addressing SpotBugs issues (#16894)
Browse files Browse the repository at this point in the history
* Addressing SpotBugs issues

Co-authored-by: Victor Colin Amador <[email protected]>
  • Loading branch information
mnriem and vcolin7 authored Oct 30, 2020
1 parent 15e7cf0 commit af6582e
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2458,23 +2458,35 @@
<Field name="detectionConfiguration" />
<Bug pattern="UWF_UNWRITTEN_FIELD" />
</Match>

<!-- Disabling false positives in azure-core -->
<!-- This Issue has been resolved as per spotbugs's recommended solution but the static checker still flags it, its a known issue with this rule. -->
<Match>
<Class name="com.azure.core.util.logging.ClientLogger" />
<Bug pattern="CRLF_INJECTION_LOGS" />
</Match>

<!-- The predictable randomness doesn't expose any crucial detail in this case. -->
<Match>
<Class name="com.azure.core.http.policy.ExponentialBackoff" />
<Bug pattern="PREDICTABLE_RANDOM" />
</Match>

<!-- In the default log level azure-core will not print the stack trace, but when the user opt-in for the lowest level log (DEBUG) we'll print it, which is expected. -->
<Match>
<Class name="com.azure.core.implementation.logging.DefaultLogger" />
<Bug pattern="INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE" />
</Match>

<!-- False positives -->
<Match>
<Class name="com.azure.security.keyvault.jca.KeyVaultKeyStore" />
<Method name="getFilenames" />
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
</Match>
<Match>
<Class name="com.azure.security.keyvault.jca.LegacyRestClient" />
<Method name="~(get|post)" />
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE" />
</Match>
</FindBugsFilter>
12 changes: 2 additions & 10 deletions sdk/keyvault/azure-security-keyvault-jca/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@
</rules>
</configuration>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.12.2</version> <!-- {x-version-update;com.github.spotbugs:spotbugs-maven-plugin;external_dependency} -->
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.revapi</groupId>
<artifactId>revapi-maven-plugin</artifactId>
Expand All @@ -148,12 +140,12 @@
<version>5.0.3</version> <!-- {x-version-update;org.apache.httpcomponents.client5:httpclient5;external_dependency} -->
<optional>true</optional>
</dependency>
<!-- Conscrypt -->
<dependency>
<groupId>org.conscrypt</groupId>
<artifactId>conscrypt-openjdk-uber</artifactId>
<scope>compile</scope>
<scope>provided</scope>
<version>2.2.1</version> <!-- {x-version-update;org.conscrypt:conscrypt-openjdk-uber;external_dependency} -->
<optional>true</optional>
</dependency>
<!-- Jackson Databind -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ public class KeyVaultKeyManager extends X509ExtendedKeyManager {
public KeyVaultKeyManager(KeyStore keystore, char[] password) {
LOGGER.entering("KeyVaultKeyManager", "<init>", new Object[] { keystore, password });
this.keystore = keystore;
this.password = password;
if (password != null) {
this.password = new char[password.length];
System.arraycopy(password, 0, this.password, 0, password.length);
} else {
this.password = null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
Expand All @@ -33,7 +34,7 @@
/**
* The Azure Key Vault implementation of the KeyStoreSpi.
*/
public class KeyVaultKeyStore extends KeyStoreSpi {
public final class KeyVaultKeyStore extends KeyStoreSpi {

/**
* Stores the logger.
Expand Down Expand Up @@ -155,7 +156,7 @@ public Certificate[] engineGetCertificateChain(String alias) {

@Override
public Date engineGetCreationDate(String alias) {
return creationDate;
return new Date(creationDate.getTime());
}

@Override
Expand Down Expand Up @@ -259,7 +260,7 @@ private String[] getFilenames(String path) throws IOException {
List<String> filenames = new ArrayList<>();
try (InputStream in = getClass().getResourceAsStream(path)) {
if (in != null) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
String resource;
while ((resource = br.readLine()) != null) {
filenames.add(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
* The CertificateBundle REST model.
*/
public class CertificateBundle implements Serializable {

/**
* Stores the serial version UID.
*/
private static final long serialVersionUID = 1L;

/**
* Stores the CER bytes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
* The CertificateItem REST model.
*/
public class CertificateItem implements Serializable {

/**
* Stores the serial version UID.
*/
private static final long serialVersionUID = 1L;

/**
* Stores the id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
* The CertificateItem REST model.
*/
public class CertificateListResult implements Serializable {

/**
* Stores the serial version UID.
*/
private static final long serialVersionUID = 1L;

/**
* Stores the value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
* The CertificatePolicy REST model.
*/
public class CertificatePolicy implements Serializable {

/**
* Stores the serial version UID.
*/
private static final long serialVersionUID = 1L;

/**
* Stores the key properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
* The KeyProperties REST model.
*/
public class KeyProperties implements Serializable {

/**
* Stores the serial version UID.
*/
private static final long serialVersionUID = 1L;

/**
* Stores if the key is exportable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
* An OAuth2 token.
*/
public class OAuthToken implements Serializable {

/**
* Stores the serial version UID.
*/
private static final long serialVersionUID = 1L;

/**
* Stores the access token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
* The SecretBundle REST model.
*/
public class SecretBundle implements Serializable {

/**
* Stores the serial version UID.
*/
private static final long serialVersionUID = 1L;

/**
* Stores the value.
Expand Down

0 comments on commit af6582e

Please sign in to comment.