-
Notifications
You must be signed in to change notification settings - Fork 616
Set firebase-database to -Werror #1030
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotations for the first case of every type of warning/error I fixed
androidTestImplementation 'net.java:quickcheck:0.6' | ||
androidTestAnnotationProcessor 'net.java:quickcheck-src-generator:0.6' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These annotations were not used and caused conflicts because their maximum version is 1.6
@@ -710,7 +712,7 @@ public boolean isComplete(List<EventRecord> events) { | |||
try { | |||
ref.child("two").removeValue(); | |||
} catch (DatabaseException e) { | |||
fail("Should not fail"); | |||
throw new AssertionError("Should not fail", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errorprone calls catch-then-fail an anti-pattern. AssertionError is an unchecked exception that can wrap any other throwable to preserve cause and stack traces.
@@ -2346,9 +2348,8 @@ public void onComplete(DatabaseError error, DatabaseReference ref) { | |||
assertEquals(snap.getPriority().getClass(), Double.class); | |||
assertEquals(snap.getPriority(), snap.child("b").getPriority()); | |||
assertEquals(snap.child("a").getValue(), snap.child("b").getValue()); | |||
assert (Math.abs( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert is a production method, not a test method
@@ -623,15 +626,15 @@ public void onDataChange(DataSnapshot snapshot) { | |||
try { | |||
IntegrationTestHelpers.waitFor(blockSem); | |||
} catch (InterruptedException e) { | |||
e.printStackTrace(); | |||
LOGGER.log(WARNING, "unexpected error", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll admit I don't fully understand why printStackTrace()
is considered an anti-pattern. I'm assuming it's because we should be printing to logcat rather than stdout.
@@ -20,8 +20,8 @@ | |||
import static org.junit.Assert.assertSame; | |||
import static org.junit.Assert.fail; | |||
|
|||
import androidx.test.InstrumentationRegistry; | |||
import androidx.test.runner.AndroidJUnit4; | |||
import androidx.test.ext.junit.runners.AndroidJUnit4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These libraries moved
@@ -1243,8 +1245,7 @@ public void beanMapsMustHaveStringKeys() { | |||
|
|||
@Test | |||
public void serializeStringBean() { | |||
StringBean bean = new StringBean(); | |||
bean.value = "foo"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct member access was disallowed. I had the choice of adding a setValue or just a constructor that accepted a value.
@@ -1380,54 +1380,28 @@ public void serializingListsWorks() { | |||
@Test | |||
public void serializingMapsWorks() { | |||
MapBean bean = new MapBean(); | |||
bean.values = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter list initialization is disallowed because it leads to memory issues. We can use the ImmutableFoo.of methods in unit tests or the ImmutableFoo builders in code with a lower target JRE version.
@@ -151,8 +150,8 @@ private final void doTestEquivalanceGroupOrdering() { | |||
testClassCast(reference); | |||
for (int otherIndex = 0; otherIndex < equalityGroups.size(); otherIndex++) { | |||
for (Object other : equalityGroups.get(otherIndex)) { | |||
assertThat(Integer.signum(compare(reference, other))) | |||
.named("compare(%s, %s)", reference, other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .named
method is deprecated. We're instead supposed to assertWithMessage
.
assertWithMessage( | ||
"Testing equals() for compatibility with compare()/compareTo(), " | ||
+ "add a call to doNotRequireEqualsCompatibility() if this is not required") | ||
// Testing equals() for compatibility with compare()/compareTo(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per above, I had to use only assertWithMessage, not .named
I kept the printf text formerly in .named
and moved the other message to a comment to avoid losing information.
@@ -99,7 +100,7 @@ private static boolean weakTypeMatch(Object a, Object b) { | |||
} | |||
|
|||
private static boolean deepEquals(Object a, Object b, Set visited) { | |||
LinkedList<DualKey> stack = new LinkedList<DualKey>(); | |||
Deque<DualKey> stack = new ArrayDeque<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LinkedList
is generally prohibited because it almost never outperforms an ArrayList
(there's a great C++ talk from Meyers on this; std::linked_list performs worse than std::vector for random operations and the gap actually increases as the list size increases. Memory locality is more important than O-notation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much!
+ "add a call to doNotRequireEqualsCompatibility() if this is not required") | ||
// Testing equals() for compatibility with compare()/compareTo(), | ||
// add a call to doNotRequireEqualsCompatibility() if this is not required | ||
assertWithMessage("%s.equals(%s)", reference, other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Should the message have quotes around %s
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL. you just couldn't let me have a clean review, eh?
Awesome :) Thank you! |
* Set compile options to -Werror * Fix all build breaks
assert (Math.abs( | ||
System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString())) | ||
< 2000); | ||
Long drift = System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long drift = System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString()); | |
long drift = System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good cleanup
int result = repoInfo.hashCode(); | ||
result = 31 * result + path.hashCode(); | ||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int result = repoInfo.hashCode(); | |
result = 31 * result + path.hashCode(); | |
return result; | |
return 31 * repoInfo.hashCode() + path.hashCode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been too many years since I've been in school to remember the name of the notation but writing
AX^N + BX^(N-1) + CX^(N-2)...YX^1 + Z as
((((A)X + B)X + C)X + D)...
is a much very common factorization for hashes and checksums because it forms a pattern that works incrementally as the input increase. Keeping the pattern.
@@ -37,11 +37,17 @@ | |||
@org.junit.runner.RunWith(RobolectricTestRunner.class) | |||
@Config(manifest = Config.NONE) | |||
public class MapperTest { | |||
private static final double EPISLON = 0.00001f; | |||
private static final double EPISLON = 0.00025f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static final double EPISLON = 0.00025f; | |
private static final double EPSILON = 0.00025f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good typo catch.
@@ -41,7 +41,7 @@ public void getComponents_publishesLibVersionComponent() { | |||
|
|||
private static FirebaseApp appForDatabaseUrl(String url, String name) { | |||
return FirebaseApp.initializeApp( | |||
RuntimeEnvironment.application.getApplicationContext(), | |||
getApplicationContext(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getApplicationContext(), | |
ApplicationProvider.getApplicationContext(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The public Google style guide only states that static methods should be referenced from a class and not a variable. The Google employee style guide is stricter and enforces this by requiring static methods to be statically imported.
@@ -289,7 +289,7 @@ public static void ensureAppInitialized() { | |||
if (!appInitialized) { | |||
appInitialized = true; | |||
FirebaseApp.initializeApp( | |||
RuntimeEnvironment.application.getApplicationContext(), | |||
getApplicationContext(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getApplicationContext(), | |
ApplicationProvider.getApplicationContext(), |
@@ -59,7 +59,7 @@ public void getDifferentInstanceForAppWithUrl() { | |||
|
|||
private static FirebaseApp appForDatabaseUrl(String url, String name) { | |||
return FirebaseApp.initializeApp( | |||
RuntimeEnvironment.application.getApplicationContext(), | |||
getApplicationContext(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getApplicationContext(), | |
ApplicationProvider.getApplicationContext(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the drive-by sanity check @PromanSEW
assert (Math.abs( | ||
System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString())) | ||
< 2000); | ||
Long drift = System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good cleanup
int result = repoInfo.hashCode(); | ||
result = 31 * result + path.hashCode(); | ||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been too many years since I've been in school to remember the name of the notation but writing
AX^N + BX^(N-1) + CX^(N-2)...YX^1 + Z as
((((A)X + B)X + C)X + D)...
is a much very common factorization for hashes and checksums because it forms a pattern that works incrementally as the input increase. Keeping the pattern.
@@ -41,7 +41,7 @@ public void getComponents_publishesLibVersionComponent() { | |||
|
|||
private static FirebaseApp appForDatabaseUrl(String url, String name) { | |||
return FirebaseApp.initializeApp( | |||
RuntimeEnvironment.application.getApplicationContext(), | |||
getApplicationContext(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The public Google style guide only states that static methods should be referenced from a class and not a variable. The Google employee style guide is stricter and enforces this by requiring static methods to be statically imported.
@@ -37,11 +37,17 @@ | |||
@org.junit.runner.RunWith(RobolectricTestRunner.class) | |||
@Config(manifest = Config.NONE) | |||
public class MapperTest { | |||
private static final double EPISLON = 0.00001f; | |||
private static final double EPISLON = 0.00025f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good typo catch.
@inlined: The following test failed, say
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Ignoring the |
As a bar-raising experiment, I added -Werror to our compilation options. This broke the build; fixes are also included in this change. With this update, compiler warnings (most importantly, errorprone warnings) will not be allowed into future pull requests. Hopefully this will catch a bug or two before our customers do.