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

View File

@ -756,7 +756,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
ServiceOffering svo = _entityMgr.findById(ServiceOffering.class, vm.getServiceOfferingId()); ServiceOffering svo = _entityMgr.findById(ServiceOffering.class, vm.getServiceOfferingId());
DiskOffering diskVO = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId()); DiskOffering diskVO = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
Long clusterId = (storagePool == null ? null : storagePool.getClusterId()); Long clusterId = storagePool.getClusterId();
VolumeInfo vol = null; VolumeInfo vol = null;
if (volume.getState() == Volume.State.Allocated) { 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.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted()));
pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(2, usage.getAccountId());
pstmt.setLong(3, usage.getId()); pstmt.setLong(3, usage.getId());
}
pstmt.executeUpdate(); pstmt.executeUpdate();
}
txn.commit(); txn.commit();
} catch (Exception e) { } catch (Exception e) {
txn.rollback(); txn.rollback();

View File

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

View File

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

View File

@ -100,7 +100,7 @@ public class SwiftUtil {
String[] lines = parser.getLines().split("\\n"); String[] lines = parser.getLines().split("\\n");
for (String line : lines) { for (String line : lines) {
if (line.contains("Errno") || line.contains("failed") || line.contains("not found")) { 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); URI uri = new URI(url);
if (uri.getScheme().equalsIgnoreCase("http")) { if (uri.getScheme().equalsIgnoreCase("http")) {
httpConn = (HttpURLConnection)uri.toURL().openConnection(); httpConn = (HttpURLConnection)uri.toURL().openConnection();
if (httpConn != null) {
httpConn.setConnectTimeout(2000); httpConn.setConnectTimeout(2000);
httpConn.setReadTimeout(5000); httpConn.setReadTimeout(5000);
if (httpConn != null) {
String contentLength = httpConn.getHeaderField("content-length"); String contentLength = httpConn.getHeaderField("content-length");
if (contentLength != null) { if (contentLength != null) {
remoteSize = Long.parseLong(contentLength); remoteSize = Long.parseLong(contentLength);

View File

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

View File

@ -69,8 +69,11 @@ public class SSHKeysHelper {
e.printStackTrace(); e.printStackTrace();
} }
String sumString = toHexString(md5.digest(keyBytes));
String rString = ""; String rString = "";
String sumString = "";
if (md5 != null) {
sumString = toHexString(md5.digest(keyBytes));
}
for (int i = 2; i <= sumString.length(); i += 2) { for (int i = 2; i <= sumString.length(); i += 2) {
rString += sumString.substring(i - 2, i); 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) { public DecodedDataObject(String objType, Long size, String name, String path, DecodedDataStore store) {
this.objType = objType; this.objType = objType;
this.size = size; this.size = size;
this.name = name;
this.path = path; this.path = path;
this.store = store; this.store = store;
} }