Skip to content
Permalink
Browse files
AMBARI-25517. Should not use '!=' to compare 'Long hostId' in HostSta…
…teEntity, which could lead to unforeseen problems (#3199) (rickyma via dgrinenko)
  • Loading branch information
rickyma committed Jun 9, 2020
1 parent c575567 commit 77b5af4ae591f15f00807c3a939f78393d32d034
Showing 1 changed file with 8 additions and 14 deletions.
@@ -33,6 +33,8 @@

import org.apache.ambari.server.state.HostState;

import java.util.Objects;

@javax.persistence.Table(name = "hoststate")
@Entity
@NamedQueries({
@@ -136,24 +138,16 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;

HostStateEntity that = (HostStateEntity) o;

if (hostId != null ? hostId != that.hostId : that.hostId != null) return false;
if (availableMem != null ? !availableMem.equals(that.availableMem) : that.availableMem != null) return false;
if (timeInState != null ? !timeInState.equals(that.timeInState) : that.timeInState!= null) return false;
if (agentVersion != null ? !agentVersion.equals(that.agentVersion) : that.agentVersion != null) return false;
if (currentState != null ? !currentState.equals(that.currentState) : that.currentState != null) return false;

return true;
return Objects.equals(hostId, that.hostId) &&
Objects.equals(availableMem, that.availableMem) &&
Objects.equals(timeInState, that.timeInState) &&
Objects.equals(agentVersion, that.agentVersion) &&
currentState == that.currentState;
}

@Override
public int hashCode() {
int result = hostId != null ? hostId.intValue() : 0;
result = 31 * result + (availableMem != null ? availableMem.intValue() : 0);
result = 31 * result + (timeInState != null ? timeInState.intValue() : 0);
result = 31 * result + (agentVersion != null ? agentVersion.hashCode() : 0);
result = 31 * result + (currentState != null ? currentState.hashCode() : 0);
return result;
return Objects.hash(hostId, availableMem, timeInState, agentVersion, currentState);
}

public HostEntity getHostEntity() {

0 comments on commit 77b5af4

Please sign in to comment.