Skip to content
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

Small tweaks to fix Error Prone warnings. #2227

Merged
merged 2 commits into from Oct 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -277,7 +277,7 @@ JsonElement nextJsonElement() throws IOException {
JsonToken peeked = peek();
switch (peeked) {
case NAME:
nextName(true);
String unused = nextName(true);

Check notice

Code scanning / CodeQL

Unread local variable

Variable 'String unused' is never read.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add @SuppressWarnings("unused") to avoid (Eclipse) IDE warnings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you send a PR for that, I will merge it. :-)
Error Prone doesn't warn about an unused variable if its name begins with unused.
Eventually I might want to add Error Prone's @CanIgnoreReturnValue to methods like this nextName, and then we wouldn't need to have this assignment. But that would mean introducing a dependency on Error Prone's annotations artifact.

break;
case END_ARRAY:
endArray();
Expand Down
4 changes: 2 additions & 2 deletions gson/src/test/java/com/google/gson/JsonArrayAsListTest.java
Expand Up @@ -210,7 +210,7 @@ public void testContains() {
assertFalse(list.contains(new JsonPrimitive(2)));
assertFalse(list.contains(null));

@SuppressWarnings("unlikely-arg-type")
@SuppressWarnings({"unlikely-arg-type", "CollectionIncompatibleType"})
boolean containsInt = list.contains(1); // should only contain JsonPrimitive(1)
assertFalse(containsInt);
}
Expand All @@ -227,7 +227,7 @@ public void testIndexOf() {
assertEquals(-1, list.indexOf(new JsonPrimitive(2)));
assertEquals(-1, list.indexOf(null));

@SuppressWarnings("unlikely-arg-type")
@SuppressWarnings({"unlikely-arg-type", "CollectionIncompatibleType"})
int indexOfInt = list.indexOf(1); // should only contain JsonPrimitive(1)
assertEquals(-1, indexOfInt);

Expand Down
Expand Up @@ -59,7 +59,7 @@ public void testContainsValue() {
assertFalse(map.containsValue(new JsonPrimitive(2)));
assertFalse(map.containsValue(null));

@SuppressWarnings("unlikely-arg-type")
@SuppressWarnings({"unlikely-arg-type", "CollectionIncompatibleType"})
boolean containsInt = map.containsValue(1); // should only contain JsonPrimitive(1)
assertFalse(containsInt);
}
Expand Down