Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Fix bad unchecked casts for generic types (#87)

Mike Drobda384087380a
diff --git a/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java b/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java
index 66991a4eb3c..75793a284f8 100644
--- a/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java
+++ b/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java
@@ -220,10 +220,10 @@ public class ConfigOverlay implements MapSerializable {
}
@SuppressWarnings({"unchecked"})
- public Map<String, String> getEditableSubProperties(String xpath) {
+ public Map<String, Object> getEditableSubProperties(String xpath) {
Object o = Utils.getObjectByPath(props, false, StrUtils.splitSmart(xpath, '/'));
if (o instanceof Map) {
- return (Map<String,String>) o;
+ return (Map<String, Object>) o;
} else {
return null;
}
diff --git a/solr/core/src/java/org/apache/solr/search/CacheConfig.java b/solr/core/src/java/org/apache/solr/search/CacheConfig.java
index 1520f80620f..af1b87f3568 100644
--- a/solr/core/src/java/org/apache/solr/search/CacheConfig.java
+++ b/solr/core/src/java/org/apache/solr/search/CacheConfig.java
@@ -104,14 +104,13 @@ public class CacheConfig implements MapSerializable{
}
- @SuppressWarnings({"unchecked"})
public static CacheConfig getConfig(SolrConfig solrConfig, String xpath) {
Node node = solrConfig.getNode(xpath, false);
if(node == null || !"true".equals(DOMUtil.getAttrOrDefault(node, "enabled", "true"))) {
- Map<String, String> m = solrConfig.getOverlay().getEditableSubProperties(xpath);
+ Map<?, ?> m = solrConfig.getOverlay().getEditableSubProperties(xpath);
if(m==null) return null;
List<String> parts = StrUtils.splitSmart(xpath, '/');
- return getConfig(solrConfig,parts.get(parts.size()-1) , Collections.EMPTY_MAP,xpath);
+ return getConfig(solrConfig,parts.get(parts.size()-1), Collections.emptyMap(), xpath);
}
return getConfig(solrConfig, node.getNodeName(),DOMUtil.toMap(node.getAttributes()), xpath);
}
@@ -129,11 +128,11 @@ public class CacheConfig implements MapSerializable{
attrs = attrsCopy;
config.args = attrs;
- Map<String, String> map = xpath == null ? null : solrConfig.getOverlay().getEditableSubProperties(xpath);
+ Map<String, Object> map = xpath == null ? null : solrConfig.getOverlay().getEditableSubProperties(xpath);
if(map != null){
HashMap<String, String> mapCopy = new HashMap<>(config.args);
- for (Map.Entry<String, String> e : map.entrySet()) {
- mapCopy.put(e.getKey(),String.valueOf(e.getValue()));
+ for (Map.Entry<String, Object> e : map.entrySet()) {
+ mapCopy.put(e.getKey(), String.valueOf(e.getValue()));
}
config.args = mapCopy;
}
diff --git a/solr/core/src/test/org/apache/solr/core/TestConfigOverlay.java b/solr/core/src/test/org/apache/solr/core/TestConfigOverlay.java
index 1c39fa98683..07708c66d75 100644
--- a/solr/core/src/test/org/apache/solr/core/TestConfigOverlay.java
+++ b/solr/core/src/test/org/apache/solr/core/TestConfigOverlay.java
@@ -69,7 +69,7 @@ public class TestConfigOverlay extends SolrTestCase {
ConfigOverlay overlay = new ConfigOverlay(Collections.EMPTY_MAP,0);
overlay = overlay.setProperty("query.filterCache.initialSize",100);
assertEquals(100, overlay.getXPathProperty("query/filterCache/@initialSize"));
- Map<String, String> map = overlay.getEditableSubProperties("query/filterCache");
+ Map<String, Object> map = overlay.getEditableSubProperties("query/filterCache");
assertNotNull(map);
assertEquals(1,map.size());
assertEquals(100,map.get("initialSize"));
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/PropertiesRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/PropertiesRequestHandlerTest.java
index bbbde8a6673..64da006c442 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/PropertiesRequestHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/PropertiesRequestHandlerTest.java
@@ -43,7 +43,7 @@ public class PropertiesRequestHandlerTest extends SolrTestCaseJ4 {
RedactionUtils.setRedactSystemProperty(true);
for(String propName: new String[]{"some.password", "javax.net.ssl.trustStorePassword"}){
System.setProperty(propName, PASSWORD);
- NamedList<NamedList<NamedList<Object>>> properties = readProperties();
+ NamedList<Object> properties = readProperties();
assertEquals("Failed to redact "+propName, REDACT_STRING, properties.get(propName));
}
@@ -54,21 +54,21 @@ public class PropertiesRequestHandlerTest extends SolrTestCaseJ4 {
RedactionUtils.setRedactSystemProperty(false);
for(String propName: new String[]{"some.password", "javax.net.ssl.trustStorePassword"}){
System.setProperty(propName, PASSWORD);
- NamedList<NamedList<NamedList<Object>>> properties = readProperties();
+ NamedList<Object> properties = readProperties();
assertEquals("Failed to *not* redact "+propName, PASSWORD, properties.get(propName));
}
}
@SuppressWarnings({"unchecked"})
- private NamedList<NamedList<NamedList<Object>>> readProperties() throws Exception {
+ private NamedList<Object> readProperties() throws Exception {
String xml = h.query(req(
CommonParams.QT, "/admin/properties",
CommonParams.WT, "xml"
));
XMLResponseParser parser = new XMLResponseParser();
- return (NamedList<NamedList<NamedList<Object>>>)
+ return (NamedList<Object>)
parser.processResponse(new StringReader(xml)).get("system.properties");
}
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java
index a8e53cd2b66..2ae9d7a77c3 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java
@@ -2642,21 +2642,19 @@ public void testParallelRankStream() throws Exception {
}
- protected boolean assertOrder(List<Tuple> tuples, int... ids) throws Exception {
+ protected boolean assertOrder(List<Tuple> tuples, int... ids) {
int i = 0;
for(int val : ids) {
Tuple t = tuples.get(i);
String tip = (String)t.get("id");
String valStr = Integer.toString(val);
- if(!tip.equals(valStr)) {
- assertEquals("Found value:"+tip+" expecting:"+valStr, val, tip);
- }
+ assertEquals(valStr, tip);
++i;
}
return true;
}
- protected boolean assertGroupOrder(Tuple tuple, int... ids) throws Exception {
+ protected boolean assertGroupOrder(Tuple tuple, int... ids) {
@SuppressWarnings({"rawtypes"})
List group = (List)tuple.get("tuples");
int i=0;
@@ -2664,9 +2662,7 @@ public void testParallelRankStream() throws Exception {
@SuppressWarnings({"rawtypes"})
Map t = (Map)group.get(i);
Long tip = (Long)t.get("id");
- if(tip.intValue() != val) {
- throw new Exception("Found value:"+tip.intValue()+" expecting:"+val);
- }
+ assertEquals(val, tip.intValue());
++i;
}
return true;