You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2020/05/05 15:52:54 UTC
[GitHub] [geode] bschuchardt commented on a change in pull request #4978: GEODE-8004: Fix for regression introduced by GEODE-7565
bschuchardt commented on a change in pull request #4978:
URL: https://github.com/apache/geode/pull/4978#discussion_r420211074
##########
File path: geode-core/src/main/java/org/apache/geode/distributed/internal/ServerLocationAndMemberId.java
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.distributed.internal;
+
+public class ServerLocationAndMemberId {
+
+ private final ServerLocation serverLocation;
+ private final String memberId;
+
+ public ServerLocationAndMemberId(ServerLocation serverLocation, String memberId) {
+ this.serverLocation = serverLocation;
+ this.memberId = memberId;
+ }
+
+ public ServerLocation getServerLocation() {
+ return this.serverLocation;
+ }
+
+ public String getMemberId() {
+ return this.memberId;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof ServerLocationAndMemberId))
+ return false;
+ final ServerLocationAndMemberId other = (ServerLocationAndMemberId) obj;
+
+ if (!this.serverLocation.equals(other.getServerLocation())) {
+ return false;
+ }
+
+ return this.memberId.equals(other.getMemberId());
Review comment:
There is a null check for memberId in hashCode() but not in equals(). If it's possible for memberId to be null then you should add a null check to equals().
##########
File path: geode-core/src/main/java/org/apache/geode/internal/cache/GridAdvisor.java
##########
@@ -418,18 +418,24 @@ public String toString() {
public int hashCode() {
final String thisHost = this.gp.getHost();
final int thisPort = this.gp.getPort();
- return thisHost != null ? (thisHost.hashCode() ^ thisPort) : thisPort;
+ final String thisMemberId = this.getMemberId().getUniqueId();
+ final int thisMemberIdHashCode = (thisMemberId != null) ? thisMemberId.hashCode() : 0;
+ return thisHost != null ? (thisHost.hashCode() ^ thisPort) + thisMemberIdHashCode
+ : thisPort + thisMemberIdHashCode;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof GridProfileId) {
final GridProfileId other = (GridProfileId) obj;
+
if (this.gp.getPort() == other.gp.getPort()) {
final String thisHost = this.gp.getHost();
final String otherHost = other.gp.getHost();
if (thisHost != null) {
- return thisHost.equals(otherHost);
+ if (thisHost.equals(otherHost)) {
+ return this.getMemberId().getUniqueId().equals(other.getMemberId().getUniqueId());
Review comment:
This pair of equals()/hashCode() methods has the same problem.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org