Skip to content

Commit 819d738

Browse files
authored
Clean up warnings (#216)
* Use diamond operator where possible. * Remove unnecessary parentheses * Fix accidental use of raw type * Move cast inside parenthesis * Suppress warnings for intentional synchronization around non-final fields * Explicitly handle null case to avoid NPE warning in the catch block * Fix typo * Switch from junit.framework to org.junit * Pass -1 explicitly to String.split to avoid unexpected behavior https://errorprone.info/bugpattern/StringSplitter * Use a lambda * Use a larger epsilon Doubles near long_max are farther apart than 0.00001
1 parent 1a39d8c commit 819d738

File tree

13 files changed

+30
-28
lines changed

13 files changed

+30
-28
lines changed

firebase-database-collection/src/main/java/com/google/firebase/database/collection/LLRBValueNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public LLRBValueNode<K, V> copy(
6767
LLRBNode<K, V> newLeft = left == null ? this.left : left;
6868
LLRBNode<K, V> newRight = right == null ? this.right : right;
6969
if (color == Color.RED) {
70-
return new LLRBRedValueNode<K, V>(newKey, newValue, newLeft, newRight);
70+
return new LLRBRedValueNode<>(newKey, newValue, newLeft, newRight);
7171
} else {
72-
return new LLRBBlackValueNode<K, V>(newKey, newValue, newLeft, newRight);
72+
return new LLRBBlackValueNode<>(newKey, newValue, newLeft, newRight);
7373
}
7474
}
7575

@@ -221,7 +221,7 @@ private LLRBValueNode<K, V> fixUp() {
221221
if (n.right.isRed() && !n.left.isRed()) {
222222
n = n.rotateLeft();
223223
}
224-
if (n.left.isRed() && ((LLRBValueNode<K, V>) (n.left)).left.isRed()) {
224+
if (n.left.isRed() && ((LLRBValueNode<K, V>) n.left).left.isRed()) {
225225
n = n.rotateRight();
226226
}
227227
if (n.left.isRed() && n.right.isRed()) {
@@ -232,13 +232,13 @@ private LLRBValueNode<K, V> fixUp() {
232232

233233
private LLRBValueNode<K, V> rotateLeft() {
234234
LLRBValueNode<K, V> newLeft =
235-
this.copy(null, null, Color.RED, null, ((LLRBValueNode<K, V>) (this.right)).left);
235+
this.copy(null, null, Color.RED, null, ((LLRBValueNode<K, V>) this.right).left);
236236
return (LLRBValueNode<K, V>) this.right.copy(null, null, this.getColor(), newLeft, null);
237237
}
238238

239239
private LLRBValueNode<K, V> rotateRight() {
240240
LLRBValueNode<K, V> newRight =
241-
this.copy(null, null, Color.RED, ((LLRBValueNode<K, V>) (this.left)).right, null);
241+
this.copy(null, null, Color.RED, ((LLRBValueNode<K, V>) this.left).right, null);
242242
return (LLRBValueNode<K, V>) this.left.copy(null, null, this.getColor(), null, newRight);
243243
}
244244

firebase-database-collection/src/main/java/com/google/firebase/database/collection/RBTreeSortedMap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static class Base1_2 implements Iterable<BooleanChunk> {
243243
public Base1_2(int size) {
244244
int toCalc = size + 1;
245245
length = (int) Math.floor(Math.log(toCalc) / Math.log(2));
246-
long mask = (long) (Math.pow(2, length)) - 1;
246+
long mask = ((long) Math.pow(2, length)) - 1;
247247
value = toCalc & mask;
248248
}
249249

@@ -340,7 +340,7 @@ public static <A, B, C> RBTreeSortedMap<A, C> buildFrom(
340340
Comparator<A> comparator) {
341341
Builder<A, B, C> builder = new Builder<>(keys, values, translator);
342342
Collections.sort(keys, comparator);
343-
Iterator<BooleanChunk> iter = (new Base1_2(keys.size())).iterator();
343+
Iterator<BooleanChunk> iter = new Base1_2(keys.size()).iterator();
344344
int index = keys.size();
345345
while (iter.hasNext()) {
346346
BooleanChunk next = iter.next();

firebase-firestore/src/main/java/com/google/firebase/firestore/util/ListenerRegistrationImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public static class StopListenerSupportFragment extends android.support.v4.app.F
7878
CallbackList callbacks = new CallbackList();
7979

8080
@Override
81+
@SuppressWarnings("SynchronizeOnNonFinalField")
8182
public void onStop() {
8283
super.onStop();
8384

@@ -100,6 +101,7 @@ public static class StopListenerFragment extends android.app.Fragment {
100101
CallbackList callbacks = new CallbackList();
101102

102103
@Override
104+
@SuppressWarnings("SynchronizeOnNonFinalField")
103105
public void onStop() {
104106
super.onStop();
105107

@@ -116,6 +118,9 @@ public void onStop() {
116118
@Nullable
117119
private static <T> T castFragment(Class<T> fragmentClass, @Nullable Object fragment, String tag) {
118120
try {
121+
if (fragment == null) {
122+
return null;
123+
}
119124
return fragmentClass.cast(fragment);
120125
} catch (ClassCastException e) {
121126
throw new IllegalStateException(
@@ -132,8 +137,8 @@ private static <T> T castFragment(Class<T> fragmentClass, @Nullable Object fragm
132137
private static final String FRAGMENT_TAG = "FirestoreOnStopObserverFragment";
133138

134139
/**
135-
* Implementation for non-FragmentActivity Activity's. Unfortunatly, all Fragment related
136-
* classes/methods with nonFragmentActivityActivity's are deprecated, implying that almost
140+
* Implementation for non-FragmentActivity Activities. Unfortunately, all Fragment related
141+
* classes/methods with nonFragmentActivityActivities are deprecated, implying that almost
137142
* everything in this function is deprecated.
138143
*/
139144
@SuppressWarnings("deprecation")

firebase-firestore/src/test/java/com/google/firebase/firestore/DocumentChangeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import static com.google.firebase.firestore.testutil.TestUtil.path;
2525
import static com.google.firebase.firestore.testutil.TestUtil.targetChange;
2626
import static java.util.Arrays.asList;
27-
import static junit.framework.Assert.assertEquals;
27+
import static org.junit.Assert.assertEquals;
2828
import static org.mockito.Mockito.mock;
2929

3030
import com.google.firebase.database.collection.ImmutableSortedMap;

firebase-firestore/src/test/java/com/google/firebase/firestore/TestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import java.util.HashMap;
3737
import java.util.List;
3838
import java.util.Map;
39-
import junit.framework.Assert;
39+
import org.junit.Assert;
4040
import org.robolectric.Robolectric;
4141

4242
public class TestUtil {

firebase-firestore/src/test/java/com/google/firebase/firestore/core/EventManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
package com.google.firebase.firestore.core;
1616

1717
import static com.google.firebase.firestore.testutil.TestUtil.path;
18-
import static junit.framework.Assert.assertEquals;
19-
import static org.mockito.Matchers.any;
18+
import static org.junit.Assert.assertEquals;
19+
import static org.mockito.ArgumentMatchers.any;
2020
import static org.mockito.Mockito.doAnswer;
2121
import static org.mockito.Mockito.inOrder;
2222
import static org.mockito.Mockito.mock;

firebase-firestore/src/test/java/com/google/firebase/firestore/local/LruGarbageCollectorTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private QueryData addNextQuery() {
124124
}
125125

126126
private DocumentKey nextTestDocumentKey() {
127-
return DocumentKey.fromPathString("docs/doc_" + (++previousDocNum));
127+
return DocumentKey.fromPathString("docs/doc_" + ++previousDocNum);
128128
}
129129

130130
private Document nextTestDocument() {

firebase-firestore/src/test/java/com/google/firebase/firestore/local/RemoteDocumentCacheTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void testReadSeveralDocumentsIncludingMissingDocument() {
106106
}
107107
written.put(DocumentKey.fromPathString("foo/nonexistent"), null);
108108

109-
List<String> keys = new ArrayList(Arrays.asList(paths));
109+
List<String> keys = new ArrayList<>(Arrays.asList(paths));
110110
keys.add("foo/nonexistent");
111111
Map<DocumentKey, MaybeDocument> read = getAll(keys);
112112
assertEquals(written, read);

firebase-firestore/src/test/java/com/google/firebase/firestore/local/SQLiteSchemaTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public void addsSentinelRows() {
291291
String path = row.getString(0);
292292
long sequenceNumber = row.getLong(1);
293293

294-
int docNum = Integer.parseInt(path.split("_")[1]);
294+
int docNum = Integer.parseInt(path.split("_", -1)[1]);
295295
// The even documents were missing sequence numbers, they should now be filled in
296296
// to have the new sequence number. The odd documents should have their
297297
// sequence number unchanged, and so be the old value.

firebase-firestore/src/test/java/com/google/firebase/firestore/model/DocumentSetTest.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import static com.google.firebase.firestore.testutil.TestUtil.docSet;
1919
import static com.google.firebase.firestore.testutil.TestUtil.field;
2020
import static com.google.firebase.firestore.testutil.TestUtil.map;
21-
import static junit.framework.Assert.assertFalse;
22-
import static junit.framework.Assert.assertNull;
2321
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertFalse;
2423
import static org.junit.Assert.assertNotEquals;
24+
import static org.junit.Assert.assertNull;
2525
import static org.junit.Assert.assertTrue;
2626

2727
import com.google.firebase.firestore.model.value.FieldValue;
@@ -38,13 +38,10 @@
3838
public class DocumentSetTest {
3939

4040
private static final Comparator<Document> TEST_COMPARATOR =
41-
new Comparator<Document>() {
42-
@Override
43-
public int compare(Document left, Document right) {
44-
FieldValue leftValue = left.getField(field("sort"));
45-
FieldValue rightValue = right.getField(field("sort"));
46-
return leftValue.compareTo(rightValue);
47-
}
41+
(left, right) -> {
42+
FieldValue leftValue = left.getField(field("sort"));
43+
FieldValue rightValue = right.getField(field("sort"));
44+
return leftValue.compareTo(rightValue);
4845
};
4946

5047
private static final Document DOC1 = doc("docs/1", 0, map("sort", 2));

firebase-firestore/src/test/java/com/google/firebase/firestore/model/FieldValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public void testExtractsFields() {
275275
FieldValue val = wrapObject("foo", map("a", 1, "b", true, "c", "string"));
276276
assertTrue(val instanceof ObjectValue);
277277
ObjectValue obj = (ObjectValue) val;
278-
assertTrue((obj.get(field("foo"))) instanceof ObjectValue);
278+
assertTrue(obj.get(field("foo")) instanceof ObjectValue);
279279
assertEquals(wrap(1), obj.get(field("foo.a")));
280280
assertEquals(wrap(true), obj.get(field("foo.b")));
281281
assertEquals(wrap("string"), obj.get(field("foo.c")));

firebase-firestore/src/test/java/com/google/firebase/firestore/remote/RemoteEventTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import static com.google.firebase.firestore.testutil.TestUtil.version;
2626
import static java.util.Arrays.asList;
2727
import static java.util.Collections.emptyList;
28-
import static junit.framework.Assert.fail;
2928
import static org.junit.Assert.assertEquals;
3029
import static org.junit.Assert.assertFalse;
3130
import static org.junit.Assert.assertNull;
3231
import static org.junit.Assert.assertTrue;
32+
import static org.junit.Assert.fail;
3333

3434
import com.google.firebase.database.collection.ImmutableSortedSet;
3535
import com.google.firebase.firestore.TestUtil.TestTargetMetadataProvider;

firebase-firestore/src/test/java/com/google/firebase/firestore/util/MapperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
@Config(manifest = Config.NONE)
4242
@SuppressWarnings({"unused", "WeakerAccess", "SpellCheckingInspection"})
4343
public class MapperTest {
44-
private static final double EPSILON = 0.00001f;
44+
private static final double EPSILON = 0.0003;
4545

4646
private static class StringBean {
4747
private String value;

0 commit comments

Comments
 (0)