Skip to content

Commit 8f99575

Browse files
committed
Enabling lint
There are types of linting errors that seem worthy of being fixed. I have adopted some cookie cutter solution to fix two types of errors: 1) Remove usage of asserts that are unsupported in ART See: https://android.googlesource.com/platform/tools/base/+/master/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AssertDetector.java 2) Replace HashMaps with SparseArrays Which seemed appropriate based on a rudimentary glance. See: https://stackoverflow.com/questions/25560629/sparsearray-vs-hashmap If you feel like these replacements are appropriate, I can replace them at a bunch of more places and enable linting
1 parent 5e25b96 commit 8f99575

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

firebase-firestore/firebase-firestore.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ android {
5959
multiDexEnabled true
6060
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
6161
}
62-
lintOptions {
63-
abortOnError false
64-
}
62+
6563
sourceSets {
6664
main {
6765
proto {

firebase-firestore/src/main/java/com/google/cloud/datastore/core/number/IndexNumberEncoder.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.cloud.datastore.core.number;
1616

17+
import com.google.firebase.firestore.BuildConfig;
18+
1719
/**
1820
* Encodes numbers (longs and doubles) as bytes whose order matches the numeric order.
1921
*
@@ -296,7 +298,8 @@ private static int encodeNumber(
296298

297299
// Store exponents [4, 19] biased as [0, 15]
298300
exponent -= EXP1_END;
299-
assert exponent <= 0xF;
301+
if(BuildConfig.DEBUG && !(exponent <= 0xF))
302+
throw new RuntimeException();
300303

301304
// Store exponent as low order 4 bits, no continuation bit
302305
lastByte |= exponent;
@@ -314,7 +317,8 @@ private static int encodeNumber(
314317

315318
// Store exponents [20, 147] biased as [0, 127]
316319
exponent -= EXP2_END;
317-
assert exponent <= 0x7F;
320+
if(BuildConfig.DEBUG && !(exponent <= 0x7F))
321+
throw new RuntimeException();
318322

319323
// Pack the top 3 bits of the 7 bit exponent as the low order bits
320324
lastByte |= exponent >>> 4;
@@ -342,7 +346,8 @@ private static int encodeNumber(
342346

343347
// Store exponents [148, 1171] biased as [0, 1023]
344348
exponent -= EXP3_END;
345-
assert exponent <= 0x3FF;
349+
if(BuildConfig.DEBUG && !(exponent <= 0x3FF))
350+
throw new RuntimeException();
346351

347352
// Pack the top 2 bits of the exponent as the low order bits
348353
lastByte |= exponent >>> 8;

firebase-firestore/src/main/java/com/google/cloud/datastore/core/number/NumberIndexEncoder.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import static com.google.cloud.datastore.core.number.NumberParts.SIGNIFICAND_BITS;
1818

19+
import com.google.firebase.firestore.BuildConfig;
1920
import java.util.Arrays;
2021

2122
/**
@@ -194,7 +195,8 @@ public static byte[] encode(NumberParts parts) {
194195

195196
// Store exponents [4, 19] biased as [0, 15]
196197
exponent -= EXP1_END;
197-
assert exponent <= 0xF;
198+
if(BuildConfig.DEBUG && !(exponent <= 0xF))
199+
throw new RuntimeException();
198200

199201
// Store exponent as low order 4 bits, no continuation bit
200202
lastByte |= exponent;
@@ -212,7 +214,8 @@ public static byte[] encode(NumberParts parts) {
212214

213215
// Store exponents [20, 147] biased as [0, 127]
214216
exponent -= EXP2_END;
215-
assert exponent <= 0x7F;
217+
if(BuildConfig.DEBUG && !(exponent <= 0x7F))
218+
throw new RuntimeException();
216219

217220
// Pack the top 3 bits of the 7 bit exponent as the low order bits
218221
lastByte |= exponent >>> 4;
@@ -240,7 +243,8 @@ public static byte[] encode(NumberParts parts) {
240243

241244
// Store exponents [148, 1171] biased as [0, 1023]
242245
exponent -= EXP3_END;
243-
assert exponent <= 0x3FF;
246+
if(BuildConfig.DEBUG && !(exponent <= 0x3FF))
247+
throw new RuntimeException();
244248

245249
// Pack the top 2 bits of the exponent as the low order bits
246250
lastByte |= exponent >>> 8;

firebase-firestore/src/main/java/com/google/firebase/firestore/remote/RemoteStore.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static com.google.firebase.firestore.util.Assert.hardAssert;
1818

1919
import android.support.annotation.Nullable;
20+
import android.util.SparseArray;
2021
import com.google.firebase.database.collection.ImmutableSortedSet;
2122
import com.google.firebase.firestore.core.OnlineState;
2223
import com.google.firebase.firestore.core.Transaction;
@@ -118,7 +119,7 @@ public interface RemoteStoreCallback {
118119
* removed with unlistens are removed eagerly without waiting for confirmation from the listen
119120
* stream.
120121
*/
121-
private final Map<Integer, QueryData> listenTargets;
122+
private final SparseArray<QueryData> listenTargets;
122123

123124
private final OnlineStateTracker onlineStateTracker;
124125

@@ -152,7 +153,7 @@ public RemoteStore(
152153
this.localStore = localStore;
153154
this.datastore = datastore;
154155

155-
listenTargets = new HashMap<>();
156+
listenTargets = new SparseArray<QueryData>();
156157
writePipeline = new ArrayDeque<>();
157158

158159
onlineStateTracker =
@@ -292,8 +293,7 @@ public void handleCredentialChange() {
292293
/** Listens to the target identified by the given QueryData. */
293294
public void listen(QueryData queryData) {
294295
Integer targetId = queryData.getTargetId();
295-
hardAssert(
296-
!listenTargets.containsKey(targetId),
296+
hardAssert(listenTargets.get(targetId) == null,
297297
"listen called with duplicate target ID: %d",
298298
targetId);
299299

@@ -318,7 +318,8 @@ private void sendWatchRequest(QueryData queryData) {
318318
* be torn down after one minute of inactivity.
319319
*/
320320
public void stopListening(int targetId) {
321-
QueryData queryData = listenTargets.remove(targetId);
321+
QueryData queryData = listenTargets.get(targetId);
322+
listenTargets.remove(targetId);
322323
hardAssert(
323324
queryData != null, "stopListening called on target no currently watched: %d", targetId);
324325

@@ -327,7 +328,7 @@ public void stopListening(int targetId) {
327328
sendUnwatchRequest(targetId);
328329
}
329330

330-
if (listenTargets.isEmpty()) {
331+
if (listenTargets.size()==0) {
331332
if (watchStream.isOpen()) {
332333
watchStream.markIdle();
333334
} else if (this.canUseNetwork()) {
@@ -357,7 +358,7 @@ private boolean shouldStartWriteStream() {
357358
* active watch targets.
358359
*/
359360
private boolean shouldStartWatchStream() {
360-
return canUseNetwork() && !watchStream.isStarted() && !listenTargets.isEmpty();
361+
return canUseNetwork() && !watchStream.isStarted() && listenTargets.size() != 0;
361362
}
362363

363364
private void cleanUpWatchStreamState() {
@@ -378,9 +379,10 @@ private void startWatchStream() {
378379
}
379380

380381
private void handleWatchStreamOpen() {
382+
final int nsize = listenTargets.size();
381383
// Restore any existing watches.
382-
for (QueryData queryData : listenTargets.values()) {
383-
sendWatchRequest(queryData);
384+
for(int i = 0; i < nsize; i++) {
385+
sendWatchRequest(listenTargets.get(i));
384386
}
385387
}
386388

@@ -515,7 +517,7 @@ private void processTargetError(WatchTargetChange targetChange) {
515517
hardAssert(targetChange.getCause() != null, "Processing target error without a cause");
516518
for (Integer targetId : targetChange.getTargetIds()) {
517519
// Ignore targets that have been removed already.
518-
if (listenTargets.containsKey(targetId)) {
520+
if (listenTargets.get(targetId) != null) {
519521
listenTargets.remove(targetId);
520522
watchChangeAggregator.removeTarget(targetId);
521523
remoteStoreCallback.handleRejectedListen(targetId, targetChange.getCause());

0 commit comments

Comments
 (0)