Merge pull request #1354 from maginatics/findbugs

Address FindBugs warnings
This commit is contained in:
Adrian Cole 2013-02-24 23:46:49 -08:00
commit 5626922ad4
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;
public SCSIDevice(String driveUuid, MediaType mediaType, int unit) {

View File

@ -50,7 +50,7 @@ import com.google.common.collect.Sets;
*
*/
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();
/**

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;
public SCSIDevice(String driveUuid, MediaType mediaType, int unit) {

View File

@ -19,6 +19,7 @@
package org.jclouds.filesystem.strategy.internal;
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 java.io.File;
@ -208,7 +209,9 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
return eTag;
} catch (IOException ex) {
if (outputFile != null) {
outputFile.delete();
if (!outputFile.delete()) {
logger.debug("Could not delete %s", outputFile);
}
}
throw ex;
} finally {
@ -223,7 +226,9 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
String fileName = buildPathStartingFromBaseDir(container, blobKey);
logger.debug("Deleting blob %s", 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)
// and eventually remove empty directory
@ -404,12 +409,15 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
String parentPath = file.getParent();
// no need to manage "/" parentPath, because "/" cannot be used as start
// char of blobkey
if (null != parentPath || "".equals(parentPath)) {
if (!isNullOrEmpty(parentPath)) {
// remove parent directory only it's empty
File directory = new File(buildPathStartingFromBaseDir(container, parentPath));
String[] children = directory.list();
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
removeDirectoriesTreeOfBlobKey(container, parentPath);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -50,8 +50,6 @@ public class DescribeDBInstancesResultHandler extends
private boolean inInstances;
private String marker;
protected int memberDepth;
@Inject
public DescribeDBInstancesResultHandler(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.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.savvis.vpdc.domain.FirewallRule;
import com.jamesmurty.utils.XMLBuilder;
@ -55,7 +54,7 @@ public class BindCaptureVAppTemplateToXmlPayload extends BindToStringPayload imp
for (Object arg : gRequest.getInvocation().getArgs()) {
if (arg instanceof URI) {
return (URI) arg;
} else if (arg instanceof FirewallRule[]) {
} else if (arg instanceof URI[]) {
URI[] rules = (URI[]) arg;
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.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.savvis.vpdc.domain.FirewallRule;
import com.jamesmurty.utils.XMLBuilder;
@ -55,7 +54,7 @@ public class BindCloneVMToXmlPayload extends BindToStringPayload implements MapB
for (Object arg : gRequest.getInvocation().getArgs()) {
if (arg instanceof URI) {
return (URI) arg;
} else if (arg instanceof FirewallRule[]) {
} else if (arg instanceof URI[]) {
URI[] rules = (URI[]) arg;
return (rules.length > 0) ? rules[0] : null;
}

View File

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

View File

@ -55,7 +55,7 @@ public class FirewallServiceHandlerTest {
assertEquals(
result.getFirewallRules(),
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(),
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()));

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.Preconditions.checkNotNull;
import com.google.common.base.Objects;
/**
* @author Adrian Cole
*/
@ -51,6 +53,11 @@ public final class UltraDNSWSError {
return description;
}
@Override
public int hashCode() {
return Objects.hashCode(code, description);
}
@Override
public boolean equals(Object obj) {
if (this == obj)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -60,7 +60,7 @@ import com.google.inject.Inject;
@Singleton
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])$";

View File

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