-
Notifications
You must be signed in to change notification settings - Fork 39
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
Introduce NestedPublishers
check
#642
Conversation
error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java
Outdated
Show resolved
Hide resolved
Looks good. All 5 mutations in this change were killed.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MonoOfPublishers.java
Outdated
Show resolved
Hide resolved
d6838c0
to
a27838d
Compare
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposal from pair-programming session with @rickie
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java
Outdated
Show resolved
Hide resolved
Looks good. All 18 mutations in this change were killed.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
1 similar comment
Looks good. All 18 mutations in this change were killed.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏻
error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedPublishersTest.java
Outdated
Show resolved
Hide resolved
Looks good. All 18 mutations in this change were killed.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
229226e
to
a654657
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased and added a commit.
Nice changes @mohamedsamehsalah 😄, let's get your first BugPattern merged 💪🏻!
Thanks for the review @Venorcis 💪🏻 !
Suggested commit message:
Introduce `NestedPublishers` check (#642)
error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedPublishersTest.java
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java
Outdated
Show resolved
Hide resolved
private static boolean isTypeArgumentGroupedFlux( | ||
VisitorState state, @Nullable Type groupedFluxType, Type treeType) { | ||
return groupedFluxType != null | ||
&& treeType.getTypeArguments().stream() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can assume that Publisher
has only one type, so we can use something like Iterables#getONlyElement
here :)
So we should either do:
isSubType(type.getTypeArguments().get(0), GROUPED_FLUX.get(state), state)
// or
isSubType(Iterables.getOnlyElement(type.getTypeArguments()), GROUPED_FLUX.get(state), state)
// or have:
List<Type> typeArguments = type.getTypeArguments();
....
isSubType(typeArguments.get(0), GROUPED_FLUX.get(state), state)
Not sure what the best option is though.... Will push a suggestion but feel free to change.
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java
Show resolved
Hide resolved
(Okay, there was an issue with my internet, I reviewed + approved twice all at once ????, sorry for that). |
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
a654657
to
c920892
Compare
Rebased ✅ |
Looks good. All 18 mutations in this change were killed.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
Resolved ✅ |
23bc818
to
10d4173
Compare
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late re-approve but it looks goood! ✅
Thanks @mohamedsamehsalah 🚀 !
10d4173
to
4547ce9
Compare
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a commit with quite some changes; consider re-reviewing :)
Suggested commit message:
Introduce `NestedPublishers` check (#642)
And introduce a few utility methods that simplify `Tree`- and `Type`-based
matching, allowing the existing (and similar) `NestedOptionals` check to be
simplified as well.
} | ||
|
||
private static boolean isSubType(Type subType, @Nullable Type type, VisitorState state) { | ||
return type != null && state.getTypes().isSubtype(subType, type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can deduplicate the null
check by pulling it up. That also prevents IDEA from warning about the type.getTypeArguments()
call.
That said, in practice (see e.g. NestedOptionals
) we often omit this null
check, so apparently it's redundant. Omitting has the benefit that Pitest won't complain. (But then of IDEA will still complain. Trade-off.)
Another way to make sure that the null
check doesn't need to be performed explicitly, is by using ASTHelpers.isSubtype
. Unfortunately that method performs type erasure, which makes it unsuitable. That's actually quite a gotcha, which also impacts Matchers#isSubtypeOf(Supplier)
. What I'd like to do is define a corresponding MoreMatchers
variant; then we can also further simplify NestedOptionals
.
private static final long serialVersionUID = 1L; | ||
private static final Supplier<Type> PUBLISHER = type("org.reactivestreams.Publisher"); | ||
private static final Supplier<Type> PUBLISHER_OF_PUBLISHERS = | ||
VisitorState.memoize(generic(PUBLISHER, subOf(generic(PUBLISHER, unbound())))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also match raw inner publishers, just like in NestedOptionals
. Likewise below. (And then update the tests to cover these cases.)
" // BUG: Diagnostic contains:", | ||
" Mono.just(Mono.empty());", | ||
" // BUG: Diagnostic contains:", | ||
" Mono.just(Mono.just(1));", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can drop a few of these tests, since they produce exactly the same type of expression.
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { | ||
Type type = ASTHelpers.getType(tree); | ||
|
||
if (!isSubType(type, PUBLISHER_OF_PUBLISHERS.get(state), state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PUBLISHER_OF_PUBLISHERS.get(state)
can be null
, causing an NPE. See NestedOptionalsTest#identificationOptionalTypeNotLoaded()
for a similar case.
public NestedPublishers() {} | ||
|
||
@Override | ||
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also holds for NestedOptionals
): next to method invocations we should perhaps also flag e.g. return types and variable types. 🤔 Perhaps we can keep it out of scope for this PR by only adding an XXX
comment. After all, most (but not all) such definitions would involve a method invocation of the same type.
import org.jspecify.annotations.Nullable; | ||
import org.reactivestreams.Publisher; | ||
|
||
/** A {@link BugChecker} that flags nesting of {@link Publisher Publishers}. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call out the GroupedFlux
exclusion.
Looks good. All 23 mutations in this change were killed.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still LGTM 👍🏻
b4ce298
to
7b7987a
Compare
Looks good. All 23 mutations in this change were killed.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a tiny Javadoc tweak. Really nice changes, we'll be able to use this in many more future cases 🚀 !
Looks good. All 23 mutations in this change were killed.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
ad7debd
to
de119dd
Compare
Rebased, will merge once 🟢. |
Kudos, SonarCloud Quality Gate passed! |
Looks good. All 23 mutations in this change were killed.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
NestedPublishers
bug checkNestedPublishers
check
Bug checker that gives a warning when nested publishers are used.
Suggested commit message: