Skip to content

Commit 2dfa934

Browse files
authored
Merge pull request #472 from apache/fix_spot_bugs_issues2
This fixes the remaining spotBugs issues.
2 parents b5ed0b5 + 8484dad commit 2dfa934

18 files changed

Lines changed: 161 additions & 51 deletions

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,9 @@ In Eclipse, open the project *Properties / Java Build Path / Module Dependencies
150150

151151
**NOTE:** If you execute *Maven/Update Project...* from Eclipse with the option *Update project configuration from pom.xml* checked, all of the above will be erased, and you will have to redo it.
152152

153+
## Known Issues
154+
155+
#### SpotBugs
156+
157+
* Make sure you configure SpotBugs with the /tools/FindBugsExcludeFilter.xml file. Otherwise, you will get a lot of false positive or low risk issues that we have examined and exliminated with this exclusion file.
158+

src/main/java/org/apache/datasketches/common/Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ public static int numDigits(int n) {
767767
* @return the given number to a string prepended with spaces
768768
*/
769769
public static String intToFixedLengthString(final int number, final int length) {
770-
final String num = Integer.valueOf(number).toString();
770+
final String num = Integer.toString(number);
771771
return characterPad(num, length, ' ', false);
772772
}
773773

src/main/java/org/apache/datasketches/kll/KllItemsSketch.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ public double[] getRanks(final T[] quantiles, final QuantileSearchCriteria searc
240240
}
241241

242242
@Override
243-
public KllItemsSketchSortedView<T> getSortedView() {
243+
public final KllItemsSketchSortedView<T> getSortedView() {
244244
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
245-
refreshSortedView();
246-
return kllItemsSV;
245+
return refreshSortedView();
246+
//return kllItemsSV; //SpotBugs EI_EXPOSE_REP, Suppressed by FindBugsExcludeFilter
247247
}
248248

249249
@Override
@@ -301,8 +301,11 @@ MemoryRequestServer getMemoryRequestServer() {
301301
@Override
302302
abstract int getMinMaxSizeBytes();
303303

304-
private final void refreshSortedView() {
305-
kllItemsSV = (kllItemsSV == null) ? new KllItemsSketchSortedView<T>(this) : kllItemsSV;
304+
private final KllItemsSketchSortedView<T> refreshSortedView() {
305+
final KllItemsSketchSortedView<T> sv = (kllItemsSV == null)
306+
? kllItemsSV = new KllItemsSketchSortedView<T>(this)
307+
: kllItemsSV;
308+
return sv;
306309
}
307310

308311
abstract T[] getRetainedItemsArray();

src/main/java/org/apache/datasketches/kll/KllItemsSketchSortedView.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ public class KllItemsSketchSortedView<T> implements GenericSortedView<T> {
5858
* @param totalN the total number of items presented to the sketch.
5959
* @param minItem used to extract the type of T
6060
* @param comparator the Comparator for type T
61-
*
6261
*/
63-
public KllItemsSketchSortedView(
62+
KllItemsSketchSortedView(
6463
final T[] quantiles,
6564
final long[] cumWeights,
6665
final long totalN,
@@ -77,7 +76,7 @@ public KllItemsSketchSortedView(
7776
* Constructs this Sorted View given the sketch
7877
* @param sk the given KllItemsSketch.
7978
*/
80-
public KllItemsSketchSortedView(final KllItemsSketch<T> sk) {
79+
KllItemsSketchSortedView(final KllItemsSketch<T> sk) {
8180
this.totalN = sk.getN();
8281
this.minItem = sk.getMinItem();
8382
final Object[] srcQuantiles = sk.getTotalItemsArray();

src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ public void putMemory(final WritableMemory dstMem, final ArrayOfItemsSerDe<T> se
581581

582582
@Override
583583
public GenericSortedView<T> getSortedView() {
584-
return new ItemsSketchSortedView<T>(this);
584+
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
585+
return refreshSortedView();
585586
}
586587

587588
@Override
@@ -605,8 +606,11 @@ public void update(final T item) {
605606

606607
// Restricted
607608

608-
private final void refreshSortedView() {
609-
classicQisSV = (classicQisSV == null) ? new ItemsSketchSortedView<T>(this) : classicQisSV;
609+
private final ItemsSketchSortedView<T> refreshSortedView() {
610+
final ItemsSketchSortedView<T> sv = (classicQisSV == null)
611+
? classicQisSV = new ItemsSketchSortedView<T>(this)
612+
: classicQisSV;
613+
return sv;
610614
}
611615

612616
/**

src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* @author Kevin Lang
4242
* @author Alexander Saydakov
4343
*/
44-
public final class ItemsSketchSortedView<T> implements GenericSortedView<T> {
44+
public class ItemsSketchSortedView<T> implements GenericSortedView<T> {
4545
private final T[] quantiles;
4646
private final long[] cumWeights; //comes in as individual weights, converted to cumulative natural weights
4747
private final long totalN;
@@ -54,7 +54,10 @@ public final class ItemsSketchSortedView<T> implements GenericSortedView<T> {
5454
* @param totalN the total number of items presented to the sketch.
5555
* @param comparator comparator for type T
5656
*/
57-
ItemsSketchSortedView(final T[] quantiles, final long[] cumWeights, final long totalN,
57+
ItemsSketchSortedView(
58+
final T[] quantiles,
59+
final long[] cumWeights,
60+
final long totalN,
5861
final Comparator<T> comparator) {
5962
this.quantiles = quantiles;
6063
this.cumWeights = cumWeights;

src/main/java/org/apache/datasketches/quantilescommon/GenericSortedViewIterator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public class GenericSortedViewIterator<T> implements SortedViewIterator {
3535
private int index;
3636

3737
public GenericSortedViewIterator(final T[] quantiles, final long[] cumWeights) {
38-
this.quantiles = quantiles;
39-
this.cumWeights = cumWeights;
38+
this.quantiles = quantiles; //SpotBugs EI_EXPOSE_REP2 suppressed by FindBugsExcludeFilter
39+
this.cumWeights = cumWeights; //SpotBugs EI_EXPOSE_REP2 suppressed by FindBugsExcludeFilter
4040
this.totalN = (cumWeights.length > 0) ? cumWeights[cumWeights.length - 1] : 0;
4141
index = -1;
4242
}

src/test/java/org/apache/datasketches/common/TestUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
public final class TestUtil {
3131

32-
private static String userDir = System.getProperty("user.dir");
32+
private static final String userDir = System.getProperty("user.dir");
3333

3434
/**
3535
* TestNG group constants
@@ -41,17 +41,17 @@ public final class TestUtil {
4141
/**
4242
* The full target Path for Java serialized sketches to be tested by other languages.
4343
*/
44-
public static Path javaPath = createPath("target/java_generated_files");
44+
public static final Path javaPath = createPath("target/java_generated_files");
4545

4646
/**
4747
* The full target Path for C++ serialized sketches to be tested by Java.
4848
*/
49-
public static Path cppPath = createPath("target/cpp_generated_files");
49+
public static final Path cppPath = createPath("target/cpp_generated_files");
5050

5151
/**
5252
* The full target Path for historical C++ serialized sketches to be tested by Java.
5353
*/
54-
public static Path cppHistPath = createPath("src/test/resources");
54+
public static final Path cppHistPath = createPath("src/test/resources");
5555

5656
private static Path createPath(final String projectLocalDir) {
5757
try {

src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public int compare(final String s1, final String s2) {
161161
try {
162162
final int i1 = Integer.parseInt(s1);
163163
final int i2 = Integer.parseInt(s2);
164-
return Integer.valueOf(i1).compareTo(i2);
164+
return Integer.compare(i1, i2);
165165
} catch (NumberFormatException e) {
166166
throw new RuntimeException(e);
167167
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.datasketches.kll;
21+
22+
import java.util.Comparator;
23+
24+
/**
25+
* For testing only
26+
*/
27+
public class KllItemsSketchSortedViewString extends KllItemsSketchSortedView<String> {
28+
29+
public KllItemsSketchSortedViewString(
30+
final String[] quantiles,
31+
final long[] cumWeights,
32+
final long totalN,
33+
final String minItem,
34+
final Comparator<String> comparator) {
35+
super(quantiles, cumWeights, totalN, minItem, comparator);
36+
}
37+
}

0 commit comments

Comments
 (0)