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

Enable additional Error Prone checks & fix violations #2561

Conversation

Marcono1234
Copy link
Collaborator

@Marcono1234 Marcono1234 commented Dec 2, 2023

Purpose

Enable additional Error Prone checks which are disabled by default

Description

Some of them also enforce additional Google Java Format requirements which are not handled by google-java-format, such as disallowing wildcard imports.

Not all experimental checks have been listed because some are not applicable, such as Dependency Injection framework checks, or checks related to Guava's immutable collections (since Gson's main code does not have a dependency on Guava).

Other checks have been omitted because they are probably not relevant (this was a subjective choice), or would require larger refactoring or would flag issues with the public API, which cannot be changed easily.


Open questions:

  • Are some of the Error Prone checks too strict?
  • Should some of the checks be disabled for test code?
    Though might not be easily possible without separate testCompile configuration, which duplicates configuration, or without disabling all Error Prone checks for a certain file path. There are also the (undocumented?) flags -XepCompilingTestOnlyCode and -XepCompilingPubliclyVisibleCode, but it is not clear which checks consider them, and it would probably still be necessary to have a separate testCompile configuration then which sets these flags.

Checklist

  • New code follows the Google Java Style Guide
    This is automatically checked by mvn verify, but can also be checked on its own using mvn spotless:check.
    Style violations can be fixed using mvn spotless:apply; this can be done in a separate commit to verify that it did not cause undesired changes.
  • If necessary, new public API validates arguments, for example rejects null
  • New public API has Javadoc
    • Javadoc uses @since $next-version$
      ($next-version$ is a special placeholder which is automatically replaced during release)
  • If necessary, new unit tests have been added
    • Assertions in unit tests use Truth, see existing tests
    • No JUnit 3 features are used (such as extending class TestCase)
    • If this pull request fixes a bug, a new test was added for a situation which failed previously and is now fixed
  • mvn clean verify javadoc:jar passes without errors

Some of them also enforce additional Google Java Format requirements which
are not handled by google-java-format, such as disallowing wildcard imports.

Not all experimental checks have been listed because some are not applicable,
such as Dependency Injection framework checks, or checks related to Guava's
immutable collections (since Gson's main code does not have a dependency on
Guava).

Other checks have been omitted because they are probably not relevant
(this was a subjective choice), or would require larger refactoring or
would flag issues with the public API, which cannot be changed easily.
Comment on lines -214 to -215
default:
throw new IllegalArgumentException("Unexpected token" + reader.peek());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

switch covers all enum constants (this redundant default was flagged by Error Prone).

Copy link
Member

@eamonnmcmanus eamonnmcmanus left a comment

Choose a reason for hiding this comment

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

This is great. Thanks for all this work!

I did have a few minor comments.

Comment on lines -265 to -266
try {
// Invoke the ProtoClass.newBuilder() method
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is related to #2561 (comment).

I removed the inner try-catch because there is already an enclosing catch (Exception e) which wraps the exception in a JsonParseException, so this would probably have lead to JsonParseException -> JsonParseException -> actual exception.

(Compare this with whitespace diff turned off to properly see the changes.)

@eamonnmcmanus eamonnmcmanus merged commit 5187808 into google:main Jan 9, 2024
11 checks passed
@Marcono1234 Marcono1234 deleted the marcono1234/additional-error-prone-checks branch January 10, 2024 00:05
tibor-universe pushed a commit to getuniverse/gson that referenced this pull request Sep 14, 2024
* Enable additional Error Prone checks & fix violations

Some of them also enforce additional Google Java Format requirements which
are not handled by google-java-format, such as disallowing wildcard imports.

Not all experimental checks have been listed because some are not applicable,
such as Dependency Injection framework checks, or checks related to Guava's
immutable collections (since Gson's main code does not have a dependency on
Guava).

Other checks have been omitted because they are probably not relevant
(this was a subjective choice), or would require larger refactoring or
would flag issues with the public API, which cannot be changed easily.

* Address review feedback

---------

Co-authored-by: Éamonn McManus <[email protected]>
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.

2 participants