Skip to content

Audit code to ensure printf style templates are compile time constants. #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public void testQuerySnapshotEventsForAdd() {
assertFalse(doc2.getMetadata().hasPendingWrites());
break;
default:
fail("unexpected call to onSnapshot:" + snapshot);
fail("unexpected call to onSnapshot: " + snapshot);
}
});
waitFor(emptyLatch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public EventAccumulator() {
public EventListener<T> listener() {
return (value, error) -> {
synchronized (EventAccumulator.this) {
hardAssert(error == null, "Unexpected error: " + error);
hardAssert(error == null, "Unexpected error: %s", error);
Log.i("EventAccumulator", "Received new event: " + value);
events.add(value);
checkFulfilled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,14 @@ private Object convertValue(FieldValue value, FieldValueOptions options) {
// TODO: Somehow support foreign references.
Logger.warn(
"DocumentSnapshot",
String.format(
"Document %s contains a document reference within a different database "
+ "(%s/%s) which is not supported. It will be treated as a reference in "
+ "the current database (%s/%s) instead.",
key.getPath(),
refDatabase.getProjectId(),
refDatabase.getDatabaseId(),
database.getProjectId(),
database.getDatabaseId()));
"Document %s contains a document reference within a different database "
+ "(%s/%s) which is not supported. It will be treated as a reference in "
+ "the current database (%s/%s) instead.",
key.getPath(),
refDatabase.getProjectId(),
refDatabase.getDatabaseId(),
database.getProjectId(),
database.getDatabaseId());
}
return new DocumentReference(key, firestore);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private boolean matchesComparison(int comp) {
case GREATER_THAN_OR_EQUAL:
return comp >= 0;
default:
throw Assert.fail("Unknown operator: ", operator);
throw Assert.fail("Unknown operator: %s", operator);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public void handleRejectedListen(int targetId, Status error) {
handleRemoteEvent(event);
} else {
QueryView queryView = queryViewsByTarget.get(targetId);
hardAssert(queryView != null, "Unknown target: " + targetId);
hardAssert(queryView != null, "Unknown target: %s", targetId);
localStore.releaseQuery(queryView.getQuery());
removeAndCleanup(queryView);
callback.onError(queryView.getQuery(), error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingCollection
} else if (mutatedDoc instanceof Document) {
results = results.insert(key, (Document) mutatedDoc);
} else {
throw fail("Unknown document type: " + mutatedDoc);
throw fail("Unknown document type: %s", mutatedDoc);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ MaybeDocument decodeMaybeDocument(com.google.firebase.firestore.proto.MaybeDocum
return decodeNoDocument(proto.getNoDocument());

default:
throw fail("Unknown MaybeDocument " + proto);
throw fail("Unknown MaybeDocument %s", proto);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ public static MutationBatchResult create(
ByteString streamToken) {
Assert.hardAssert(
batch.getMutations().size() == mutationResults.size(),
"Mutations sent "
+ batch.getMutations().size()
+ " must equal results received "
+ mutationResults.size());
"Mutations sent %d must equal results received %d",
batch.getMutations().size(),
mutationResults.size());
ImmutableSortedMap<DocumentKey, SnapshotVersion> docVersions =
DocumentCollections.emptyVersionMap();
List<Mutation> mutations = batch.getMutations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public MaybeDocument applyToLocalView(
* method is guaranteed to be safe.
*/
private Document requireDocument(@Nullable MaybeDocument maybeDoc) {
hardAssert(maybeDoc instanceof Document, "Unknown MaybeDocument type " + maybeDoc);
hardAssert(maybeDoc instanceof Document, "Unknown MaybeDocument type %s", maybeDoc);
Document doc = (Document) maybeDoc;
hardAssert(doc.getKey().equals(getKey()), "Can only transform a document with the same key");
return doc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ private void logClientOfflineWarningIfNecessary(String reason) {
reason);

if (shouldWarnClientIsOffline) {
Logger.warn(LOG_TAG, message);
Logger.warn(LOG_TAG, "%s", message);
shouldWarnClientIsOffline = false;
} else {
Logger.debug(LOG_TAG, message);
Logger.debug(LOG_TAG, "%s", message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public com.google.firestore.v1beta1.Value encodeValue(FieldValue value) {
DocumentKey key = (DocumentKey) encodedValue;
builder.setReferenceValue(encodeResourceName(id, key.getPath()));
} else {
throw fail("Can't serialize " + value);
throw fail("Can't serialize %s", value);
}

return builder.build();
Expand Down Expand Up @@ -330,7 +330,7 @@ public FieldValue decodeValue(com.google.firestore.v1beta1.Value proto) {
case MAP_VALUE:
return decodeMapValue(proto.getMapValue());
default:
throw fail("Unknown value " + proto);
throw fail("Unknown value %s", proto);
}
}

Expand Down Expand Up @@ -446,7 +446,7 @@ public com.google.firestore.v1beta1.Write encodeMutation(Mutation mutation) {
} else if (mutation instanceof DeleteMutation) {
builder.setDelete(encodeKey(mutation.getKey()));
} else {
throw fail("unknown mutation type ", mutation.getClass());
throw fail("unknown mutation type %s", mutation.getClass());
}

if (!mutation.getPrecondition().isNone()) {
Expand Down Expand Up @@ -579,7 +579,8 @@ private FieldTransform decodeFieldTransform(DocumentTransform.FieldTransform fie
hardAssert(
fieldTransform.getSetToServerValue()
== DocumentTransform.FieldTransform.ServerValue.REQUEST_TIME,
"Unknown transform setToServerValue: " + fieldTransform.getSetToServerValue());
"Unknown transform setToServerValue: %s",
fieldTransform.getSetToServerValue());
return new FieldTransform(
FieldPath.fromServerFormat(fieldTransform.getFieldPath()),
ServerTimestampOperation.getInstance());
Expand Down Expand Up @@ -857,7 +858,7 @@ private StructuredQuery.Filter encodeUnaryFilter(Filter filter) {
} else if (filter instanceof NullFilter) {
proto.setOp(UnaryFilter.Operator.IS_NULL);
} else {
throw fail("Unrecognized filter: " + filter.getCanonicalId());
throw fail("Unrecognized filter: %s", filter.getCanonicalId());
}
return StructuredQuery.Filter.newBuilder().setUnaryFilter(proto).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ TargetChange toTargetChange() {
removedDocuments = removedDocuments.insert(key);
break;
default:
throw fail("Encountered invalid change type: " + changeType);
throw fail("Encountered invalid change type: %s", changeType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void handleTargetChange(WatchTargetChange targetChange) {
}
break;
default:
throw fail("Unknown target watch change state: " + targetChange.getChangeType());
throw fail("Unknown target watch change state: %s", targetChange.getChangeType());
}
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public void handleExistenceFilter(ExistenceFilterWatchChange watchChange) {
removeDocumentFromTarget(targetId, key, new NoDocument(key, SnapshotVersion.NONE));
} else {
hardAssert(
expectedCount == 1, "Single document existence filter with count: " + expectedCount);
expectedCount == 1, "Single document existence filter with count: %d", expectedCount);
}
} else {
long currentSize = getCurrentDocumentCountForTarget(targetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ T deserialize(
if (throwOnUnknownProperties) {
throw new RuntimeException(message);
} else if (warnOnUnknownProperties) {
Logger.warn(CustomClassMapper.class.getSimpleName(), message);
Logger.warn(CustomClassMapper.class.getSimpleName(), "%s", message);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private Query parseQuery(Object querySpec) throws JSONException {
}
return query;
} else {
throw Assert.fail("Invalid query: " + querySpec);
throw Assert.fail("Invalid query: %s", querySpec);
}
}

Expand Down Expand Up @@ -761,7 +761,7 @@ private void doStep(JSONObject step) throws Exception {
throw Assert.fail(
"'applyClientState' is not supported on Android and should only be used in multi-client tests");
} else {
throw Assert.fail("Unknown step: " + step);
throw Assert.fail("Unknown step: %s", step);
}
}

Expand Down