Skip to content

Commit d920962

Browse files
Address RTDB Lint violations (#1866)
1 parent 96b07e3 commit d920962

35 files changed

+171
-98
lines changed

firebase-database/src/main/java/com/google/firebase/database/DatabaseError.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.PrintWriter;
2020
import java.io.StringWriter;
2121
import java.util.HashMap;
22+
import java.util.Locale;
2223
import java.util.Map;
2324

2425
/**
@@ -164,7 +165,7 @@ public static DatabaseError fromCode(int code) {
164165
*/
165166
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
166167
public static DatabaseError fromStatus(String status, String reason, String details) {
167-
Integer code = errorCodes.get(status.toLowerCase());
168+
Integer code = errorCodes.get(status.toLowerCase(Locale.US));
168169
if (code == null) {
169170
code = UNKNOWN_ERROR;
170171
}

firebase-database/src/main/java/com/google/firebase/database/Query.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ private Query startAt(Node node, String key) {
362362
QueryParams newParams = params.startAt(node, childKey);
363363
validateLimit(newParams);
364364
validateQueryEndpoints(newParams);
365-
assert newParams.isValid();
365+
hardAssert(newParams.isValid());
366366
return new Query(repo, path, newParams, orderByCalled);
367367
}
368368

@@ -460,7 +460,7 @@ private Query endAt(Node node, String key) {
460460
QueryParams newParams = params.endAt(node, childKey);
461461
validateLimit(newParams);
462462
validateQueryEndpoints(newParams);
463-
assert newParams.isValid();
463+
hardAssert(newParams.isValid());
464464
return new Query(repo, path, newParams, orderByCalled);
465465
}
466466

firebase-database/src/main/java/com/google/firebase/database/android/SqlPersistenceStorageEngine.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ public void onCreate(SQLiteDatabase db) {
171171

172172
@Override
173173
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
174-
assert newVersion == DATABASE_VERSION : "Why is onUpgrade() called with a different version?";
174+
hardAssert(
175+
newVersion == DATABASE_VERSION, "Why is onUpgrade() called with a different version?");
175176
if (oldVersion <= 1) {
176177
// Leave old writes table.
177178

@@ -1036,12 +1037,12 @@ private static String pathToKey(Path path) {
10361037
}
10371038

10381039
private static String pathPrefixStartToPrefixEnd(String prefix) {
1039-
assert prefix.endsWith("/") : "Path keys must end with a '/'";
1040+
hardAssert(prefix.endsWith("/"), "Path keys must end with a '/'");
10401041
return prefix.substring(0, prefix.length() - 1) + (char) ('/' + 1);
10411042
}
10421043

10431044
private static String buildAncestorWhereClause(Path path, String[] arguments) {
1044-
assert arguments.length >= path.size() + 1;
1045+
hardAssert(arguments.length >= path.size() + 1);
10451046
int count = 0;
10461047
StringBuilder whereClause = new StringBuilder("(");
10471048
while (!path.isEmpty()) {

firebase-database/src/main/java/com/google/firebase/database/connection/PersistentConnectionImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,9 @@ private void putInternal(
10101010
}
10111011

10121012
private void sendPut(final long putId) {
1013-
assert canSendWrites()
1014-
: "sendPut called when we can't send writes (we're disconnected or writes are paused).";
1013+
hardAssert(
1014+
canSendWrites(),
1015+
"sendPut called when we can't send writes (we're disconnected or writes are paused).");
10151016
final OutstandingPut put = outstandingPuts.get(putId);
10161017
final RequestResultCallback onComplete = put.getOnComplete();
10171018
final String action = put.getAction();

firebase-database/src/main/java/com/google/firebase/database/core/CompoundWrite.java

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

1515
package com.google.firebase.database.core;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
18+
1719
import com.google.firebase.database.core.utilities.ImmutableTree;
1820
import com.google.firebase.database.snapshot.ChildKey;
1921
import com.google.firebase.database.snapshot.NamedNode;
@@ -227,7 +229,7 @@ private Node applySubtreeWrite(Path relativePath, ImmutableTree<Node> writeTree,
227229
if (childKey.isPriorityChildName()) {
228230
// Apply priorities at the end so we don't update priorities for either empty nodes or
229231
// forget to apply priorities to empty nodes that are later filled
230-
assert childTree.getValue() != null : "Priority writes must always be leaf nodes";
232+
hardAssert(childTree.getValue() != null, "Priority writes must always be leaf nodes");
231233
priorityWrite = childTree.getValue();
232234
} else {
233235
node = applySubtreeWrite(relativePath.child(childKey), childTree, node);

firebase-database/src/main/java/com/google/firebase/database/core/EventRegistration.java

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

1515
package com.google.firebase.database.core;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
18+
1719
import com.google.firebase.database.DatabaseError;
1820
import com.google.firebase.database.annotations.NotNull;
1921
import com.google.firebase.database.core.view.Change;
@@ -56,8 +58,8 @@ public boolean isZombied() {
5658
}
5759

5860
public void setOnZombied(EventRegistrationZombieListener listener) {
59-
assert !isZombied();
60-
assert this.listener == null;
61+
hardAssert(!isZombied());
62+
hardAssert(this.listener == null);
6163
this.listener = listener;
6264
}
6365

firebase-database/src/main/java/com/google/firebase/database/core/Path.java

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

1515
package com.google.firebase.database.core;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
18+
1719
import com.google.firebase.database.DatabaseException;
1820
import com.google.firebase.database.snapshot.ChildKey;
1921
import java.util.ArrayList;
@@ -51,7 +53,7 @@ public Path(ChildKey... segments) {
5153
this.start = 0;
5254
this.end = segments.length;
5355
for (ChildKey name : segments) {
54-
assert name != null : "Can't construct a path with a null value!";
56+
hardAssert(name != null, "Can't construct a path with a null value!");
5557
}
5658
}
5759

firebase-database/src/main/java/com/google/firebase/database/core/Repo.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ public void addEventCallback(@NotNull EventRegistration eventRegistration) {
642642
}
643643

644644
public void keepSynced(QuerySpec query, boolean keep) {
645-
assert query.getPath().isEmpty() || !query.getPath().getFront().equals(Constants.DOT_INFO);
645+
hardAssert(query.getPath().isEmpty() || !query.getPath().getFront().equals(Constants.DOT_INFO));
646646

647647
serverSyncTree.keepSynced(query, keep);
648648
}
@@ -920,7 +920,7 @@ private void sendReadyTransactions(Tree<List<TransactionData>> node) {
920920
List<TransactionData> queue = node.getValue();
921921
if (queue != null) {
922922
queue = buildTransactionQueue(node);
923-
assert queue.size() > 0; // Sending zero length transaction queue
923+
hardAssert(queue.size() > 0); // Sending zero length transaction queue
924924

925925
Boolean allRun = true;
926926
for (TransactionData transaction : queue) {
@@ -959,8 +959,9 @@ private void sendTransactionQueue(final List<TransactionData> queue, final Path
959959
}
960960

961961
for (TransactionData txn : queue) {
962-
assert txn.status
963-
== TransactionStatus.RUN; // sendTransactionQueue: items in queue should all be run.'
962+
hardAssert(
963+
txn.status
964+
== TransactionStatus.RUN); // sendTransactionQueue: items in queue should all be run.'
964965
txn.status = TransactionStatus.SENT;
965966
txn.retryCount++;
966967
Path relativePath = Path.getRelative(path, txn.path);
@@ -1116,7 +1117,7 @@ private void rerunTransactionQueue(List<TransactionData> queue, Path path) {
11161117
DatabaseError abortReason = null;
11171118
List<Event> events = new ArrayList<Event>();
11181119

1119-
assert relativePath != null; // rerunTransactionQueue: relativePath should not be null.
1120+
hardAssert(relativePath != null); // rerunTransactionQueue: relativePath should not be null.
11201121

11211122
if (transaction.status == TransactionStatus.NEEDS_ABORT) {
11221123
abortTransaction = true;
@@ -1321,14 +1322,15 @@ private void abortTransactionsAtNode(Tree<List<TransactionData>> node, int reaso
13211322
if (transaction.status == TransactionStatus.SENT_NEEDS_ABORT) {
13221323
// No-op. Already marked
13231324
} else if (transaction.status == TransactionStatus.SENT) {
1324-
assert lastSent == i - 1; // All SENT items should be at beginning of queue.
1325+
hardAssert(lastSent == i - 1); // All SENT items should be at beginning of queue.
13251326
lastSent = i;
13261327
// Mark transaction for abort when it comes back.
13271328
transaction.status = TransactionStatus.SENT_NEEDS_ABORT;
13281329
transaction.abortReason = abortError;
13291330
} else {
1330-
assert transaction.status
1331-
== TransactionStatus.RUN; // Unexpected transaction status in abort
1331+
hardAssert(
1332+
transaction.status
1333+
== TransactionStatus.RUN); // Unexpected transaction status in abort
13321334
// We can abort this immediately.
13331335
removeEventCallback(
13341336
new ValueEventRegistration(

firebase-database/src/main/java/com/google/firebase/database/core/SyncPoint.java

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

1515
package com.google.firebase.database.core;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
18+
1719
import com.google.firebase.database.DatabaseError;
1820
import com.google.firebase.database.annotations.NotNull;
1921
import com.google.firebase.database.annotations.Nullable;
@@ -98,7 +100,7 @@ public List<DataEvent> applyOperation(
98100
QueryParams queryParams = operation.getSource().getQueryParams();
99101
if (queryParams != null) {
100102
View view = this.views.get(queryParams);
101-
assert view != null;
103+
hardAssert(view != null);
102104
return applyOperationToView(view, operation, writesCache, optCompleteServerCache);
103105
} else {
104106
List<DataEvent> events = new ArrayList<DataEvent>();

firebase-database/src/main/java/com/google/firebase/database/core/SyncTree.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ public List<? extends Event> applyTaggedRangeMerges(
348348
Path path, List<RangeMerge> rangeMerges, Tag tag) {
349349
QuerySpec query = queryForTag(tag);
350350
if (query != null) {
351-
assert path.equals(query.getPath());
351+
hardAssert(path.equals(query.getPath()));
352352
SyncPoint syncPoint = syncPointTree.get(query.getPath());
353-
assert syncPoint != null : "Missing sync point for query tag that we're tracking";
353+
hardAssert(syncPoint != null, "Missing sync point for query tag that we're tracking");
354354
View view = syncPoint.viewForQuery(query);
355-
assert view != null : "Missing view for query tag that we're tracking";
355+
hardAssert(view != null, "Missing view for query tag that we're tracking");
356356
Node serverNode = view.getServerCache();
357357
for (RangeMerge merge : rangeMerges) {
358358
serverNode = merge.applyTo(serverNode);
@@ -400,7 +400,7 @@ public List<? extends Event> call() {
400400
private List<? extends Event> applyTaggedOperation(QuerySpec query, Operation operation) {
401401
Path queryPath = query.getPath();
402402
SyncPoint syncPoint = syncPointTree.get(queryPath);
403-
assert syncPoint != null : "Missing sync point for query tag that we're tracking";
403+
hardAssert(syncPoint != null, "Missing sync point for query tag that we're tracking");
404404
WriteTreeRef writesCache = pendingWriteTree.childWrites(queryPath);
405405
return syncPoint.applyOperation(operation, writesCache, /*serverCache*/ null);
406406
}
@@ -542,7 +542,8 @@ public List<? extends Event> call() {
542542
boolean viewAlreadyExists = syncPoint.viewExistsForQuery(query);
543543
if (!viewAlreadyExists && !query.loadsAllData()) {
544544
// We need to track a tag for this query
545-
assert !queryToTagMap.containsKey(query) : "View does not exist but we have a tag";
545+
hardAssert(
546+
!queryToTagMap.containsKey(query), "View does not exist but we have a tag");
546547
Tag tag = getNextQueryTag();
547548
queryToTagMap.put(query, tag);
548549
tagToQueryMap.put(tag, query);
@@ -663,7 +664,7 @@ public List<Event> call() {
663664
} else {
664665
for (QuerySpec queryToRemove : removed) {
665666
Tag tag = tagForQuery(queryToRemove);
666-
assert tag != null;
667+
hardAssert(tag != null);
667668
listenProvider.stopListening(queryForListening(queryToRemove), tag);
668669
}
669670
}
@@ -770,7 +771,7 @@ private void removeTags(List<QuerySpec> queries) {
770771
if (!removedQuery.loadsAllData()) {
771772
// We should have a tag for this
772773
Tag tag = this.tagForQuery(removedQuery);
773-
assert tag != null;
774+
hardAssert(tag != null);
774775
this.queryToTagMap.remove(removedQuery);
775776
this.tagToQueryMap.remove(tag);
776777
}
@@ -798,8 +799,9 @@ private void setupListener(QuerySpec query, View view) {
798799
// The root of this subtree has our query. We're here because we definitely need to send a
799800
// listen for that, but we may need to shadow other listens as well.
800801
if (tag != null) {
801-
assert !subtree.getValue().hasCompleteView()
802-
: "If we're adding a query, it shouldn't be shadowed";
802+
hardAssert(
803+
!subtree.getValue().hasCompleteView(),
804+
"If we're adding a query, it shouldn't be shadowed");
803805
} else {
804806
// Shadow everything at or below this location, this is a default listener.
805807
subtree.foreach(

firebase-database/src/main/java/com/google/firebase/database/core/WriteTree.java

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

1515
package com.google.firebase.database.core;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
18+
1719
import com.google.firebase.database.core.utilities.Predicate;
1820
import com.google.firebase.database.core.view.CacheNode;
1921
import com.google.firebase.database.snapshot.ChildKey;
@@ -67,7 +69,7 @@ public WriteTreeRef childWrites(Path path) {
6769

6870
/** Record a new overwrite from user code. */
6971
public void addOverwrite(Path path, Node snap, Long writeId, boolean visible) {
70-
assert writeId > this.lastWriteId; // Stacking an older write on top of newer ones
72+
hardAssert(writeId > this.lastWriteId); // Stacking an older write on top of newer ones
7173
this.allWrites.add(new UserWriteRecord(writeId, path, snap, visible));
7274
if (visible) {
7375
this.visibleWrites = this.visibleWrites.addWrite(path, snap);
@@ -77,7 +79,7 @@ public void addOverwrite(Path path, Node snap, Long writeId, boolean visible) {
7779

7880
/** Record a new merge from user code. */
7981
public void addMerge(Path path, CompoundWrite changedChildren, Long writeId) {
80-
assert writeId > this.lastWriteId; // Stacking an older write on top of newer ones
82+
hardAssert(writeId > this.lastWriteId); // Stacking an older write on top of newer ones
8183
this.allWrites.add(new UserWriteRecord(writeId, path, changedChildren));
8284
this.visibleWrites = this.visibleWrites.addWrites(path, changedChildren);
8385
this.lastWriteId = writeId;
@@ -126,7 +128,7 @@ public boolean removeWrite(long writeId) {
126128
}
127129
idx++;
128130
}
129-
assert writeToRemove != null : "removeWrite called with nonexistent writeId";
131+
hardAssert(writeToRemove != null, "removeWrite called with nonexistent writeId");
130132

131133
this.allWrites.remove(writeToRemove);
132134

@@ -300,8 +302,9 @@ public Node calcEventCacheAfterServerOverwrite(
300302
final Path childPath,
301303
final Node existingEventSnap,
302304
final Node existingServerSnap) {
303-
assert existingEventSnap != null || existingServerSnap != null
304-
: "Either existingEventSnap or existingServerSnap must exist";
305+
hardAssert(
306+
existingEventSnap != null || existingServerSnap != null,
307+
"Either existingEventSnap or existingServerSnap must exist");
305308
Path path = treePath.child(childPath);
306309
if (this.visibleWrites.hasCompleteWrite(path)) {
307310
// At this point we can probably guarantee that we're in case 2, meaning no events

firebase-database/src/main/java/com/google/firebase/database/core/ZombieEventManager.java

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

1515
package com.google.firebase.database.core;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
18+
1719
import com.google.firebase.database.annotations.NotNull;
1820
import com.google.firebase.database.core.view.QuerySpec;
1921
import java.util.ArrayList;
@@ -89,7 +91,7 @@ private void unRecordEventRegistration(EventRegistration zombiedRegistration) {
8991
globalEventRegistrations.remove(zombiedRegistration);
9092
}
9193
}
92-
assert (found || !zombiedRegistration.isUserInitiated());
94+
hardAssert(found || !zombiedRegistration.isUserInitiated());
9395

9496
// If the registration was recorded twice, we need to remove its second
9597
// record.

firebase-database/src/main/java/com/google/firebase/database/core/operation/ListenComplete.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414

1515
package com.google.firebase.database.core.operation;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
18+
1719
import com.google.firebase.database.core.Path;
1820
import com.google.firebase.database.snapshot.ChildKey;
1921

2022
public class ListenComplete extends Operation {
2123

2224
public ListenComplete(OperationSource source, Path path) {
2325
super(OperationType.ListenComplete, source, path);
24-
assert !source.isFromUser() : "Can't have a listen complete from a user source";
26+
hardAssert(!source.isFromUser(), "Can't have a listen complete from a user source");
2527
}
2628

2729
@Override

firebase-database/src/main/java/com/google/firebase/database/core/operation/OperationSource.java

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

1515
package com.google.firebase.database.core.operation;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
18+
1719
import com.google.firebase.database.core.view.QueryParams;
1820

1921
public class OperationSource {
@@ -38,7 +40,7 @@ public OperationSource(Source source, QueryParams queryParams, boolean tagged) {
3840
this.source = source;
3941
this.queryParams = queryParams;
4042
this.tagged = tagged;
41-
assert !tagged || isFromServer();
43+
hardAssert(!tagged || isFromServer());
4244
}
4345

4446
public boolean isFromUser() {

0 commit comments

Comments
 (0)