Findbugs fixes in cloud-utils project and a few other places

This commit is contained in:
Koushik Das 2014-07-15 14:23:17 +05:30
parent 33d6bc278f
commit aacf8ef77b
10 changed files with 37 additions and 29 deletions

View File

@ -24,7 +24,7 @@ public class NicTO extends NetworkTO {
Integer networkRateMulticastMbps;
boolean defaultNic;
boolean pxeDisable;
String uuid;
String nicUuid;
List<String> nicSecIps;
public NicTO() {
@ -69,12 +69,12 @@ public class NicTO extends NetworkTO {
@Override
public String getUuid() {
return uuid;
return nicUuid;
}
@Override
public void setUuid(String uuid) {
this.uuid = uuid;
this.nicUuid = uuid;
}
@Override

View File

@ -756,7 +756,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
ServiceOffering svo = _entityMgr.findById(ServiceOffering.class, vm.getServiceOfferingId());
DiskOffering diskVO = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
Long clusterId = (storagePool == null ? null : storagePool.getClusterId());
Long clusterId = storagePool.getClusterId();
VolumeInfo vol = null;
if (volume.getState() == Volume.State.Allocated) {

View File

@ -88,8 +88,8 @@ public class UsageVolumeDaoImpl extends GenericDaoBase<UsageVolumeVO, Long> impl
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted()));
pstmt.setLong(2, usage.getAccountId());
pstmt.setLong(3, usage.getId());
pstmt.executeUpdate();
}
pstmt.executeUpdate();
txn.commit();
} catch (Exception e) {
txn.rollback();

View File

@ -61,7 +61,7 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
pstmt.executeUpdate();
} catch (SQLException e) {
throw new CloudRuntimeException("DB exception on " + pstmt.toString(), e);
throw new CloudRuntimeException("DB exception: ", e);
}
}
@ -227,7 +227,7 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
throw new CloudRuntimeException("Invalid cluster session detected, runId " + runId + " is no longer valid", new ClusterInvalidSessionException("runId " + runId + " is no longer valid"));
}
} catch (SQLException e) {
throw new CloudRuntimeException("DB exception on " + pstmt.toString(), e);
throw new CloudRuntimeException("DB exception: ", e);
}
}
@ -255,7 +255,7 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase<ManagementServer
orphanList.add(rs.getLong(1));
}
} catch (SQLException e) {
throw new CloudRuntimeException("DB exception on " + pstmt.toString(), e);
throw new CloudRuntimeException("DB exception: ", e);
}
return orphanList;

View File

@ -101,24 +101,28 @@ public class NumbersUtil {
* @return interval in ms
*/
public static long parseInterval(String str, long defaultValue) {
SimpleDateFormat sdf = null;
if (str.contains("D")) {
sdf = new SimpleDateFormat("dd'D'HH'h'mm'M'ss'S'SSS'ms'");
} else if (str.contains("h")) {
sdf = new SimpleDateFormat("HH'h'mm'M'ss'S'SSS'ms'");
} else if (str.contains("M")) {
sdf = new SimpleDateFormat("mm'M'ss'S'SSS'ms'");
} else if (str.contains("S")) {
sdf = new SimpleDateFormat("ss'S'SSS'ms'");
} else if (str.contains("ms")) {
sdf = new SimpleDateFormat("SSS'ms'");
}
Date date;
try {
if (str == null || sdf == null) {
if (str == null) {
throw new ParseException("String is wrong", 0);
}
date = sdf.parse(str);
SimpleDateFormat sdf = null;
if (str.contains("D")) {
sdf = new SimpleDateFormat("dd'D'HH'h'mm'M'ss'S'SSS'ms'");
} else if (str.contains("h")) {
sdf = new SimpleDateFormat("HH'h'mm'M'ss'S'SSS'ms'");
} else if (str.contains("M")) {
sdf = new SimpleDateFormat("mm'M'ss'S'SSS'ms'");
} else if (str.contains("S")) {
sdf = new SimpleDateFormat("ss'S'SSS'ms'");
} else if (str.contains("ms")) {
sdf = new SimpleDateFormat("SSS'ms'");
}
if (sdf == null) {
throw new ParseException("String is wrong", 0);
}
Date date = sdf.parse(str);
return date.getTime();
} catch (ParseException e) {
if (defaultValue != -1) {

View File

@ -100,7 +100,7 @@ public class SwiftUtil {
String[] lines = parser.getLines().split("\\n");
for (String line : lines) {
if (line.contains("Errno") || line.contains("failed") || line.contains("not found")) {
throw new CloudRuntimeException("Failed to upload file: " + lines.toString());
throw new CloudRuntimeException("Failed to upload file: " + Arrays.toString(lines));
}
}
}

View File

@ -205,9 +205,9 @@ public class UriUtils {
URI uri = new URI(url);
if (uri.getScheme().equalsIgnoreCase("http")) {
httpConn = (HttpURLConnection)uri.toURL().openConnection();
httpConn.setConnectTimeout(2000);
httpConn.setReadTimeout(5000);
if (httpConn != null) {
httpConn.setConnectTimeout(2000);
httpConn.setReadTimeout(5000);
String contentLength = httpConn.getHeaderField("content-length");
if (contentLength != null) {
remoteSize = Long.parseLong(contentLength);

View File

@ -1420,10 +1420,10 @@ public class NetUtils {
public static boolean isSameIsolationId(String one, String other) {
// check nulls
// check empty strings
if ((one == null || one.equals("")) && (other == null || other.equals(""))) {
if ((one == null || one.isEmpty()) && (other == null || other.isEmpty())) {
return true;
}
if ((one == null || other == null) && !(one == null && other == null)) {
if (one == null || other == null) {
return false;
}
// check 'untagged'

View File

@ -69,8 +69,11 @@ public class SSHKeysHelper {
e.printStackTrace();
}
String sumString = toHexString(md5.digest(keyBytes));
String rString = "";
String sumString = "";
if (md5 != null) {
sumString = toHexString(md5.digest(keyBytes));
}
for (int i = 2; i <= sumString.length(); i += 2) {
rString += sumString.substring(i - 2, i);

View File

@ -29,6 +29,7 @@ public class DecodedDataObject {
public DecodedDataObject(String objType, Long size, String name, String path, DecodedDataStore store) {
this.objType = objType;
this.size = size;
this.name = name;
this.path = path;
this.store = store;
}