From 716d43eca936e3ea5325a0ee0cceb087a4ff32e5 Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Wed, 15 Mar 2017 06:03:54 -0400 Subject: [PATCH] LUCENE-7742: fix places where we were unboxing and then re-boxing according to FindBugs --- lucene/CHANGES.txt | 3 +++ .../org/apache/lucene/document/LatLonDocValuesField.java | 2 +- .../org/apache/lucene/spatial3d/Geo3DDocValuesField.java | 2 +- .../processor/TikaLanguageIdentifierUpdateProcessor.java | 5 +++-- solr/core/src/java/org/apache/solr/core/RequestParams.java | 2 +- .../src/java/org/apache/solr/handler/sql/SolrEnumerator.java | 4 ++-- .../src/java/org/apache/solr/schema/NumericFieldType.java | 4 ++-- solr/core/src/java/org/apache/solr/search/Grouping.java | 2 +- .../src/java/org/apache/solr/search/SolrIndexSearcher.java | 2 +- .../responseprocessor/SearchGroupShardResponseProcessor.java | 2 +- .../org/apache/solr/security/AutorizationEditOperation.java | 2 +- .../org/apache/solr/search/TestCollapseQParserPlugin.java | 2 +- .../org/apache/solr/update/TestInPlaceUpdatesDistrib.java | 2 +- .../apache/solr/client/solrj/io/eval/EqualsEvaluator.java | 2 +- .../src/java/org/apache/solr/common/cloud/DocCollection.java | 2 +- .../test/org/apache/solr/common/params/SolrParamTest.java | 4 ++-- 16 files changed, 23 insertions(+), 19 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index e14ab53e41d..62f4763325e 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -256,6 +256,9 @@ Optimizations * LUCENE-7699: Query parsers now use span queries to produce more efficient phrase queries for multi-token synonyms. (Matt Webber via Jim Ferenczi) +* LUCENE-7742: Fix places where we were unboxing and then re-boxing + according to FindBugs (Daniel Jelinski via Mike McCandless) + Build * LUCENE-7653: Update randomizedtesting to version 2.5.0. (Dawid Weiss) diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonDocValuesField.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonDocValuesField.java index 08a7da78012..10e90b4838b 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonDocValuesField.java +++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonDocValuesField.java @@ -106,7 +106,7 @@ public class LatLonDocValuesField extends Field { result.append(name); result.append(':'); - long currentValue = Long.valueOf((Long)fieldsData); + long currentValue = (Long)fieldsData; result.append(decodeLatitude((int)(currentValue >> 32))); result.append(','); result.append(decodeLongitude((int)(currentValue & 0xFFFFFFFF))); diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DDocValuesField.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DDocValuesField.java index 551fa5a8e4f..dc9df35576b 100644 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DDocValuesField.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DDocValuesField.java @@ -305,7 +305,7 @@ public class Geo3DDocValuesField extends Field { result.append(name); result.append(':'); - long currentValue = Long.valueOf((Long)fieldsData); + long currentValue = (Long)fieldsData; result.append(decodeXValue(currentValue)); result.append(','); diff --git a/solr/contrib/langid/src/java/org/apache/solr/update/processor/TikaLanguageIdentifierUpdateProcessor.java b/solr/contrib/langid/src/java/org/apache/solr/update/processor/TikaLanguageIdentifierUpdateProcessor.java index 3d3fa41be00..836a3bf6795 100644 --- a/solr/contrib/langid/src/java/org/apache/solr/update/processor/TikaLanguageIdentifierUpdateProcessor.java +++ b/solr/contrib/langid/src/java/org/apache/solr/update/processor/TikaLanguageIdentifierUpdateProcessor.java @@ -56,8 +56,9 @@ public class TikaLanguageIdentifierUpdateProcessor extends LanguageIdentifierUpd // FIXME: Hack - we get the distance from toString and calculate our own certainty score Double distance = Double.parseDouble(tikaSimilarityPattern.matcher(identifier.toString()).replaceFirst("$1")); // This formula gives: 0.02 => 0.8, 0.1 => 0.5 which is a better sweetspot than isReasonablyCertain() - Double certainty = 1 - (5 * distance); - certainty = (certainty < 0) ? 0 : certainty; + Double certainty = 1 - (5 * distance); + if (certainty < 0) + certainty = 0d; DetectedLanguage language = new DetectedLanguage(identifier.getLanguage(), certainty); languages.add(language); log.debug("Language detected as "+language+" with a certainty of "+language.getCertainty()+" (Tika distance="+identifier.toString()+")"); diff --git a/solr/core/src/java/org/apache/solr/core/RequestParams.java b/solr/core/src/java/org/apache/solr/core/RequestParams.java index ff0d36c5685..fbb2555e322 100644 --- a/solr/core/src/java/org/apache/solr/core/RequestParams.java +++ b/solr/core/src/java/org/apache/solr/core/RequestParams.java @@ -222,7 +222,7 @@ public class RequestParams implements MapSerializable { } public Long getVersion() { - return meta == null ? 0l : (Long) meta.get("v"); + return meta == null ? Long.valueOf(0l) : (Long) meta.get("v"); } @Override diff --git a/solr/core/src/java/org/apache/solr/handler/sql/SolrEnumerator.java b/solr/core/src/java/org/apache/solr/handler/sql/SolrEnumerator.java index 6f9dddfbf2f..be6046c98fe 100644 --- a/solr/core/src/java/org/apache/solr/handler/sql/SolrEnumerator.java +++ b/solr/core/src/java/org/apache/solr/handler/sql/SolrEnumerator.java @@ -103,10 +103,10 @@ class SolrEnumerator implements Enumerator { private Object getRealVal(Object val) { // Check if Double is really a Long if(val instanceof Double) { - Double doubleVal = (double) val; + double doubleVal = (double) val; //make sure that double has no decimals and fits within Long if(doubleVal % 1 == 0 && doubleVal >= Long.MIN_VALUE && doubleVal <= Long.MAX_VALUE) { - return doubleVal.longValue(); + return (long)doubleVal; } return doubleVal; } diff --git a/solr/core/src/java/org/apache/solr/schema/NumericFieldType.java b/solr/core/src/java/org/apache/solr/schema/NumericFieldType.java index 5801766f7a9..6cda9ca6438 100644 --- a/solr/core/src/java/org/apache/solr/schema/NumericFieldType.java +++ b/solr/core/src/java/org/apache/solr/schema/NumericFieldType.java @@ -114,10 +114,10 @@ public abstract class NumericFieldType extends PrimitiveFieldType { if ((minVal == null || minVal.doubleValue() < 0d || minBits == minusZeroBits) && (maxVal != null && (maxVal.doubleValue() < 0d || maxBits == minusZeroBits))) { query = numericDocValuesRangeQuery - (fieldName, maxBits, (min == null ? negativeInfinityBits : minBits), maxInclusive, minInclusive, false); + (fieldName, maxBits, (min == null ? Long.valueOf(negativeInfinityBits) : minBits), maxInclusive, minInclusive, false); } else { // If both max and min are positive, then issue range query query = numericDocValuesRangeQuery - (fieldName, minBits, (max == null ? positiveInfinityBits : maxBits), minInclusive, maxInclusive, false); + (fieldName, minBits, (max == null ? Long.valueOf(positiveInfinityBits) : maxBits), minInclusive, maxInclusive, false); } } return query; diff --git a/solr/core/src/java/org/apache/solr/search/Grouping.java b/solr/core/src/java/org/apache/solr/search/Grouping.java index 327e5bb6e44..302383a00a7 100644 --- a/solr/core/src/java/org/apache/solr/search/Grouping.java +++ b/solr/core/src/java/org/apache/solr/search/Grouping.java @@ -601,7 +601,7 @@ public class Grouping { groupResult.add("matches", matches); if (totalCount == TotalCount.grouped) { Integer totalNrOfGroups = getNumberOfGroups(); - groupResult.add("ngroups", totalNrOfGroups == null ? 0 : totalNrOfGroups); + groupResult.add("ngroups", totalNrOfGroups == null ? Integer.valueOf(0) : totalNrOfGroups); } maxMatches = Math.max(maxMatches, matches); return groupResult; diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java index a7ee433f4d1..19e47d0a022 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -847,7 +847,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI newVal = val.intValue(); break; case LONG: - newVal = val.longValue(); + newVal = val; break; case FLOAT: newVal = Float.intBitsToFloat(val.intValue()); diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java index 1645b1edd49..a12cad1912c 100644 --- a/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java +++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java @@ -119,7 +119,7 @@ public class SearchGroupShardResponseProcessor implements ShardResponseProcessor if (groupCount != null) { Integer existingGroupCount = rb.mergedGroupCounts.get(field); // Assuming groups don't cross shard boundary... - rb.mergedGroupCounts.put(field, existingGroupCount != null ? existingGroupCount + groupCount : groupCount); + rb.mergedGroupCounts.put(field, existingGroupCount != null ? Integer.valueOf(existingGroupCount + groupCount) : groupCount); } final Collection> searchGroups = firstPhaseCommandResult.getSearchGroups(); diff --git a/solr/core/src/java/org/apache/solr/security/AutorizationEditOperation.java b/solr/core/src/java/org/apache/solr/security/AutorizationEditOperation.java index 88c7987ef48..6a5230cd9c0 100644 --- a/solr/core/src/java/org/apache/solr/security/AutorizationEditOperation.java +++ b/solr/core/src/java/org/apache/solr/security/AutorizationEditOperation.java @@ -83,7 +83,7 @@ enum AutorizationEditOperation { boolean indexSatisfied = index == null; for (int i = 0; i < permissions.size(); i++) { Map perm = permissions.get(i); - Integer thisIdx = (int) perm.get("index"); + Integer thisIdx = (Integer) perm.get("index"); if (thisIdx.equals(beforeIdx)) { beforeSatisfied = true; permissionsCopy.add(dataMap); diff --git a/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java b/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java index 2fca452a520..ea4114a08b0 100644 --- a/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java +++ b/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java @@ -336,7 +336,7 @@ public class TestCollapseQParserPlugin extends SolrTestCaseJ4 { if(boostedResults.size() == controlResults.size()) { for(int i=0; i { this.replicationFactor = (Integer) verifyProp(props, REPLICATION_FACTOR); this.maxShardsPerNode = (Integer) verifyProp(props, MAX_SHARDS_PER_NODE); Boolean autoAddReplicas = (Boolean) verifyProp(props, AUTO_ADD_REPLICAS); - this.autoAddReplicas = autoAddReplicas == null ? false : autoAddReplicas; + this.autoAddReplicas = autoAddReplicas == null ? Boolean.FALSE : autoAddReplicas; Integer realtimeReplicas = (Integer) verifyProp(props, REALTIME_REPLICAS); this.realtimeReplicas = realtimeReplicas == null ? -1 : realtimeReplicas; if (this.realtimeReplicas != -1 && this.realtimeReplicas != 1) { diff --git a/solr/solrj/src/test/org/apache/solr/common/params/SolrParamTest.java b/solr/solrj/src/test/org/apache/solr/common/params/SolrParamTest.java index 48237c5250b..80f9036433b 100644 --- a/solr/solrj/src/test/org/apache/solr/common/params/SolrParamTest.java +++ b/solr/solrj/src/test/org/apache/solr/common/params/SolrParamTest.java @@ -213,10 +213,10 @@ public class SolrParamTest extends LuceneTestCase { // Get things with defaults assertEquals( pstr , params.get( "xxx", pstr ) ); - assertEquals( pbool.booleanValue() , params.getBool( "xxx", pbool ) ); + assertEquals( pbool , params.getBool( "xxx", pbool ) ); assertEquals( pint.intValue() , params.getInt( "xxx", pint ) ); assertEquals( pfloat.floatValue() , params.getFloat( "xxx", pfloat ), 0.1); - assertEquals( pbool.booleanValue() , params.getFieldBool( "xxx", "bool", pbool ) ); + assertEquals( pbool , params.getFieldBool( "xxx", "bool", pbool ) ); assertEquals( pint.intValue() , params.getFieldInt( "xxx", "int", pint ) ); assertEquals( pfloat.floatValue() , params.getFieldFloat("xxx", "float", pfloat ), 0.1); assertEquals( pstr , params.getFieldParam("xxx", "str", pstr ) );