Fix a few Coverity defects

This commit is contained in:
Andrew Gaul 2017-11-05 16:42:31 -08:00
parent 83d10e8194
commit 46759f8bda
7 changed files with 22 additions and 8 deletions

View File

@ -281,7 +281,7 @@ public class Capacity implements Comparable<Capacity> {
public int compareTo(Capacity other) {
int comparison = this.zoneId.compareTo(other.zoneId);
if (comparison == 0) comparison = this.podId.compareTo(other.podId);
if (comparison == 0) Integer.valueOf(this.type.code).compareTo(other.type.code);
if (comparison == 0) comparison = Integer.valueOf(this.type.code).compareTo(other.type.code);
return comparison;
}
}

View File

@ -114,6 +114,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.io.ByteSource;
import com.google.common.io.ByteStreams;
import com.google.common.io.Closeables;
import com.google.common.net.HttpHeaders;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@ -758,7 +759,13 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
SwiftObject object = api.getObjectApi(regionId, containerName)
.get(objectName, org.jclouds.http.options.GetOptions.Builder.range(begin, end));
// Download first, this is the part that usually fails
byte[] targetArray = ByteStreams.toByteArray(object.getPayload().openStream());
byte[] targetArray;
InputStream is = object.getPayload().openStream();
try {
targetArray = ByteStreams.toByteArray(is);
} finally {
Closeables.closeQuietly(is);
}
// Map file region
MappedByteBuffer out = raf.getChannel().map(FileChannel.MapMode.READ_WRITE, begin, end - begin + 1);
out.put(targetArray);
@ -898,7 +905,13 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
long time = System.nanoTime();
SwiftObject object = api.getObjectApi(regionId, containerName)
.get(objectName, org.jclouds.http.options.GetOptions.Builder.range(begin, end));
byte[] downloadedBlock = ByteStreams.toByteArray(object.getPayload().openStream());
byte[] downloadedBlock;
InputStream is = object.getPayload().openStream();
try {
downloadedBlock = ByteStreams.toByteArray(is);
} finally {
Closeables.closeQuietly(is);
}
return downloadedBlock;
} catch (IOException e) {
logger.debug(e.toString());

View File

@ -24,6 +24,7 @@ import static org.jclouds.util.Maps2.transformKeys;
import static org.jclouds.util.Predicates2.startsWith;
import java.util.Map;
import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.inject.Named;
@ -107,7 +108,7 @@ public class ReadAnnotationsAndProperties implements InvocationConfig {
});
return transformKeys(longsByName, new Function<String, String>() {
public String apply(String input) {
return input.replaceFirst(PROPERTY_TIMEOUTS_PREFIX, "");
return input.replaceFirst(Pattern.quote(PROPERTY_TIMEOUTS_PREFIX), "");
}
});
}

View File

@ -275,7 +275,7 @@ public class JschSshClient implements SshClient {
try {
sftp.put(is, path);
} finally {
Closeables2.closeQuietly(contents);
Closeables2.closeQuietly(is);
}
return null;
}

View File

@ -49,7 +49,7 @@ public class ParseToResumableUpload implements Function<HttpResponse, ResumableU
}
}
return ResumableUpload.create(response.getStatusCode(), uploadId, contentLength, upperLimit, lowerLimit);
return ResumableUpload.create(response.getStatusCode(), uploadId, contentLength, lowerLimit, upperLimit);
}
// Return the Id of the Upload

View File

@ -137,7 +137,7 @@ public class ResponseStatusFromPayloadHttpCommandExecutorService extends JavaUrl
char[] chars = new char[size];
byte[] bytes = new byte[size];
is.read(bytes, 0, size);
ByteStreams.readFully(is, bytes);
for (int i = 0; i < size;)
chars[i] = (char) (bytes[i++] & 0xff);

View File

@ -164,7 +164,7 @@ public class SoftLayerComputeServiceAdapter implements
} else {
VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup = VirtualGuestBlockDeviceTemplateGroup
.builder().globalIdentifier(imageId).build();
virtualGuestBuilder.blockDeviceTemplateGroup(blockDeviceTemplateGroup).build();
virtualGuestBuilder.blockDeviceTemplateGroup(blockDeviceTemplateGroup);
}
// set multi-disks
if (!templateOptions.getBlockDevices().isEmpty()) {