Skip to content

Commit

Permalink
SOLR-14536: Fix or suppress warnings in apache/solr/common
Browse files Browse the repository at this point in the history
  • Loading branch information
Erick Erickson authored and Erick Erickson committed Jun 6, 2020
1 parent c8e4334 commit 6d5b1ae
Show file tree
Hide file tree
Showing 24 changed files with 137 additions and 50 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ Other Changes

* SOLR-14538: Fix or suppress remaining warnings in apache/solr/handler (Erick Erickson)

* SOLR-14536: Fix or suppress warnings in apache/solr/common (Erick Erickson)

================== 8.5.2 ==================

Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public CollectionAdminRequest(String path, CollectionAction action) {
}

@Override
@SuppressWarnings({"rawtypes"})
public SolrRequest getV2Request() {
return usev2 ?
V1toV2ApiMapper.convert(this).useBinary(useBinaryV2).build() :
Expand Down Expand Up @@ -294,6 +295,7 @@ public SolrParams getParams() {
}
}

@SuppressWarnings({"rawtypes"})
protected abstract static class ShardSpecificAdminRequest extends CollectionAdminRequest {

protected String collection;
Expand Down Expand Up @@ -1535,6 +1537,7 @@ private ForceLeader(String collection, String shard) {
public static class RequestStatusResponse extends CollectionAdminResponse {

public RequestStatusState getRequestStatus() {
@SuppressWarnings({"rawtypes"})
NamedList innerResponse = (NamedList) getResponse().get("status");
return RequestStatusState.fromKey((String) innerResponse.get("state"));
}
Expand Down Expand Up @@ -2682,6 +2685,7 @@ protected CollectionAdminResponse createResponse(SolrClient client) {
/**
* Returns a SolrRequest to get a list of collections in the cluster
*/
@SuppressWarnings({"unchecked"})
public static java.util.List<String> listCollections(SolrClient client) throws IOException, SolrServerException {
CollectionAdminResponse resp = new List().process(client);
return (java.util.List<String>) resp.getResponse().get("collections");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ synchronized void setPath() {
public V2Request.Builder convert(SolrParams paramsV1) {
String[] list = new String[template.variables.size()];
MapWriter data = serializeToV2Format(paramsV1, list);
@SuppressWarnings({"rawtypes"})
Map o = data.toMap(new LinkedHashMap<>());
return new V2Request.Builder(template.apply(s -> {
int idx = template.variables.indexOf(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ default ItemWriter add(boolean v) throws IOException {
return this;
}
}
@SuppressWarnings({"unchecked", "rawtypes"})
default List toList( List l) {
try {
writeIter(new ItemWriter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public interface MapSerializable {
* Do not keep a reference to the passed map and reuse it.
* it may be reused by the framework
*/
@SuppressWarnings({"rawtypes"})
Map toMap(Map<String, Object> map);
}
1 change: 1 addition & 0 deletions solr/solrj/src/java/org/apache/solr/common/MapWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ default String jsonStr(){
}

@Override
@SuppressWarnings({"unchecked", "rawtypes"})
default Map toMap(Map<String, Object> map) {
try {
writeMap(new EntryWriter() {
Expand Down
7 changes: 6 additions & 1 deletion solr/solrj/src/java/org/apache/solr/common/MapWriterMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,36 @@
import java.util.Map;

public class MapWriterMap implements MapWriter {
@SuppressWarnings({"rawtypes"})
private final Map delegate;

public MapWriterMap(Map delegate) {
public MapWriterMap(@SuppressWarnings({"rawtypes"})Map delegate) {
this.delegate = delegate;
}

@Override
@SuppressWarnings({"unchecked"})
public void writeMap(EntryWriter ew) throws IOException {
delegate.forEach(ew.getBiConsumer());
}

@Override
@SuppressWarnings({"unchecked"})
public Object _get(String path, Object def) {
if (path.indexOf('/') == -1) return delegate.getOrDefault(path, def);
return MapWriter.super._get(path, def);
}

@Override
@SuppressWarnings({"unchecked"})
public Object _get(List<String> path, Object def) {
if (path.size() == 1) return delegate.getOrDefault(path.get(0), def);
return MapWriter.super._get(path, def);
}


@Override
@SuppressWarnings({"rawtypes"})
public Map toMap(Map<String, Object> map) {
return delegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ default String _getStr(String path, String def) {
/**Iterate through the entries of a navigable Object at a certain path
* @param path the json path
*/
default void _forEachEntry(String path, BiConsumer fun) {
default void _forEachEntry(String path, @SuppressWarnings({"rawtypes"})BiConsumer fun) {
Utils.forEachMapEntry(this, path, fun);
}

/**Iterate through the entries of a navigable Object at a certain path
* @param path the json path
*/
default void _forEachEntry(List<String> path, BiConsumer fun) {
default void _forEachEntry(List<String> path, @SuppressWarnings({"rawtypes"})BiConsumer fun) {
Utils.forEachMapEntry(this, path, fun);
}

/**Iterate through each entry in this object
*/
default void _forEachEntry(BiConsumer fun) {
default void _forEachEntry(@SuppressWarnings({"rawtypes"})BiConsumer fun) {
Utils.forEachMapEntry(this, fun);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public abstract class SolrDocumentBase<T, K> implements Map<String, T>, Serializ
/**
* Get a collection of values for a given field name
*/
@SuppressWarnings({"rawtypes"})
public abstract Collection getFieldValues(String name);

public abstract void addChildDocument(K child);
Expand Down
14 changes: 7 additions & 7 deletions solr/solrj/src/java/org/apache/solr/common/SolrException.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SolrException extends RuntimeException {

public static final String ROOT_ERROR_CLASS = "root-error-class";
public static final String ERROR_CLASS = "error-class";
final private Map mdcContext;
final private Map<String, String> mdcContext;

/**
* This list of valid HTTP Status error codes that Solr may return in
Expand Down Expand Up @@ -160,13 +160,12 @@ public static void log(Logger log, String msg, Throwable e) {
}

public static void log(Logger log, String msg) {
String stackTrace = msg;
String ignore = doIgnore(null, stackTrace);
String ignore = doIgnore(null, msg);
if (ignore != null) {
log.info(ignore);
return;
}
log.error(stackTrace);
log.error(msg);
}

// public String toString() { return toStr(this); } // oops, inf loop
Expand Down Expand Up @@ -225,8 +224,9 @@ public static Throwable getRootCause(Throwable t) {
return t;
}

@SuppressWarnings({"unchecked"})
public void logInfoWithMdc(Logger logger, String msg) {
Map previousMdcContext = MDC.getCopyOfContextMap();
Map<String, String> previousMdcContext = MDC.getCopyOfContextMap();
MDC.setContextMap(mdcContext);
try {
logger.info(msg);
Expand All @@ -236,7 +236,7 @@ public void logInfoWithMdc(Logger logger, String msg) {
}

public void logDebugWithMdc(Logger logger, String msg) {
Map previousMdcContext = MDC.getCopyOfContextMap();
Map<String, String> previousMdcContext = MDC.getCopyOfContextMap();
MDC.setContextMap(mdcContext);
try {
logger.debug(msg);
Expand All @@ -246,7 +246,7 @@ public void logDebugWithMdc(Logger logger, String msg) {
}

public void logWarnWithMdc(Logger logger, String msg) {
Map previousMdcContext = MDC.getCopyOfContextMap();
Map<String, String> previousMdcContext = MDC.getCopyOfContextMap();
MDC.setContextMap(mdcContext);
try {
logger.warn(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public Map<String, Object> getClusterProperties() throws IOException {
public void setClusterProperties(Map<String, Object> properties) throws IOException, KeeperException, InterruptedException {
client.atomicUpdate(ZkStateReader.CLUSTER_PROPS, zkData -> {
if (zkData == null) return Utils.toJSON(convertCollectionDefaultsToNestedFormat(properties));
@SuppressWarnings({"unchecked"})
Map<String, Object> zkJson = (Map<String, Object>) Utils.fromJSON(zkData);
zkJson = convertCollectionDefaultsToNestedFormat(zkJson);
boolean modified = Utils.mergeJson(zkJson, convertCollectionDefaultsToNestedFormat(properties));
Expand All @@ -122,6 +123,7 @@ public void setClusterProperties(Map<String, Object> properties) throws IOExcept
* @param properties the properties to be converted
* @return the converted map
*/
@SuppressWarnings({"unchecked"})
static Map<String, Object> convertCollectionDefaultsToNestedFormat(Map<String, Object> properties) {
if (properties.containsKey(COLLECTION_DEF)) {
Map<String, Object> values = (Map<String, Object>) properties.remove(COLLECTION_DEF);
Expand Down Expand Up @@ -161,6 +163,7 @@ public void setClusterProperty(String propertyName, Object propertyValue) throws
Stat s = new Stat();
try {
if (client.exists(ZkStateReader.CLUSTER_PROPS, true)) {
@SuppressWarnings({"rawtypes"})
Map properties = (Map) Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, s, true));
if (propertyValue == null) {
//Don't update ZK unless absolutely necessary.
Expand All @@ -176,6 +179,7 @@ public void setClusterProperty(String propertyName, Object propertyValue) throws
}
}
} else {
@SuppressWarnings({"rawtypes"})
Map properties = new LinkedHashMap();
properties.put(propertyName, propertyValue);
client.create(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), CreateMode.PERSISTENT, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.zookeeper.ZooKeeper;

// we use this class to expose nasty stuff for tests
@SuppressWarnings({"try"})
public class SolrZooKeeper extends ZooKeeper {
final Set<Thread> spawnedThreads = new CopyOnWriteArraySet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public AutoScalingConfig getAutoScalingConfig() throws KeeperException, Interrup
* @return current configuration from <code>autoscaling.json</code>. NOTE:
* this data is retrieved from ZK on each call.
*/
@SuppressWarnings({"unchecked"})
public AutoScalingConfig getAutoScalingConfig(Watcher watcher) throws KeeperException, InterruptedException {
Stat stat = new Stat();

Expand Down Expand Up @@ -487,6 +488,7 @@ public Integer compareStateVersions(String coll, int version) {
return collection.getZNodeVersion();
}

@SuppressWarnings({"unchecked"})
public synchronized void createClusterStateWatchersAndUpdate() throws KeeperException,
InterruptedException {
// We need to fetch the current cluster state and the set of live nodes
Expand Down Expand Up @@ -1085,6 +1087,7 @@ public <T> T getClusterProperty(String key, T defaultValue) {
* @param defaultValue a default value to use if no such property exists
* @return the cluster property, or a default if the property is not set
*/
@SuppressWarnings({"unchecked"})
public <T> T getClusterProperty(List<String> keyPath, T defaultValue) {
T value = (T) Utils.getObjectByPath(clusterProperties, false, keyPath);
if (value == null)
Expand Down Expand Up @@ -1256,6 +1259,7 @@ private VersionedCollectionProps fetchCollectionProperties(String collection, Wa
* Returns the content of /security.json from ZooKeeper as a Map
* If the files doesn't exist, it returns null.
*/
@SuppressWarnings({"unchecked"})
public ConfigData getSecurityProps(boolean getFresh) {
if (!getFresh) {
if (securityData == null) return new ConfigData(EMPTY_MAP, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public static SolrParams wrapAppended(SolrParams params, SolrParams defaults) {

/** Create a Map&lt;String,String&gt; from a NamedList given no keys are repeated */
@Deprecated // Doesn't belong here (no SolrParams). Just remove.
public static Map<String,String> toMap(NamedList params) {
public static Map<String,String> toMap(@SuppressWarnings({"rawtypes"})NamedList params) {
HashMap<String,String> map = new HashMap<>();
for (int i=0; i<params.size(); i++) {
map.put(params.getName(i), params.getVal(i).toString());
Expand All @@ -468,14 +468,15 @@ public static Map<String,String> toMap(NamedList params) {

/** Create a Map&lt;String,String[]&gt; from a NamedList */
@Deprecated // Doesn't belong here (no SolrParams). Just remove.
public static Map<String,String[]> toMultiMap(NamedList params) {
public static Map<String,String[]> toMultiMap(@SuppressWarnings({"rawtypes"})NamedList params) {
HashMap<String,String[]> map = new HashMap<>();
for (int i=0; i<params.size(); i++) {
String name = params.getName(i);
Object val = params.getVal(i);
if (val instanceof String[]) {
MultiMapSolrParams.addParam(name, (String[]) val, map);
} else if (val instanceof List) {
@SuppressWarnings({"rawtypes"})
List l = (List) val;
String[] s = new String[l.size()];
for (int j = 0; j < l.size(); j++) {
Expand All @@ -494,7 +495,7 @@ public static Map<String,String[]> toMultiMap(NamedList params) {
* @deprecated Use {@link NamedList#toSolrParams()}.
*/
@Deprecated //move to NamedList to allow easier flow
public static SolrParams toSolrParams(NamedList params) {
public static SolrParams toSolrParams(@SuppressWarnings({"rawtypes"})NamedList params) {
return params.toSolrParams();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public ByteArrayUtf8CharSequence deepCopy() {
return new ByteArrayUtf8CharSequence(bytes, 0, length, utf16, hashCode);
}

@SuppressWarnings({"unchecked", "rawtypes"})
public static Map.Entry convertCharSeq(Map.Entry e) {
if (e.getKey() instanceof Utf8CharSequence || e.getValue() instanceof Utf8CharSequence) {
return new AbstractMap.SimpleEntry(convertCharSeq(e.getKey()), convertCharSeq(e.getValue()));
Expand All @@ -188,6 +189,7 @@ public static Map.Entry convertCharSeq(Map.Entry e) {

}

@SuppressWarnings({"unchecked", "rawtypes"})
public static Collection convertCharSeq(Collection vals) {
if (vals == null) return vals;
boolean needsCopy = false;
Expand All @@ -200,9 +202,9 @@ public static Collection convertCharSeq(Collection vals) {
if (needsCopy) {
Collection copy = null;
if (vals instanceof Set){
copy = new HashSet(vals.size());
copy = new HashSet<>(vals.size());
} else {
copy = new ArrayList(vals.size());
copy = new ArrayList<>(vals.size());
}
for (Object o : vals) copy.add(convertCharSeq(o));
return copy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,11 @@ public void stream(EntryImpl entry, StreamCodec codec) throws IOException {
}

@Override
@SuppressWarnings({"unchecked"})
public Object readObject(StreamCodec codec, EntryImpl entry) throws IOException {
SolrDocumentList solrDocs = new SolrDocumentList();
if(entry.metadata != null){
@SuppressWarnings({"rawtypes"})
List list = (List) entry.metadata;
solrDocs.setNumFound((Long) list.get(0));
solrDocs.setStart((Long) list.get(1));
Expand Down Expand Up @@ -779,6 +781,7 @@ public void skip(EntryImpl entry, StreamCodec codec) throws IOException {
}
}

@SuppressWarnings({"unchecked", "rawtypes"})
private static void addObj(DataEntry e) {
if (e.type().isContainer) {
Object ctx = e.type() == DataEntry.Type.KEYVAL_ITER ?
Expand Down
Loading

0 comments on commit 6d5b1ae

Please sign in to comment.