Address FindBugs warnings

This commit is contained in:
Andrew Gaul 2013-02-23 13:44:30 -08:00
parent 0d43da7339
commit ff42fdfa13
24 changed files with 79 additions and 76 deletions

View File

@ -39,7 +39,7 @@ public class SCSIDevice extends Device {
} }
private final int bus = 0; private static final int bus = 0;
private final int unit; private final int unit;
public SCSIDevice(String driveUuid, MediaType mediaType, int unit) { public SCSIDevice(String driveUuid, MediaType mediaType, int unit) {

View File

@ -50,7 +50,7 @@ import com.google.common.collect.Sets;
* *
*/ */
public class CloneDriveOptions { public class CloneDriveOptions {
private final String SSD_AFFINITY_TAG = "affinity:ssd"; private static final String SSD_AFFINITY_TAG = "affinity:ssd";
private final Map<String, String> options = Maps.newLinkedHashMap(); private final Map<String, String> options = Maps.newLinkedHashMap();
/** /**

View File

@ -39,7 +39,7 @@ public class SCSIDevice extends Device {
} }
private final int bus = 0; private static final int bus = 0;
private final int unit; private final int unit;
public SCSIDevice(String driveUuid, MediaType mediaType, int unit) { public SCSIDevice(String driveUuid, MediaType mediaType, int unit) {

View File

@ -19,6 +19,7 @@
package org.jclouds.filesystem.strategy.internal; package org.jclouds.filesystem.strategy.internal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.io.BaseEncoding.base16; import static com.google.common.io.BaseEncoding.base16;
import java.io.File; import java.io.File;
@ -208,7 +209,9 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
return eTag; return eTag;
} catch (IOException ex) { } catch (IOException ex) {
if (outputFile != null) { if (outputFile != null) {
outputFile.delete(); if (!outputFile.delete()) {
logger.debug("Could not delete %s", outputFile);
}
} }
throw ex; throw ex;
} finally { } finally {
@ -223,7 +226,9 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
String fileName = buildPathStartingFromBaseDir(container, blobKey); String fileName = buildPathStartingFromBaseDir(container, blobKey);
logger.debug("Deleting blob %s", fileName); logger.debug("Deleting blob %s", fileName);
File fileToBeDeleted = new File(fileName); File fileToBeDeleted = new File(fileName);
fileToBeDeleted.delete(); if (!fileToBeDeleted.delete()) {
logger.debug("Could not delete %s", fileToBeDeleted);
}
// now examine if the key of the blob is a complex key (with a directory structure) // now examine if the key of the blob is a complex key (with a directory structure)
// and eventually remove empty directory // and eventually remove empty directory
@ -404,12 +409,15 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
String parentPath = file.getParent(); String parentPath = file.getParent();
// no need to manage "/" parentPath, because "/" cannot be used as start // no need to manage "/" parentPath, because "/" cannot be used as start
// char of blobkey // char of blobkey
if (null != parentPath || "".equals(parentPath)) { if (!isNullOrEmpty(parentPath)) {
// remove parent directory only it's empty // remove parent directory only it's empty
File directory = new File(buildPathStartingFromBaseDir(container, parentPath)); File directory = new File(buildPathStartingFromBaseDir(container, parentPath));
String[] children = directory.list(); String[] children = directory.list();
if (null == children || children.length == 0) { if (null == children || children.length == 0) {
directory.delete(); if (!directory.delete()) {
logger.debug("Could not delete %s", directory);
return;
}
// recursively call for removing other path // recursively call for removing other path
removeDirectoriesTreeOfBlobKey(container, parentPath); removeDirectoriesTreeOfBlobKey(container, parentPath);
} }

View File

@ -33,7 +33,7 @@ import com.google.common.cache.CacheLoader;
@Beta @Beta
public class BackoffOnNotFoundWhenGetBucketACL extends CacheLoader<String, AccessControlList> { public class BackoffOnNotFoundWhenGetBucketACL extends CacheLoader<String, AccessControlList> {
private final S3Client client; private final S3Client client;
private final int maxTries = 5; private static final int maxTries = 5;
@Inject @Inject
BackoffOnNotFoundWhenGetBucketACL(S3Client client) { BackoffOnNotFoundWhenGetBucketACL(S3Client client) {

View File

@ -56,6 +56,11 @@ public final class User {
return arn; return arn;
} }
@Override
public int hashCode() {
return Objects.hashCode(id, arn);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)

View File

@ -35,12 +35,8 @@ import com.google.common.collect.ImmutableSet.Builder;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class DataCentersHandler extends ParseSax.HandlerWithResult<Set<DataCenter>> { public class DataCentersHandler extends ParseSax.HandlerWithResult<Set<DataCenter>> {
protected StringBuilder currentText = new StringBuilder();
protected Builder<DataCenter> dataCenters = ImmutableSet.builder(); protected Builder<DataCenter> dataCenters = ImmutableSet.builder();
protected DataCenter.Builder builder = DataCenter.builder();
protected final DataCenterHandler handler; protected final DataCenterHandler handler;
public Set<DataCenter> getResult() { public Set<DataCenter> getResult() {

View File

@ -67,7 +67,7 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Org> {
putReferenceType(catalogs, attributes); putReferenceType(catalogs, attributes);
} else if (type.indexOf("tasksList+xml") != -1) { } else if (type.indexOf("tasksList+xml") != -1) {
putReferenceType(tasksLists, attributes); putReferenceType(tasksLists, attributes);
} else if (type != null && type.endsWith("keysList+xml")) { } else if (type.endsWith("keysList+xml")) {
keys = newReferenceType(attributes); keys = newReferenceType(attributes);
} }
} }

View File

@ -43,13 +43,9 @@ public class Processor implements Comparable<Processor> {
*/ */
@Override @Override
public int compareTo(Processor that) { public int compareTo(Processor that) {
if (that instanceof Processor) {
Processor thatProcessor = Processor.class.cast(that); Processor thatProcessor = Processor.class.cast(that);
return ComparisonChain.start().compare(this.getCores(), thatProcessor.getCores()) return ComparisonChain.start().compare(this.getCores(), thatProcessor.getCores())
.compare(this.getSpeed(), thatProcessor.getSpeed()).result(); .compare(this.getSpeed(), thatProcessor.getSpeed()).result();
} else {
return -1;
}
} }
/** /**

View File

@ -76,8 +76,12 @@ public class KeyStoreSupplier implements Supplier<KeyStore> {
File certFile = new File(checkNotNull(cert)); File certFile = new File(checkNotNull(cert));
if (certFile.isFile()) { // cert is path to pkcs12 file if (certFile.isFile()) { // cert is path to pkcs12 file
FileInputStream stream = new FileInputStream(certFile);
keyStore.load(new FileInputStream(certFile), keyStorePassword.toCharArray()); try {
keyStore.load(stream, keyStorePassword.toCharArray());
} finally {
stream.close();
}
} else { // cert is PEM encoded, containing private key and certs } else { // cert is PEM encoded, containing private key and certs
// split in private key and certs // split in private key and certs

View File

@ -76,8 +76,12 @@ public class KeyStoreSupplier implements Supplier<KeyStore> {
File certFile = new File(checkNotNull(cert)); File certFile = new File(checkNotNull(cert));
if (certFile.isFile()) { // cert is path to pkcs12 file if (certFile.isFile()) { // cert is path to pkcs12 file
FileInputStream stream = new FileInputStream(certFile);
keyStore.load(new FileInputStream(certFile), keyStorePassword.toCharArray()); try {
keyStore.load(stream, keyStorePassword.toCharArray());
} finally {
stream.close();
}
} else { // cert is PEM encoded, containing private key and certs } else { // cert is PEM encoded, containing private key and certs
// split in private key and certs // split in private key and certs

View File

@ -50,8 +50,6 @@ public class DescribeDBInstancesResultHandler extends
private boolean inInstances; private boolean inInstances;
private String marker; private String marker;
protected int memberDepth;
@Inject @Inject
public DescribeDBInstancesResultHandler(InstanceHandler instanceHandler) { public DescribeDBInstancesResultHandler(InstanceHandler instanceHandler) {
this.instanceHandler = instanceHandler; this.instanceHandler = instanceHandler;

View File

@ -34,7 +34,6 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder; import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.savvis.vpdc.domain.FirewallRule;
import com.jamesmurty.utils.XMLBuilder; import com.jamesmurty.utils.XMLBuilder;
@ -55,7 +54,7 @@ public class BindCaptureVAppTemplateToXmlPayload extends BindToStringPayload imp
for (Object arg : gRequest.getInvocation().getArgs()) { for (Object arg : gRequest.getInvocation().getArgs()) {
if (arg instanceof URI) { if (arg instanceof URI) {
return (URI) arg; return (URI) arg;
} else if (arg instanceof FirewallRule[]) { } else if (arg instanceof URI[]) {
URI[] rules = (URI[]) arg; URI[] rules = (URI[]) arg;
return (rules.length > 0) ? rules[0] : null; return (rules.length > 0) ? rules[0] : null;
} }

View File

@ -34,7 +34,6 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder; import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.savvis.vpdc.domain.FirewallRule;
import com.jamesmurty.utils.XMLBuilder; import com.jamesmurty.utils.XMLBuilder;
@ -55,7 +54,7 @@ public class BindCloneVMToXmlPayload extends BindToStringPayload implements MapB
for (Object arg : gRequest.getInvocation().getArgs()) { for (Object arg : gRequest.getInvocation().getArgs()) {
if (arg instanceof URI) { if (arg instanceof URI) {
return (URI) arg; return (URI) arg;
} else if (arg instanceof FirewallRule[]) { } else if (arg instanceof URI[]) {
URI[] rules = (URI[]) arg; URI[] rules = (URI[]) arg;
return (rules.length > 0) ? rules[0] : null; return (rules.length > 0) ? rules[0] : null;
} }

View File

@ -20,6 +20,8 @@ package org.jclouds.savvis.vpdc.domain;
import java.net.URI; import java.net.URI;
import com.google.common.base.Objects;
/** /**
* API returns a firewall rule in a firewall service * API returns a firewall rule in a firewall service
* *
@ -152,46 +154,28 @@ public class FirewallRule extends ResourceImpl {
return Builder.fromFirewallRule(this); return Builder.fromFirewallRule(this);
} }
@Override
public int hashCode() {
return Objects.hashCode(firewallType, isEnabled, source, destination,
port, policy, description, isLogged, protocol);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (!(obj instanceof FirewallRule))
return false;
if (getClass() != obj.getClass())
return false; return false;
FirewallRule other = (FirewallRule) obj; FirewallRule other = (FirewallRule) obj;
if (firewallType == null) { return Objects.equal(firewallType, other.firewallType) &&
if (other.firewallType != null) isEnabled == other.isEnabled &&
return false; Objects.equal(source, other.source) &&
} else if (!firewallType.equals(other.firewallType)) Objects.equal(destination, other.destination) &&
return false; Objects.equal(port, other.port) &&
if (source == null) { Objects.equal(policy, other.policy) &&
if (other.source != null) Objects.equal(description, other.description) &&
return false; isLogged == other.isLogged &&
} else if (!source.equals(other.source)) Objects.equal(protocol, other.protocol);
return false;
if (destination == null) {
if (other.destination != null)
return false;
} else if (!destination.equals(other.destination))
return false;
if (port == null) {
if (other.port != null)
return false;
} else if (!port.equals(other.port))
return false;
if (policy == null) {
if (other.policy != null)
return false;
} else if (!policy.equals(other.policy))
return false;
if (protocol == null) {
if (other.protocol != null)
return false;
} else if (!protocol.equals(other.protocol))
return false;
return true;
} }
public boolean isEnabled() { public boolean isEnabled() {
@ -232,7 +216,7 @@ public class FirewallRule extends ResourceImpl {
@Override @Override
public String toString() { public String toString() {
return "[firewallType=" + firewallType + ", description=" + description + ", source=" + source + ", destination=" + destination return "[firewallType=" + firewallType + ", isEnabled=" + isEnabled + ", description=" + description + ", source=" + source + ", destination=" + destination
+ ", port=" + port + ", protocol=" + protocol + ", policy=" + policy + ", isLogged=" + isLogged; + ", port=" + port + ", protocol=" + protocol + ", policy=" + policy + ", isLogged=" + isLogged;
} }

View File

@ -55,7 +55,7 @@ public class FirewallServiceHandlerTest {
assertEquals( assertEquals(
result.getFirewallRules(), result.getFirewallRules(),
ImmutableSet.<FirewallRule> of( ImmutableSet.<FirewallRule> of(
FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(true).source("internet") FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(false).source("internet")
.destination("VM Tier01").port("22").protocol("Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build(), .destination("VM Tier01").port("22").protocol("Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build(),
FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(true).source("VM Tier03") FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(true).source("VM Tier03")
.destination("VM Tier03").protocol("Icmp-ping").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build())); .destination("VM Tier03").protocol("Icmp-ping").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build()));

View File

@ -21,6 +21,8 @@ package org.jclouds.ultradns.ws;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Objects;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -51,6 +53,11 @@ public final class UltraDNSWSError {
return description; return description;
} }
@Override
public int hashCode() {
return Objects.hashCode(code, description);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)

View File

@ -52,6 +52,11 @@ public final class Account {
return name; return name;
} }
@Override
public int hashCode() {
return Objects.hashCode(id, name);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)

View File

@ -100,7 +100,7 @@ public class CloneSpec {
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) if (this == o)
return true; return true;
if (o instanceof VmSpec) { if (o instanceof CloneSpec) {
CloneSpec other = (CloneSpec) o; CloneSpec other = (CloneSpec) o;
return Objects.equal(vmSpec, other.vmSpec) && Objects.equal(networkSpec, other.networkSpec); return Objects.equal(vmSpec, other.vmSpec) && Objects.equal(networkSpec, other.networkSpec);
} }

View File

@ -72,7 +72,7 @@ public class IsoSpec {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o instanceof VmSpec) { if (o instanceof IsoSpec) {
IsoSpec other = (IsoSpec) o; IsoSpec other = (IsoSpec) o;
return Objects.equal(sourcePath, other.sourcePath) && return Objects.equal(sourcePath, other.sourcePath) &&
Objects.equal(installationKeySequence, other.installationKeySequence); Objects.equal(installationKeySequence, other.installationKeySequence);

View File

@ -100,7 +100,7 @@ public class MasterSpec {
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) if (this == o)
return true; return true;
if (o instanceof VmSpec) { if (o instanceof MasterSpec) {
MasterSpec other = (MasterSpec) o; MasterSpec other = (MasterSpec) o;
return Objects.equal(vmSpec, other.vmSpec) && Objects.equal(isoSpec, other.isoSpec) return Objects.equal(vmSpec, other.vmSpec) && Objects.equal(isoSpec, other.isoSpec)
&& Objects.equal(networkSpec, other.networkSpec); && Objects.equal(networkSpec, other.networkSpec);

View File

@ -63,7 +63,7 @@ public class NetworkSpec {
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) if (this == o)
return true; return true;
if (o instanceof VmSpec) { if (o instanceof NetworkSpec) {
NetworkSpec other = (NetworkSpec) o; NetworkSpec other = (NetworkSpec) o;
return Objects.equal(networkInterfaceCards, other.networkInterfaceCards); return Objects.equal(networkInterfaceCards, other.networkInterfaceCards);
} }

View File

@ -60,7 +60,7 @@ import com.google.inject.Inject;
@Singleton @Singleton
public class MachineUtils { public class MachineUtils {
public final String IP_V4_ADDRESS_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." public static final String IP_V4_ADDRESS_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";

View File

@ -94,8 +94,6 @@ public abstract class BaseAWSReservationHandler<T> extends HandlerForGeneratedRe
private Set<RunningInstance> instances = Sets.newLinkedHashSet(); private Set<RunningInstance> instances = Sets.newLinkedHashSet();
protected int depth = 0;
private boolean inPlacement; private boolean inPlacement;
@Override @Override