SOLR-14541: Ensure classes that implement equals implement hashCode or suppress warnings

This commit is contained in:
Erick Erickson 2020-06-25 16:35:56 -04:00
parent f1650d5f47
commit 11538e52a2
20 changed files with 103 additions and 82 deletions

View File

@ -391,6 +391,9 @@ Other Changes
* SOLR-14589: Remove IntelliJ //noinspection comments (Erick Erickson) * SOLR-14589: Remove IntelliJ //noinspection comments (Erick Erickson)
* SOLR-14541: Ensure classes that implement equals implement hashCode or suppress warnings
(gezapeti, Ilan Ginsburg, Erick Erickson)
================== 8.5.2 ================== ================== 8.5.2 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

View File

@ -365,7 +365,7 @@ public class Rule {
@Override @Override
public int hashCode() { public int hashCode() {
throw new UnsupportedOperationException("TODO unimplemented"); return Objects.hash(name, operand);
} }
@Override @Override

View File

@ -19,6 +19,7 @@ package org.apache.solr.packagemanager;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.apache.solr.common.annotation.JsonProperty; import org.apache.solr.common.annotation.JsonProperty;
import org.apache.solr.common.util.ReflectMapWriter; import org.apache.solr.common.util.ReflectMapWriter;
@ -61,7 +62,7 @@ public class SolrPackageInstance implements ReflectMapWriter {
@Override @Override
public int hashCode() { public int hashCode() {
throw new UnsupportedOperationException("TODO unimplemented"); return Objects.hash(name, version);
} }
@Override @Override

View File

@ -210,7 +210,7 @@ public class PackageAPI {
@Override @Override
public int hashCode() { public int hashCode() {
throw new UnsupportedOperationException("TODO unimplemented"); return Objects.hash(version);
} }
@Override @Override

View File

@ -28,6 +28,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Objects;
import org.apache.solr.common.MapWriter; import org.apache.solr.common.MapWriter;
import org.apache.solr.common.params.AutoScalingParams; import org.apache.solr.common.params.AutoScalingParams;
@ -42,7 +43,6 @@ import static java.util.stream.Collectors.toList;
* Bean representation of <code>autoscaling.json</code>, which parses data * Bean representation of <code>autoscaling.json</code>, which parses data
* lazily. * lazily.
*/ */
@SuppressWarnings({"overrides"})
public class AutoScalingConfig implements MapWriter { public class AutoScalingConfig implements MapWriter {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@ -59,7 +59,6 @@ public class AutoScalingConfig implements MapWriter {
/** /**
* Bean representation of trigger listener config. * Bean representation of trigger listener config.
*/ */
@SuppressWarnings({"overrides"})
public static class TriggerListenerConfig implements MapWriter { public static class TriggerListenerConfig implements MapWriter {
public final String name; public final String name;
public final String trigger; public final String trigger;
@ -140,11 +139,11 @@ public class AutoScalingConfig implements MapWriter {
return properties.equals(that.properties); return properties.equals(that.properties);
} }
// @Override @Override
// public int hashCode() { public int hashCode() {
// throw new UnsupportedOperationException("TODO unimplemented"); return Objects.hash(name, trigger, listenerClass);
// } }
//
@Override @Override
public String toString() { public String toString() {
return Utils.toJSONString(this); return Utils.toJSONString(this);
@ -154,7 +153,6 @@ public class AutoScalingConfig implements MapWriter {
/** /**
* Bean representation of trigger config. * Bean representation of trigger config.
*/ */
@SuppressWarnings({"overrides"})
public static class TriggerConfig implements MapWriter { public static class TriggerConfig implements MapWriter {
/** Trigger name. */ /** Trigger name. */
public final String name; public final String name;
@ -234,10 +232,11 @@ public class AutoScalingConfig implements MapWriter {
if (event != that.event) return false; if (event != that.event) return false;
return properties.equals(that.properties); return properties.equals(that.properties);
} }
// @Override
// public int hashCode() { @Override
// throw new UnsupportedOperationException("TODO unimplemented"); public int hashCode() {
// } return Objects.hash(name);
}
@Override @Override
public void writeMap(EntryWriter ew) throws IOException { public void writeMap(EntryWriter ew) throws IOException {
@ -262,11 +261,10 @@ public class AutoScalingConfig implements MapWriter {
/** /**
* Bean representation of trigger action configuration. * Bean representation of trigger action configuration.
*/ */
@SuppressWarnings({"overrides"})
public static class ActionConfig implements MapWriter { public static class ActionConfig implements MapWriter {
/** Action name. */ /** Action name. */
public final String name; public final String name;
/** Class name of action implementtion. */ /** Class name of action implementation. */
public final String actionClass; public final String actionClass;
/** Additional action properties. */ /** Additional action properties. */
public final Map<String, Object> properties; public final Map<String, Object> properties;
@ -305,10 +303,10 @@ public class AutoScalingConfig implements MapWriter {
return properties.equals(that.properties); return properties.equals(that.properties);
} }
// @Override @Override
// public int hashCode() { public int hashCode() {
// throw new UnsupportedOperationException("TODO unimplemented"); return Objects.hash(properties);
// } }
@Override @Override
public String toString() { public String toString() {
@ -587,11 +585,11 @@ public class AutoScalingConfig implements MapWriter {
if (!getTriggerListenerConfigs().equals(that.getTriggerListenerConfigs())) return false; if (!getTriggerListenerConfigs().equals(that.getTriggerListenerConfigs())) return false;
return getProperties().equals(that.getProperties()); return getProperties().equals(that.getProperties());
} }
// @Override
// public int hashCode() {
// throw new UnsupportedOperationException("TODO unimplemented");
// }
@Override
public int hashCode() {
return Objects.hash(getPolicy());
}
private static List<Object> getList(String key, Map<String, Object> properties) { private static List<Object> getList(String key, Map<String, Object> properties) {
return getList(key, properties, null); return getList(key, properties, null);

View File

@ -70,7 +70,6 @@ import static org.apache.solr.client.solrj.cloud.autoscaling.Variable.Type.WITH_
* Create a fresh new session for each use * Create a fresh new session for each use
* *
*/ */
@SuppressWarnings({"overrides"})
public class Policy implements MapWriter { public class Policy implements MapWriter {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@ -288,10 +287,8 @@ public class Policy implements MapWriter {
return getClusterPreferences().equals(policy.getClusterPreferences()); return getClusterPreferences().equals(policy.getClusterPreferences());
} }
// @Override @Override
// public int hashCode() { public int hashCode() { return Objects.hash(getPolicies()); }
// throw new UnsupportedOperationException("TODO unimplemented");
// }
public static Map<String, List<Clause>> clausesFromMap(Map<String, List<Map<String, Object>>> map, List<String> newParams) { public static Map<String, List<Clause>> clausesFromMap(Map<String, List<Map<String, Object>>> map, List<String> newParams) {
Map<String, List<Clause>> newPolicies = new HashMap<>(); Map<String, List<Clause>> newPolicies = new HashMap<>();

View File

@ -22,6 +22,7 @@ import java.lang.invoke.MethodHandles;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.apache.solr.common.MapWriter; import org.apache.solr.common.MapWriter;
import org.apache.solr.common.util.StrUtils; import org.apache.solr.common.util.StrUtils;
@ -29,7 +30,6 @@ import org.apache.solr.common.util.Utils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@SuppressWarnings({"overrides"})
public class Preference implements MapWriter { public class Preference implements MapWriter {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@ -133,10 +133,10 @@ public class Preference implements MapWriter {
return original.equals(that.original); return original.equals(that.original);
} }
// @Override @Override
// public int hashCode() { public int hashCode() {
// throw new UnsupportedOperationException("TODO unimplemented"); return Objects.hash(getName(), precision, sort, idx);
// } }
public Policy.SortParam getName() { public Policy.SortParam getName() {
return name; return name;

View File

@ -19,12 +19,12 @@ package org.apache.solr.client.solrj.cloud.autoscaling;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.apache.solr.common.MapWriter; import org.apache.solr.common.MapWriter;
import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.util.Utils; import org.apache.solr.common.util.Utils;
@SuppressWarnings({"overrides"})
class ReplicaCount implements MapWriter { class ReplicaCount implements MapWriter {
long nrt, tlog, pull; long nrt, tlog, pull;
@ -107,10 +107,10 @@ class ReplicaCount implements MapWriter {
return false; return false;
} }
// @Override @Override
// public int hashCode() { public int hashCode() {
// throw new UnsupportedOperationException("TODO unimplemented"); return Objects.hash(nrt, tlog, pull);
// } }
@Override @Override
public String toString() { public String toString() {

View File

@ -35,7 +35,6 @@ import static org.apache.solr.common.ConditionalMapWriter.NON_NULL_VAL;
import static org.apache.solr.common.ConditionalMapWriter.dedupeKeyPredicate; import static org.apache.solr.common.ConditionalMapWriter.dedupeKeyPredicate;
import static org.apache.solr.common.cloud.ZkStateReader.LEADER_PROP; import static org.apache.solr.common.cloud.ZkStateReader.LEADER_PROP;
@SuppressWarnings({"overrides"})
public class ReplicaInfo implements MapWriter { public class ReplicaInfo implements MapWriter {
private final String name; private final String name;
private final String core, collection, shard; private final String core, collection, shard;
@ -209,10 +208,10 @@ public class ReplicaInfo implements MapWriter {
} }
} }
// @Override @Override
// public int hashCode() { public int hashCode() {
// throw new UnsupportedOperationException("TODO unimplemented"); return Objects.hash(name, core, collection, shard, type);
// } }
@Override @Override
public String toString() { public String toString() {

View File

@ -28,7 +28,6 @@ import org.apache.zookeeper.CreateMode;
/** /**
* Immutable representation of binary data with version. * Immutable representation of binary data with version.
*/ */
@SuppressWarnings({"overrides"})
public class VersionedData implements MapWriter { public class VersionedData implements MapWriter {
private final int version; private final int version;
private final byte[] data; private final byte[] data;
@ -93,9 +92,8 @@ public class VersionedData implements MapWriter {
mode == that.mode; mode == that.mode;
} }
// @Override @Override
// public int hashCode() { public int hashCode() {
// throw new UnsupportedOperationException("TODO unimplemented"); return Objects.hash(version, owner);
// } }
} }

View File

@ -463,7 +463,6 @@ public class CloudSolrStream extends TupleStream implements Expressible {
} }
} }
@SuppressWarnings({"overrides"})
protected class TupleWrapper implements Comparable<TupleWrapper> { protected class TupleWrapper implements Comparable<TupleWrapper> {
private Tuple tuple; private Tuple tuple;
private SolrStream stream; private SolrStream stream;
@ -491,6 +490,11 @@ public class CloudSolrStream extends TupleStream implements Expressible {
return this == o; return this == o;
} }
@Override
public int hashCode() {
return Objects.hash(tuple);
}
public Tuple getTuple() { public Tuple getTuple() {
return tuple; return tuple;
} }

View File

@ -411,7 +411,6 @@ public class DeepRandomStream extends TupleStream implements Expressible {
} }
} }
@SuppressWarnings({"overrides"})
protected class TupleWrapper implements Comparable<TupleWrapper> { protected class TupleWrapper implements Comparable<TupleWrapper> {
private Tuple tuple; private Tuple tuple;
private SolrStream stream; private SolrStream stream;
@ -435,10 +434,15 @@ public class DeepRandomStream extends TupleStream implements Expressible {
} }
} }
@Override
public boolean equals(Object o) { public boolean equals(Object o) {
return this == o; return this == o;
} }
@Override
public int hashCode() {
return Objects.hash(tuple);
}
public Tuple getTuple() { public Tuple getTuple() {
return tuple; return tuple;
} }

View File

@ -18,11 +18,11 @@ package org.apache.solr.client.solrj.io.stream.expr;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* Expression containing a function and set of parameters * Expression containing a function and set of parameters
*/ */
@SuppressWarnings({"overrides"})
public class StreamExpression implements StreamExpressionParameter { public class StreamExpression implements StreamExpressionParameter {
private String functionName; private String functionName;
private List<StreamExpressionParameter> parameters; private List<StreamExpressionParameter> parameters;
@ -124,4 +124,9 @@ public class StreamExpression implements StreamExpressionParameter {
return true; return true;
} }
@Override
public int hashCode() {
return Objects.hash(functionName);
}
} }

View File

@ -17,10 +17,11 @@
package org.apache.solr.client.solrj.io.stream.expr; package org.apache.solr.client.solrj.io.stream.expr;
import java.util.Objects;
/** /**
* Provides a named parameter * Provides a named parameter
*/ */
@SuppressWarnings({"overrides"})
public class StreamExpressionNamedParameter implements StreamExpressionParameter { public class StreamExpressionNamedParameter implements StreamExpressionParameter {
private String name; private String name;
private StreamExpressionParameter parameter; private StreamExpressionParameter parameter;
@ -106,4 +107,9 @@ public class StreamExpressionNamedParameter implements StreamExpressionParameter
return this.parameter.equals(check.parameter); return this.parameter.equals(check.parameter);
} }
@Override
public int hashCode() {
return Objects.hash(name);
}
} }

View File

@ -16,10 +16,11 @@
*/ */
package org.apache.solr.client.solrj.io.stream.expr; package org.apache.solr.client.solrj.io.stream.expr;
/** import java.util.Objects;
/**
* Basic string stream expression * Basic string stream expression
*/ */
@SuppressWarnings({"overrides"})
public class StreamExpressionValue implements StreamExpressionParameter { public class StreamExpressionValue implements StreamExpressionParameter {
private String value; private String value;
@ -63,4 +64,9 @@ public class StreamExpressionValue implements StreamExpressionParameter {
return this.value.equals(((StreamExpressionValue)other).value); return this.value.equals(((StreamExpressionValue)other).value);
} }
@Override
public int hashCode() {
return Objects.hash(value);
}
} }

View File

@ -25,7 +25,6 @@ import org.apache.solr.common.util.ReflectMapWriter;
/** /**
* POJO for a plugin metadata used in container plugins * POJO for a plugin metadata used in container plugins
*/ */
@SuppressWarnings({"overrides"})
public class PluginMeta implements ReflectMapWriter { public class PluginMeta implements ReflectMapWriter {
@JsonProperty(required = true) @JsonProperty(required = true)
public String name; public String name;
@ -55,4 +54,8 @@ public class PluginMeta implements ReflectMapWriter {
} }
return false; return false;
} }
@Override
public int hashCode() {
return Objects.hash(name, version, klass);
}
} }

View File

@ -46,7 +46,6 @@ import static org.apache.solr.common.util.Utils.toJSONString;
/** /**
* Models a Collection in zookeeper (but that Java name is obviously taken, hence "DocCollection") * Models a Collection in zookeeper (but that Java name is obviously taken, hence "DocCollection")
*/ */
@SuppressWarnings({"overrides"})
public class DocCollection extends ZkNodeProps implements Iterable<Slice> { public class DocCollection extends ZkNodeProps implements Iterable<Slice> {
public static final String DOC_ROUTER = "router"; public static final String DOC_ROUTER = "router";
@ -383,10 +382,10 @@ public class DocCollection extends ZkNodeProps implements Iterable<Slice> {
return super.equals(that) && Objects.equals(this.name, other.name) && this.znodeVersion == other.znodeVersion; return super.equals(that) && Objects.equals(this.name, other.name) && this.znodeVersion == other.znodeVersion;
} }
// @Override @Override
// public int hashCode() { public int hashCode() {
// throw new UnsupportedOperationException("TODO unimplemented DocCollection.hashCode"); return Objects.hash(name, znodeVersion);
// } }
/** /**
* @return the number of replicas of type {@link org.apache.solr.common.cloud.Replica.Type#NRT} this collection was created with * @return the number of replicas of type {@link org.apache.solr.common.cloud.Replica.Type#NRT} this collection was created with

View File

@ -22,7 +22,6 @@ import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.apache.solr.common.util.Utils; import org.apache.solr.common.util.Utils;
@SuppressWarnings({"overrides"})
public class Replica extends ZkNodeProps { public class Replica extends ZkNodeProps {
/** /**
@ -153,10 +152,12 @@ public class Replica extends ZkNodeProps {
return name.equals(replica.name); return name.equals(replica.name);
} }
// @Override
// public int hashCode() { @Override
// throw new UnsupportedOperationException("TODO unimplemented Replica.hashCode()"); public int hashCode() {
// } return Objects.hash(name);
}
/** Also known as coreNodeName. */ /** Also known as coreNodeName. */
public String getName() { public String getName() {
return name; return name;

View File

@ -17,10 +17,7 @@
package org.apache.solr.common.cloud; package org.apache.solr.common.cloud;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.*;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.apache.solr.common.util.JavaBinCodec; import org.apache.solr.common.util.JavaBinCodec;
import org.apache.solr.common.util.Utils; import org.apache.solr.common.util.Utils;
@ -31,7 +28,6 @@ import static org.apache.solr.common.util.Utils.toJSONString;
/** /**
* ZkNodeProps contains generic immutable properties. * ZkNodeProps contains generic immutable properties.
*/ */
@SuppressWarnings({"overrides"})
public class ZkNodeProps implements JSONWriter.Writable { public class ZkNodeProps implements JSONWriter.Writable {
protected final Map<String,Object> propMap; protected final Map<String,Object> propMap;
@ -171,8 +167,9 @@ public class ZkNodeProps implements JSONWriter.Writable {
public boolean equals(Object that) { public boolean equals(Object that) {
return that instanceof ZkNodeProps && ((ZkNodeProps)that).propMap.equals(this.propMap); return that instanceof ZkNodeProps && ((ZkNodeProps)that).propMap.equals(this.propMap);
} }
// @Override
// public int hashCode() { @Override
// throw new UnsupportedOperationException("TODO unimplemented ZkNodeProps.hashCode"); public int hashCode() {
// } return Objects.hashCode(propMap);
}
} }

View File

@ -30,6 +30,7 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Objects;
import org.apache.solr.common.NavigableObject; import org.apache.solr.common.NavigableObject;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
@ -40,7 +41,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableSet; import static java.util.Collections.unmodifiableSet;
@SuppressWarnings({"overrides"})
public class ValidatingJsonMap implements Map<String, Object>, NavigableObject { public class ValidatingJsonMap implements Map<String, Object>, NavigableObject {
private static final String INCLUDE = "#include"; private static final String INCLUDE = "#include";
@ -348,10 +348,10 @@ public class ValidatingJsonMap implements Map<String, Object>, NavigableObject {
return that instanceof Map && this.delegate.equals(that); return that instanceof Map && this.delegate.equals(that);
} }
// @Override @Override
// public int hashCode() { public int hashCode() {
// throw new UnsupportedOperationException("TODO unimplemented ValidatingJsonMap.hashCode"); return Objects.hash(delegate);
// } }
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
public static final ValidatingJsonMap EMPTY = new ValidatingJsonMap(Collections.EMPTY_MAP); public static final ValidatingJsonMap EMPTY = new ValidatingJsonMap(Collections.EMPTY_MAP);