From da386ad0e25a56572dfa2b203c29f2b0490141cc Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 27 Apr 2016 20:23:32 -0700 Subject: [PATCH] Correct FindBugs warnings --- .../jclouds/s3/filters/Aws4SignerBase.java | 20 +++++++------------ .../validators/BucketNameValidator.java | 2 +- ...nitScriptStatusIsZeroThenReturnOutput.java | 2 +- ...gitalOcean2RateLimitExceededException.java | 2 +- .../jclouds/digitalocean2/ssh/ECDSAKeys.java | 9 ++++----- .../ProfitBricksComputeServiceAdapter.java | 2 +- .../ProfitBricksHttpErrorHandler.java | 2 -- 7 files changed, 15 insertions(+), 24 deletions(-) diff --git a/apis/s3/src/main/java/org/jclouds/s3/filters/Aws4SignerBase.java b/apis/s3/src/main/java/org/jclouds/s3/filters/Aws4SignerBase.java index 3ef5bf4abc..4d724af3ba 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/filters/Aws4SignerBase.java +++ b/apis/s3/src/main/java/org/jclouds/s3/filters/Aws4SignerBase.java @@ -69,25 +69,15 @@ import org.jclouds.providers.ProviderMetadata; */ public abstract class Aws4SignerBase { private static final TimeZone GMT = TimeZone.getTimeZone("GMT"); - protected static final DateFormat timestampFormat; - protected static final DateFormat dateFormat; + protected final DateFormat timestampFormat; + protected final DateFormat dateFormat; // Do not URL-encode any of the unreserved characters that RFC 3986 defines: // A-Z, a-z, 0-9, hyphen (-), underscore (_), period (.), and tilde (~). - private static final Escaper AWS_URL_PARAMETER_ESCAPER; + private static final Escaper AWS_URL_PARAMETER_ESCAPER = new PercentEscaper("-_.~", false); private static final Escaper AWS_PATH_ESCAPER = new PercentEscaper("/-_.~", false); - static { - timestampFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'"); - timestampFormat.setTimeZone(GMT); - - dateFormat = new SimpleDateFormat("yyyyMMdd"); - dateFormat.setTimeZone(GMT); - - AWS_URL_PARAMETER_ESCAPER = new PercentEscaper("-_.~", false); - } - // Specifying a default for how to parse the service and region in this way allows // tests or other downstream services to not have to use guice overrides. @ImplementedBy(ServiceAndRegion.AWSServiceAndRegion.class) @@ -137,6 +127,10 @@ public abstract class Aws4SignerBase { this.timestampProvider = timestampProvider; this.serviceAndRegion = serviceAndRegion; this.crypto = crypto; + this.timestampFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'"); + timestampFormat.setTimeZone(GMT); + this.dateFormat = new SimpleDateFormat("yyyyMMdd"); + dateFormat.setTimeZone(GMT); } protected String getContentType(HttpRequest request) { diff --git a/apis/s3/src/main/java/org/jclouds/s3/predicates/validators/BucketNameValidator.java b/apis/s3/src/main/java/org/jclouds/s3/predicates/validators/BucketNameValidator.java index 8efd1ccf0c..046e9ba41d 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/predicates/validators/BucketNameValidator.java +++ b/apis/s3/src/main/java/org/jclouds/s3/predicates/validators/BucketNameValidator.java @@ -45,7 +45,7 @@ public class BucketNameValidator extends Validator { @Override public void validate(String name) { if (name == null) { - throw exception(name, "Can't be null"); + throw exception("", "Can't be null"); } else if (name.length() < 3) { throw exception(name, "Can't be less than 3 characters"); } else if (name.length() > 255) { diff --git a/compute/src/main/java/org/jclouds/compute/callables/BlockUntilInitScriptStatusIsZeroThenReturnOutput.java b/compute/src/main/java/org/jclouds/compute/callables/BlockUntilInitScriptStatusIsZeroThenReturnOutput.java index 4d46015e55..2a15f4bbe4 100644 --- a/compute/src/main/java/org/jclouds/compute/callables/BlockUntilInitScriptStatusIsZeroThenReturnOutput.java +++ b/compute/src/main/java/org/jclouds/compute/callables/BlockUntilInitScriptStatusIsZeroThenReturnOutput.java @@ -136,7 +136,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutput extends AbstractFu String stdout = commandRunner.runAction("stdout").getOutput(); String stderr = commandRunner.runAction("stderr").getOutput(); Integer exitStatus = Ints.tryParse(commandRunner.runAction("exitstatus").getOutput().trim()); - exec = new ExecResponse(stdout, stderr, exitStatus == null ? -1 : exitStatus); + exec = new ExecResponse(stdout, stderr, exitStatus == null ? Integer.valueOf(-1) : exitStatus); } while (!isCancelled() && exec.getExitStatus() == -1); logger.debug("<< complete(%s) status(%s)", commandRunner.getStatement().getInstanceName(), exec .getExitStatus()); diff --git a/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/exceptions/DigitalOcean2RateLimitExceededException.java b/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/exceptions/DigitalOcean2RateLimitExceededException.java index fc54a7c186..8218a26ae7 100644 --- a/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/exceptions/DigitalOcean2RateLimitExceededException.java +++ b/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/exceptions/DigitalOcean2RateLimitExceededException.java @@ -67,7 +67,7 @@ public class DigitalOcean2RateLimitExceededException extends RateLimitExceededEx totalRequestsPerHour = limit == null ? null : Integer.valueOf(limit); remainingRequests = remaining == null ? null : Integer.valueOf(remaining); - timeToNextAvailableRequest = reset == null ? null : millisUntilNextAvailableRequest(Long.valueOf(reset)); + timeToNextAvailableRequest = reset == null ? null : millisUntilNextAvailableRequest(Long.parseLong(reset)); } private static Multimap rateLimitHeaders(HttpResponse response) { diff --git a/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/ssh/ECDSAKeys.java b/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/ssh/ECDSAKeys.java index f17098a5cd..15762c76e5 100644 --- a/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/ssh/ECDSAKeys.java +++ b/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/ssh/ECDSAKeys.java @@ -128,8 +128,7 @@ public class ECDSAKeys { } ECParameterSpec spec = CURVES.get(curveName); stream = new ByteArrayInputStream(base64().decode(get(parts, 1))); - @SuppressWarnings("unused") - String keyType = new String(readLengthFirst(stream)); + readLengthFirst(stream); // ignore return value String curveMarker = new String(readLengthFirst(stream)); checkArgument(curveName.equals(curveMarker), "looking for marker %s but got %s", curveName, curveMarker); @@ -308,7 +307,7 @@ public class ECDSAKeys { } public static class EllipticCurves { - public static ECParameterSpec nistp256 = new ECParameterSpec( + public static final ECParameterSpec nistp256 = new ECParameterSpec( new EllipticCurve( new ECFieldFp(new BigInteger("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", 16)), new BigInteger("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", 16), @@ -318,7 +317,7 @@ public class ECDSAKeys { new BigInteger("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", 16), 1); - public static ECParameterSpec nistp384 = new ECParameterSpec( + public static final ECParameterSpec nistp384 = new ECParameterSpec( new EllipticCurve( new ECFieldFp(new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", 16)), new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC", 16), @@ -328,7 +327,7 @@ public class ECDSAKeys { new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", 16), 1); - public static ECParameterSpec nistp521 = new ECParameterSpec( + public static final ECParameterSpec nistp521 = new ECParameterSpec( new EllipticCurve( new ECFieldFp(new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16)), new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", 16), diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/ProfitBricksComputeServiceAdapter.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/ProfitBricksComputeServiceAdapter.java index 2b4df3dbde..766b3609a5 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/ProfitBricksComputeServiceAdapter.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/ProfitBricksComputeServiceAdapter.java @@ -160,7 +160,7 @@ public class ProfitBricksComputeServiceAdapter implements ComputeServiceAdapter< if (options.getNetworks() != null) try { String networkId = Iterables.get(options.getNetworks(), 0); - lanId = Integer.valueOf(networkId); + lanId = Integer.parseInt(networkId); } catch (Exception ex) { logger.warn("no valid network id found from options. using default id='%d'", DEFAULT_LAN_ID); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/handlers/ProfitBricksHttpErrorHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/handlers/ProfitBricksHttpErrorHandler.java index eaf26fa72b..847269e054 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/handlers/ProfitBricksHttpErrorHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/handlers/ProfitBricksHttpErrorHandler.java @@ -46,8 +46,6 @@ public class ProfitBricksHttpErrorHandler implements HttpErrorHandler { Exception exception = message != null ? new HttpResponseException(command, response, message) : new HttpResponseException(command, response); - message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), - response.getStatusLine()); try { switch (response.getStatusCode()) {