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

Update to Error Prone 2.3.2 #242

Merged
merged 5 commits into from
Oct 15, 2018
Merged

Update to Error Prone 2.3.2 #242

merged 5 commits into from
Oct 15, 2018

Conversation

msridhar
Copy link
Collaborator

Only a few fixes required.

I had to disable analysis of generated code since AutoValue-generated code doesn't pass the UnnecessaryParentheses check. I tried updating AutoValue to fix this, and decided to keep the update.

Copy link
Collaborator

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

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

LGTM

@lazaroclapp
Copy link
Collaborator

Actually, I don't get why the tests are failing. It seems to be something about IllegalAccessError in this line: compilationHelper = CompilationTestHelper.newInstance(NullAway.class, getClass());

But, even on the current error-prone master, that method is public.

@msridhar
Copy link
Collaborator Author

msridhar commented Oct 11, 2018 via email

@msridhar
Copy link
Collaborator Author

@lazaroclapp @subarnob what is going with passing -cp here?

"-cp",
"../jar-infer/test-java-lib-jarinfer/build/libs/test-java-lib-jarinfer.jar"))

I wonder if it's breaking these tests with this update by overriding the test classpath.

@lazaroclapp
Copy link
Collaborator

lazaroclapp commented Oct 11, 2018

@lazaroclapp @subarnob what is going with passing -cp here?

NullAway/nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java

Lines 1078 to 1079 in 237a6ef

"-cp",
"../jar-infer/test-java-lib-jarinfer/build/libs/test-java-lib-jarinfer.jar"))
I wonder if it's breaking these tests with this update by overriding the test classpath.

Not entirely sure.

This is already a test dependency for nullaway: https://github.com/uber/NullAway/blob/master/nullaway/build.gradle#L57 But removing the -cp argument causes the tests to fail with missing errors.

I believe the code that scans for jars with models here: https://github.com/uber/NullAway/blob/master/nullaway/src/main/java/com/uber/nullaway/handlers/InferredJARModelsHandler.java#L110 looks at the -cp (or similar) option of the javac command, and can't see the way in which CompilationTestHelper makes the outer classpath available, hence the requirement to explicitly add that jar on the javac command.

@msridhar
Copy link
Collaborator Author

I believe the code that scans for jars with models here: https://github.com/uber/NullAway/blob/master/nullaway/src/main/java/com/uber/nullaway/handlers/InferredJARModelsHandler.java#L110 looks at the -cp (or similar) option of the javac command, and can't see the way in which CompilationTestHelper makes the outer classpath available, hence the requirement to explicitly add that jar on the javac command.

Can we do something like this trick to avoid looking at -cp?

@lazaroclapp
Copy link
Collaborator

I believe the code that scans for jars with models here: https://github.com/uber/NullAway/blob/master/nullaway/src/main/java/com/uber/nullaway/handlers/InferredJARModelsHandler.java#L110 looks at the -cp (or similar) option of the javac command, and can't see the way in which CompilationTestHelper makes the outer classpath available, hence the requirement to explicitly add that jar on the javac command.

Can we do something like this trick to avoid looking at -cp?

👍 Oh, nice find!

It seems to work, at least as far as NullAway's own tests are concerned. See #243 . I'd still like to test this a bit internally before merging that PR, though :)

@msridhar
Copy link
Collaborator Author

Ok, cool, once #243 is merged I'll rebase on that and hopefully we'll be good to go with this one

build.gradle Outdated
@@ -37,6 +37,8 @@ subprojects { project ->
"-Xlint:unchecked",
"-Xlint:rawtypes",
"-Werror",
// don't analyze generated code; AutoValue code fails UnnecessaryParentheses check
"-XepExcludedPaths:.*/build/classes/.*",
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for not using -XepDisableWarningsInGeneratedCode instead?

Also, does that mean that AutoValue-generated sources end up into build/classes? You may want to set options.annotationProcessorGeneratedSourcesDirectory on JavaCompile tasks to put them somewhere else so they're not packaged into the JAR. Fwiw, net.ltgt.apt will do that for you 😉
(I checked, and indeed nulaway-0.6.0.jar contains AUtoValue-generated sources)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need this since we use -Werror, and -XepDisableWarningsInGeneratedCode only disables warnings.

Nice tip on sources ending up in the final artifact! I opened #245 on fixing.

Copy link
Contributor

Choose a reason for hiding this comment

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

-XepDisableWarningsInGeneratedCode happens before warnings are emitted, so -Werror won't change the outcome (vs excluded paths), and it helps catch Error Prone errors.

Choose a reason for hiding this comment

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

@msridhar we have a similar setup and combine those two flags with -XepAllErrorsAsWarnings. That way there are no warnings (nor errors) in generated code, while both warnings and errors in the rest of the code base fail the build.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the tips! I've fixed here to use -XepDisableWarningsInGeneratedCode. And @Stephan202 that's a neat trick! Will keep it in mind for future projects.

@@ -240,7 +240,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof AccessPath)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Fwiw, you could also mark the class as final.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like the instanceof check better anyway, but I'll also make the class final.

@msridhar msridhar merged commit 81aba29 into master Oct 15, 2018
@msridhar msridhar deleted the ms/ep-2.3.2 branch October 15, 2018 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants