Skip to content

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

Merged
merged 2 commits into from
Dec 9, 2019
Merged

Set firebase-database to -Werror #1030

merged 2 commits into from
Dec 9, 2019

Conversation

inlined
Copy link
Member

@inlined inlined commented Dec 3, 2019

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.

Copy link
Member Author

@inlined inlined left a 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'
Copy link
Member Author

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);
Copy link
Member Author

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(
Copy link
Member Author

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);
Copy link
Member Author

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;
Copy link
Member Author

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";
Copy link
Member Author

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 =
Copy link
Member Author

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)
Copy link
Member Author

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(),
Copy link
Member Author

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<>();
Copy link
Member Author

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)

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a 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)
Copy link
Contributor

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?

Copy link
Member Author

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?

@schmidt-sebastian schmidt-sebastian removed their assignment Dec 3, 2019
@schmidt-sebastian
Copy link
Contributor

Annotations for the first case of every type of warning/error I fixed

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());

Choose a reason for hiding this comment

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

Suggested change
Long drift = System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString());
long drift = System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString());

Copy link
Member Author

Choose a reason for hiding this comment

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

Good cleanup

Comment on lines +38 to +40
int result = repoInfo.hashCode();
result = 31 * result + path.hashCode();
return result;

Choose a reason for hiding this comment

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

Suggested change
int result = repoInfo.hashCode();
result = 31 * result + path.hashCode();
return result;
return 31 * repoInfo.hashCode() + path.hashCode();

Copy link
Member Author

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;

Choose a reason for hiding this comment

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

Suggested change
private static final double EPISLON = 0.00025f;
private static final double EPSILON = 0.00025f;

Copy link
Member Author

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(),

Choose a reason for hiding this comment

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

Suggested change
getApplicationContext(),
ApplicationProvider.getApplicationContext(),

Copy link
Member Author

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(),

Choose a reason for hiding this comment

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

Suggested change
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(),

Choose a reason for hiding this comment

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

Suggested change
getApplicationContext(),
ApplicationProvider.getApplicationContext(),

Copy link
Member Author

@inlined inlined left a 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());
Copy link
Member Author

Choose a reason for hiding this comment

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

Good cleanup

Comment on lines +38 to +40
int result = repoInfo.hashCode();
result = 31 * result + path.hashCode();
return result;
Copy link
Member Author

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(),
Copy link
Member Author

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;
Copy link
Member Author

Choose a reason for hiding this comment

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

Good typo catch.

@google-oss-bot
Copy link
Contributor

@inlined: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
api-information 17e511c link /test api-information

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.

@inlined
Copy link
Member Author

inlined commented Dec 9, 2019

Ignoring the api-information test failure. It seems like all pull requests have failed :firebase-common:ktx:apiInformation since #1041.

@inlined inlined merged commit 00956bc into master Dec 9, 2019
@firebase firebase locked and limited conversation to collaborators Jan 9, 2020
@kaibolay kaibolay deleted the inlined.lint branch September 14, 2022 17:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Override cla size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants