mirror of https://github.com/apache/cloudstack.git
Fix for issues on Coverity related to IDs cv_1125383, cv_1125382, cv_1125380, cv_1125379, cv_1125378, cv_1125377, cv_1125376, cv_1125375, cv_1125374.
Those bugs are related to classes not implementing Serializable, nox overriding the equals and/or hashCode methods and with empty finalize method. Signed-off-by: Hugo Trippaers <htrippaers@schubergphilis.com>
This commit is contained in:
parent
e77ab38543
commit
c06d8a750c
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.cloudstack.network.contrail.management;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
|
@ -931,7 +932,7 @@ public class ServerDBSyncImpl implements ServerDBSync {
|
|||
s_logger.debug("equal " + siModel.getQualifiedName());
|
||||
}
|
||||
|
||||
static class ServiceInstanceComparator implements Comparator<ServiceInstance> {
|
||||
static class ServiceInstanceComparator implements Comparator<ServiceInstance>, Serializable {
|
||||
@Override
|
||||
public int compare(ServiceInstance obj1, ServiceInstance obj2) {
|
||||
String name1 = StringUtils.join(obj1.getQualifiedName(), ':');
|
||||
|
|
|
|||
|
|
@ -63,10 +63,6 @@ public class ServerEventHandlerImpl implements ServerEventHandler {
|
|||
setClassMap();
|
||||
}
|
||||
|
||||
protected void finalize () {
|
||||
|
||||
}
|
||||
|
||||
private void setMethodMap() {
|
||||
_methodMap = new HashMap<String, Method>();
|
||||
Method methods[] = this.getClass().getMethods();
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.cloudstack.network.contrail.model;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.TreeSet;
|
||||
|
||||
|
|
@ -38,7 +39,7 @@ import com.cloud.exception.InternalErrorException;
|
|||
* The update method pushes updates to the contrail API server.
|
||||
*/
|
||||
public interface ModelObject {
|
||||
public static class ModelReference implements Comparable<ModelReference> {
|
||||
public static class ModelReference implements Comparable<ModelReference>, Serializable {
|
||||
WeakReference<ModelObject> reference;
|
||||
ModelReference(ModelObject obj) {
|
||||
reference = new WeakReference<ModelObject>(obj);
|
||||
|
|
@ -57,8 +58,22 @@ public interface ModelObject {
|
|||
|
||||
return lhs.compareTo(rhs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((reference == null) ? 0 : reference.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other)
|
||||
return true;
|
||||
if (other == null)
|
||||
return false;
|
||||
try {
|
||||
ModelReference rhs = (ModelReference) other;
|
||||
return compareTo(rhs) == 0;
|
||||
|
|
@ -69,6 +84,8 @@ public interface ModelObject {
|
|||
public ModelObject get() {
|
||||
return reference.get();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
public void addSuccessor(ModelObject child);
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@
|
|||
|
||||
package org.apache.cloudstack.network.contrail.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public abstract class ModelObjectBase implements ModelObject {
|
||||
public static class UuidComparator implements Comparator<ModelObject> {
|
||||
public static class UuidComparator implements Comparator<ModelObject>, Serializable {
|
||||
@Override
|
||||
public int compare(ModelObject lhs, ModelObject rhs) {
|
||||
if (lhs == null) {
|
||||
|
|
@ -78,8 +79,23 @@ public abstract class ModelObjectBase implements ModelObject {
|
|||
_successors.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((_ancestors == null) ? 0 : _ancestors.hashCode());
|
||||
result = prime * result
|
||||
+ ((_successors == null) ? 0 : _successors.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object rhs) {
|
||||
if (this == rhs)
|
||||
return true;
|
||||
if (rhs == null)
|
||||
return false;
|
||||
ModelObject other;
|
||||
try {
|
||||
other = (ModelObject) rhs;
|
||||
|
|
|
|||
Loading…
Reference in New Issue