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

Introduce NestedPublishers check #642

Merged
merged 9 commits into from
Aug 14, 2023
Merged

Conversation

mohamedsamehsalah
Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah commented May 21, 2023

Bug checker that gives a warning when nested publishers are used.

Suggested commit message:

Introduce `NestedPublishers` check (#642)

@mohamedsamehsalah mohamedsamehsalah added this to the 0.12.0 milestone May 21, 2023
@github-actions
Copy link

Looks good. All 5 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.MonoOfPublishers 0 5

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@mohamedsamehsalah mohamedsamehsalah requested review from Stephan202, rickie and werli and removed request for werli May 22, 2023 06:43
@mohamedsamehsalah mohamedsamehsalah force-pushed the mohamedsamehsalah/mono-of-publishers branch from d6838c0 to a27838d Compare May 30, 2023 19:38
@github-actions
Copy link

  • Surviving mutants in this change: 1
  • Killed mutants in this change: 13
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.NestedPublishers 1 13

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Contributor Author

@mohamedsamehsalah mohamedsamehsalah left a 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

@github-actions
Copy link

Looks good. All 18 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.NestedPublishers 0 18

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

1 similar comment
@github-actions
Copy link

Looks good. All 18 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.NestedPublishers 0 18

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Contributor

@Venorcis Venorcis left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏻

@github-actions
Copy link

github-actions bot commented Jun 1, 2023

Looks good. All 18 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.NestedPublishers 0 18

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie force-pushed the mohamedsamehsalah/mono-of-publishers branch from 229226e to a654657 Compare June 7, 2023 14:00
Copy link
Member

@rickie rickie left a 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)

private static boolean isTypeArgumentGroupedFlux(
VisitorState state, @Nullable Type groupedFluxType, Type treeType) {
return groupedFluxType != null
&& treeType.getTypeArguments().stream()
Copy link
Member

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.

rickie

This comment was marked as duplicate.

rickie

This comment was marked as duplicate.

@rickie
Copy link
Member

rickie commented Jun 7, 2023

(Okay, there was an issue with my internet, I reviewed + approved twice all at once ????, sorry for that).

@github-actions
Copy link

github-actions bot commented Jun 7, 2023

  • Surviving mutants in this change: 1
  • Killed mutants in this change: 11
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.NestedPublishers 1 11

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 modified the milestones: 0.12.0, 0.13.0 Jun 21, 2023
@mohamedsamehsalah mohamedsamehsalah force-pushed the mohamedsamehsalah/mono-of-publishers branch from a654657 to c920892 Compare July 2, 2023 13:17
@mohamedsamehsalah
Copy link
Contributor Author

Rebased ✅

@github-actions
Copy link

github-actions bot commented Jul 2, 2023

Looks good. All 18 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.NestedPublishers 0 18

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@mohamedsamehsalah
Copy link
Contributor Author

mohamedsamehsalah commented Jul 16, 2023

Error:  Failed to execute goal on project documentation-support: Could not resolve dependencies for project tech.picnic.error-prone-support:documentation-support:jar:0.12.1-SNAPSHOT: Could not find artifact com.github.PicnicSupermarket.error-prone:error_prone_annotation:jar:v2.20.0-picnic-1 in jitpack.io (https://jitpack.io/)

Also getting this error locally 😬

Apparently this is happenning for all of the project's PR builds.

CC: @rickie

Resolved ✅

@mohamedsamehsalah mohamedsamehsalah force-pushed the mohamedsamehsalah/mono-of-publishers branch from 23bc818 to 10d4173 Compare July 22, 2023 21:14
@github-actions
Copy link

  • Surviving mutants in this change: 1
  • Killed mutants in this change: 11
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.NestedPublishers 1 11

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@rickie rickie left a 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 🚀 !

@rickie rickie force-pushed the mohamedsamehsalah/mono-of-publishers branch from 10d4173 to 4547ce9 Compare August 11, 2023 12:50
@github-actions
Copy link

  • Surviving mutants in this change: 1
  • Killed mutants in this change: 11
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.NestedPublishers 1 11

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@Stephan202 Stephan202 left a 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);
Copy link
Member

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()))));
Copy link
Member

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.)

Comment on lines 19 to 22
" // BUG: Diagnostic contains:",
" Mono.just(Mono.empty());",
" // BUG: Diagnostic contains:",
" Mono.just(Mono.just(1));",
Copy link
Member

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)
Copy link
Member

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) {
Copy link
Member

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}. */
Copy link
Member

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.

@github-actions
Copy link

Looks good. All 23 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.util.MoreMatchers 0 2
🎉tech.picnic.errorprone.bugpatterns.util.MoreTypePredicates 0 15
🎉tech.picnic.errorprone.bugpatterns.NestedPublishers 0 3
🎉tech.picnic.errorprone.bugpatterns.NestedOptionals 0 3

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Contributor

@Venorcis Venorcis left a comment

Choose a reason for hiding this comment

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

Still LGTM 👍🏻

@rickie rickie force-pushed the mohamedsamehsalah/mono-of-publishers branch from b4ce298 to 7b7987a Compare August 14, 2023 05:43
@github-actions
Copy link

Looks good. All 23 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.util.MoreMatchers 0 2
🎉tech.picnic.errorprone.bugpatterns.util.MoreTypePredicates 0 15
🎉tech.picnic.errorprone.bugpatterns.NestedPublishers 0 3
🎉tech.picnic.errorprone.bugpatterns.NestedOptionals 0 3

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@rickie rickie left a 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 🚀 !

@github-actions
Copy link

Looks good. All 23 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.util.MoreMatchers 0 2
🎉tech.picnic.errorprone.bugpatterns.util.MoreTypePredicates 0 15
🎉tech.picnic.errorprone.bugpatterns.NestedPublishers 0 3
🎉tech.picnic.errorprone.bugpatterns.NestedOptionals 0 3

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie force-pushed the mohamedsamehsalah/mono-of-publishers branch from ad7debd to de119dd Compare August 14, 2023 07:58
@rickie
Copy link
Member

rickie commented Aug 14, 2023

Rebased, will merge once 🟢.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

97.4% 97.4% Coverage
0.0% 0.0% Duplication

@github-actions
Copy link

Looks good. All 23 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.util.MoreMatchers 0 2
🎉tech.picnic.errorprone.bugpatterns.util.MoreTypePredicates 0 15
🎉tech.picnic.errorprone.bugpatterns.NestedPublishers 0 3
🎉tech.picnic.errorprone.bugpatterns.NestedOptionals 0 3

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie merged commit 4af7b21 into master Aug 14, 2023
@rickie rickie deleted the mohamedsamehsalah/mono-of-publishers branch August 14, 2023 08:30
@Stephan202 Stephan202 changed the title Introduce NestedPublishers bug check Introduce NestedPublishers check Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants