Skip to content

Add Error Prone static analysis - #2634

Open
vlsi wants to merge 1 commit into
assertj:3.xfrom
vlsi:errorprone
Open

vlsi wants to merge 1 commit into
assertj:3.xfrom
vlsi:errorprone

Conversation

@vlsi

@vlsi vlsi commented May 29, 2022

Copy link
Copy Markdown
Contributor

Error Prone has good patterns, and it prints good messages.

See https://errorprone.info/bugpatterns

Sample output:

[ERROR] /../assertj-core/src/main/java/org/assertj/core/api/AtomicReferenceArrayAssert.java:[2083,29] [CheckReturnValue] Ignored return value of 'usingElementComparator', which is annotated with @CheckReturnValue
[ERROR]     (see https://errorprone.info/bugpattern/CheckReturnValue)
[ERROR] /../assertj-core/src/main/java/org/assertj/core/internal/Paths.java:[438,3] [MethodCanBeStatic] A private method that does not reference the enclosing instance can be static
[ERROR]     (see https://errorprone.info/bugpattern/MethodCanBeStatic)
[ERROR]   Did you mean 'private static List<Path> sortedRecursiveContent(Path path) {'?

Check List:

Following the contributing guidelines will make it easier for us to review and accept your PR.

Error Prone has good patterns, and it prints good messages.

See https://errorprone.info/bugpatterns
@vlsi

vlsi commented May 29, 2022

Copy link
Copy Markdown
Contributor Author

@joel-costigliola

Copy link
Copy Markdown
Member

Interesting @vlsi! the team needs to have a look at the rules but looks promising

@joel-costigliola joel-costigliola added the status: team discussion An issue we'd like to discuss as a team to make progress label May 30, 2022
@joel-costigliola joel-costigliola added this to the 3.24.0 milestone May 30, 2022
@vlsi

vlsi commented May 30, 2022

Copy link
Copy Markdown
Contributor Author

Of course, I don't suggest enabling and fixing all the bug patterns, however, I believe the errors produced by the default configuration should be fixed.

Even some of the "warnings by default" are worth fixing as well.

For instance:

  1. https://github.com/assertj/assertj-core/blob/b44460623b9c0e83c2b311c1fc6b7bffa1a077b9/src/main/java/org/assertj/core/description/TextDescription.java#L54-L56
Error:  /../assertj-core/assertj-core/src/main/java/org/assertj/core/description/TextDescription.java:[56,24] [ArrayHashCode] hashcode method on array does not hash array contents
    (see https://errorprone.info/bugpattern/ArrayHashCode)
  Did you mean 'return Objects.hash(value, Arrays.hashCode(args));'?
  1. https://github.com/assertj/assertj-core/blob/8a70b403490ba5799fc06b90dc8096c729b4da0e/src/main/java/org/assertj/core/internal/Iterables.java#L1315-L1321
Error:  /../assertj-core/assertj-core/src/main/java/org/assertj/core/internal/Iterables.java:[1321,31] [ReturnValueIgnored] Return value of 'orElseThrow' must be used
    (see https://errorprone.info/bugpattern/ReturnValueIgnored)

it might be questionable, however, I believe Stream.anyMatch would indeed be better:

    if (stream(actual).anyMatch(predicate)) {
      throw failures.failure(info, anyElementShouldMatch(actual, predicateDescription));
    }

I remembered errorprone because it can detect MethodCanBeStatic (it verifies the method is private, so it does not break backward compatibility).


Then, there's https://github.com/palantir/assertj-automation which you might want to apply and promote :)

@vlsi

vlsi commented May 30, 2022 •

Copy link
Copy Markdown
Contributor Author

@joel-costigliola , one more question: for now, I include errorprone Maven plugin right into assertj-core, however, you might want to add it to the base configuration (https://github.com/assertj/assertj-parent-pom ?)

In my experience, the mere presence of assertj/assertj-parent-pom creates too much friction since Maven does not support cross-repository changes. I can't really have a pull request that would change assertj-parent-pom and apply the changed assertj-parent-pom into assertj-core.

We had the exact same issue with https://github.com/pgjdbc/pgjdbc-parent-poms when the PostgreSQL JDBC driver was Maven-based. Moving to Gradle was a huge relief so we could keep all the things in a single repository.


Even if you keep multiple repositories (e.g. keep assertj-core, assertj-parent-whatever, etc), Gradle makes it possible to use tools like https://melix.github.io/includegit-gradle-plugin/ when you can have local testing and even pull requests that cross repository bounds: https://twitter.com/CedricChampeau/status/1499019789033000962


Of course, I would yield to the team's decision, however, I strongly believe tools like ErrorProne, Cherckerframework, AutoStyle would improve contributor and developer experience.
At the same time, Maven makes many of those improvements impossible or extremely hard.

@vlsi vlsi mentioned this pull request May 30, 2022
@scordio

scordio commented May 30, 2022

Copy link
Copy Markdown
Member

I can't really have a pull request that would change assertj-parent-pom and apply the changed assertj-parent-pom into assertj-core.

We had the exact same issue with https://github.com/pgjdbc/pgjdbc-parent-poms when the PostgreSQL JDBC driver was Maven-based. Moving to Gradle was a huge relief so we could keep all the things in a single repository.

Personally, I don't see how this is related to Maven. What you're mentioning is a multi-module setup, something we already plan to tackle in #2424. Even if we would switch to Gradle, most likely we would target the same setup.

I agree Gradle would allow multi-repository development but IMHO the fact that it's possible doesn't necessarily mean it's the direction we should take.

@scordio scordio modified the milestones: 3.24.0, 3.25.0 Dec 26, 2022
@scordio
scordio force-pushed the main branch 2 times, most recently from 38c7b4b to 3cde5bf Compare July 20, 2023 15:20
@scordio scordio modified the milestones: 3.25.0, 3.26.0 Sep 13, 2023
@scordio scordio modified the milestones: 3.26.0, 3.27.0 Apr 9, 2024
@scordio
scordio force-pushed the 3.x branch 2 times, most recently from 301ca01 to c730d18 Compare June 1, 2024 16:04
@scordio scordio modified the milestones: 3.27.0, 3.28.0 Nov 25, 2024
@scordio scordio modified the milestones: 3.28.0, 4.0.0-M1 Jan 3, 2025
@scordio scordio modified the milestones: 4.0.0-M1, 4.0.0-M2 Jan 31, 2025
@joel-costigliola joel-costigliola removed this from the 4.0.0-M2 milestone Jul 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: team discussion An issue we'd like to discuss as a team to make progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants