Skip to content

Fix error prone warnings#2316

Merged
eamonnmcmanus merged 26 commits into
google:masterfrom
MaicolAntali:fix-error-prone-warns
Feb 15, 2023
Merged

Fix error prone warnings#2316
eamonnmcmanus merged 26 commits into
google:masterfrom
MaicolAntali:fix-error-prone-warns

Conversation

@MaicolAntali
Copy link
Copy Markdown
Contributor

In this PR I have fixed some ErrorProne warns.

I have also add the flag -XepExcludedPaths: to the ErrorProne plugin to exclude tests and proto path

Copy link
Copy Markdown
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.

Thanks for doing this!

Comment thread extras/src/main/java/com/google/gson/graph/GraphAdapterBuilder.java
Comment thread extras/src/main/java/com/google/gson/graph/GraphAdapterBuilder.java Outdated
Comment thread gson/src/main/java/com/google/gson/Gson.java Outdated
Comment thread gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java Outdated
Comment thread gson/src/main/java/com/google/gson/stream/JsonWriter.java Outdated
Comment thread pom.xml
<!-- Args related to Error Prone, see: https://errorprone.info/docs/installation#maven -->
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
<arg>-Xplugin:ErrorProne -XepExcludedPaths:.*gson/src/test.*|.*extras/src/test.*|.*proto.*</arg>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Eventually we might want to have the tests pass Error Prone too, but I agree that is a much lower priority.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

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

Sorry to bring this up again, but would you mind fixing (respectively removing) the incorrect @SuppressWarnings("TruthSelfEquals") suppressions as mentioned in https://github.com/google/gson/pull/2308/files#r1096471723 (simply change it to a.equals(a) for now)? The warnings are true-positives; regardless of whether guava-testlib will be added in the future, the current test code on master is incorrect and the @SuppressWarnings hide that, suggesting the code is correct.

My concern is that we forget about this, or for whatever reason guava-testlib is not integrated, and in that case the incorrect code remains unnoticed.

Comment thread pom.xml
<!-- Args related to Error Prone, see: https://errorprone.info/docs/installation#maven -->
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
<arg>-Xplugin:ErrorProne -XepExcludedPaths:.*gson/src/test.*|.*extras/src/test.*|.*proto.*</arg>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it intended that you disable warnings for the complete proto module? Maybe it would be better to only disable warnings for the generated source code, as suggested in #2308 (comment).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm going to go ahead and merge this anyway, but we could indeed consider refining the pattern here.

Copy link
Copy Markdown
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.

I'm merging this snapshot under the assumption that if there are further changes in the pipeline they can just be applied in a followup PR.

Comment thread pom.xml
<!-- Args related to Error Prone, see: https://errorprone.info/docs/installation#maven -->
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
<arg>-Xplugin:ErrorProne -XepExcludedPaths:.*gson/src/test.*|.*extras/src/test.*|.*proto.*</arg>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm going to go ahead and merge this anyway, but we could indeed consider refining the pattern here.

@eamonnmcmanus eamonnmcmanus changed the title Fix error prone warns Fix error prone warnings Feb 15, 2023
@eamonnmcmanus eamonnmcmanus merged commit 2658aca into google:master Feb 15, 2023
@MaicolAntali MaicolAntali deleted the fix-error-prone-warns branch February 15, 2023 15:07
tibor-universe pushed a commit to getuniverse/gson that referenced this pull request Sep 14, 2024
* Fix `OperatorPrecedence` warn in `JsonWriter#close`

* Fix `ReferenceEquality` warn in `LinkedTreeMap#replaceInParent`

* Fix `UnnecessaryParentheses` warn in `LinkedTreeMap#replaceInParent`

* Fix `ReferenceEquality` warn in `LinkedTreeMap#hasNext`

* Fix `ReferenceEquality` warn in `LinkedTreeMap#nextNode`

* Adds `error_prone_annotations` to the `pom.xml` of `gson`

* Fix `InlineMeSuggester` warns in `JsonParser`

* Fix `UnnecessaryParentheses` warns in `ConstructorConstructor#newDefaultImplementationConstructor`

* Fix `ThreadLocalUsage` warn in `Gson`

* Fix `JdkObsolete` warn in `GsonBuilder`

* Fix `ReferenceEquality` warn in `LazilyParsedNumber#equals`

* Fix `OperatorPrecedence` warn in `TreeTypeAdapter#create`

* Fix `OperatorPrecedence` warn in `ArrayTypeAdapter`

* Fix `UnnecessaryParentheses` warn in `TypeAdapters`

* Adds `-XepExcludedPaths` flag to ErrorProne plugin to exclude tests and proto path

* Fix `ClassNewInstance` warn in `InterceptorAdapter`

* Fix `ThreadLocalUsage` warn in `GraphAdapterBuilder`

* Fix `JdkObsolete` warn in `GraphAdapterBuilder`

* Revert "Adds `error_prone_annotations` to the `pom.xml` of `gson`"

This reverts commit 14af14d.

* Revert "Fix `InlineMeSuggester` warns in `JsonParser`"

This reverts commit 095bfd5.

* Adds `@SuppressWarnings("ThreadLocalUsage")`

* Fix `OperatorPrecedence` in `JsonWriter`

* Revert "Fix `ReferenceEquality` warn in `LinkedTreeMap#nextNode`"

This reverts commit 387746c.

* Adds `@SuppressWarnings("ReferenceEquality")`

* Adds `guava-testlib` to the gson `pom.xml`

* `@SuppressWarnings("TruthSelfEquals")` removed to use `EqualsTester()`
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