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 ExplicitArgumentEnumeration check #985

Merged
merged 7 commits into from
Dec 16, 2024

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented Jan 21, 2024

Suggested commit message:

Introduce `ExplicitArgumentEnumeration` check (#985)

I found this on an old branch from early last year. Extended it a bit and now putting it up for review. Perhaps we can find a better name. Likely this code should also be tested against the internal code base before landing. But it's certainly ready for review.

@Stephan202 Stephan202 added this to the 0.15.0 milestone Jan 21, 2024
Copy link

  • Surviving mutants in this change: 9
  • Killed mutants in this change: 37
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 9 37

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

Copy link

  • Surviving mutants in this change: 10
  • Killed mutants in this change: 38
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 10 38

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

Copy link
Member Author

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

(I see there a more mutants to be handled; will review in the ~coming days.)

Comment on lines 196 to 199
// XXX: Once we target JDK 14+, drop this method in favour of `Symbol#isPublic()`.
private static boolean isPublic(Symbol symbol) {
return symbol.getModifiers().contains(Modifier.PUBLIC);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Also present in #972, but a separate utility method doesn't seem worth it. (Or we can just drop JDK 11 support 🙃.)

@rickie rickie modified the milestones: 0.15.0, 0.16.0 Feb 10, 2024
@Stephan202 Stephan202 force-pushed the sschroevers/prefer-varargs-alternatives branch from d3877c5 to a74fd35 Compare February 10, 2024 15:29
Copy link

  • Surviving mutants in this change: 10
  • Killed mutants in this change: 38
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 10 38

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

@Stephan202 Stephan202 force-pushed the sschroevers/prefer-varargs-alternatives branch from a74fd35 to 9e7ac68 Compare February 11, 2024 15:15
Copy link

  • Surviving mutants in this change: 10
  • Killed mutants in this change: 38
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 10 38

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

@Stephan202 Stephan202 force-pushed the sschroevers/prefer-varargs-alternatives branch from 9e7ac68 to 714713b Compare February 11, 2024 20:15
Copy link
Member Author

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

Rebased and added a commit with some improvements. I think this is now properly ready for review.

Comment on lines 104 to 109
if (tree.getArguments().size() != 1) {
return Description.NO_MATCH;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Pitest reports that this if-statement can be mutated away. That's correct: it's a performance optimization. While we haven't done so in the past, it may be good to start documenting such cases. Will do for this case.

Comment on lines +125 to +132
private static boolean isUnaryIterableAcceptingMethod(MethodSymbol method, VisitorState state) {
List<VarSymbol> params = method.params();
return !method.isVarArgs()
&& params.size() == 1
&& ASTHelpers.isSubtype(params.get(0).type, state.getSymtab().iterableType, state);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Pitest flags that the params.size() == 1 can be mutated away. This is true thanks to the initial tree.getArguments().size() != 1 check, but it doesn't seem right to drop this condition; it makes the code less clear, IMHO.

@Stephan202 Stephan202 requested a review from rickie February 11, 2024 20:15
Copy link

Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 39
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 2 39

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

@rickie rickie modified the milestones: 0.16.0, 0.17.0 Mar 8, 2024
@Stephan202 Stephan202 force-pushed the sschroevers/prefer-varargs-alternatives branch from 714713b to 6ae584f Compare March 17, 2024 10:00
Copy link

Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 39
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 2 39

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

1 similar comment
Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 39
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 2 39

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

@Stephan202 Stephan202 modified the milestones: 0.17.0, 0.18.0 Jul 20, 2024
@Stephan202 Stephan202 force-pushed the sschroevers/prefer-varargs-alternatives branch from 6ae584f to 4101867 Compare August 4, 2024 10:41
Copy link

sonarqubecloud bot commented Aug 4, 2024

Copy link

github-actions bot commented Aug 4, 2024

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 39
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 2 39

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

@rickie rickie modified the milestones: 0.18.0, 0.19.0 Aug 7, 2024
@Stephan202 Stephan202 force-pushed the sschroevers/prefer-varargs-alternatives branch from 4101867 to 5f14738 Compare September 21, 2024 09:04
Copy link

@rickie
Copy link
Member

rickie commented Dec 11, 2024

And this....

Caused by: org.eclipse.aether.transfer.ArtifactTransferException: com.github.PicnicSupermarket.error-prone:error_prone_core:jar:v2.36.0-picnic-1 failed to transfer from https://jitpack.io/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of jitpack.io has elapsed or updates are forced. Original error: Could not transfer artifact com.github.PicnicSupermarket.error-prone:error_prone_core:jar:v2.36.0-picnic-1 from/to jitpack.io (https://jitpack.io/): Checksum validation failed, no checksums available

@Stephan202
Copy link
Member Author

Error:  Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (error-prone-compile) on project checkstyle: Fatal error compiling: The default --should-stop=ifError policy (INIT) is not supported by Error Prone, pass --should-stop=ifError=FLOW instead -> [Help 1]

From the IT ☝🏻.

Not checking the error in depth right now, but curious 🤔.

I filed #1455 for this.

@Stephan202
Copy link
Member Author

And this....

Caused by: org.eclipse.aether.transfer.ArtifactTransferException: com.github.PicnicSupermarket.error-prone:error_prone_core:jar:v2.36.0-picnic-1 failed to transfer from jitpack.io during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of jitpack.io has elapsed or updates are forced. Original error: Could not transfer artifact com.github.PicnicSupermarket.error-prone:error_prone_core:jar:v2.36.0-picnic-1 from/to jitpack.io (jitpack.io): Checksum validation failed, no checksums available

Same also happened for a master build, but a restart fixed it. The new PR mentioned above also has a passing build.

@rickie rickie closed this in #1455 Dec 12, 2024
@rickie rickie reopened this Dec 12, 2024
@rickie
Copy link
Member

rickie commented Dec 12, 2024

Oops, sorry, don't know what happened there 😓.

Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 39
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 2 39

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

@rickie
Copy link
Member

rickie commented Dec 12, 2024

/integration-test

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.

Only one small typo and a suggestion :). Nice check @Stephan202 . Sorry for the slow review 🐌.

pom.xml Outdated
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.16.23</version>
Copy link
Member

Choose a reason for hiding this comment

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

There is a higher version, a specific reason to not use that yet?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, maybe the age of this PR has something to do with that? 🙃

Copy link
Member

Choose a reason for hiding this comment

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

Haha, my bad. I just remembered in JPLA that JOOQ usually had some edge cases. Didn't check on which version we are internally but was thinking maybe there was something related to that .

" assertThat(ImmutableList.of()).containsExactlyInAnyOrderElementsOf(Set.of());",
" assertThat(ImmutableList.of()).containsSequence(Arrays.asList());",
" assertThat(ImmutableList.of()).containsSubsequence(ImmutableList.of(1));",
" assertThat(ImmutableList.of()).doesNotContainAnyElementsOf(ImmutableMultiset.of(1));",
Copy link
Member

Choose a reason for hiding this comment

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

No incrementing numbers this time? 😋

I see that the methods are different but might be "more" consistent 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, the number is per statement here, just like in the identification test above. Will tweak here, but leave the rest as-is.

.flatMap(e -> trySuggestCallingCustomAlternative(tree, argument, state, e.getValue()));
}

private static Optional<SuggestedFix> trySuggestCallingCustomAlternative(
Copy link
Member

Choose a reason for hiding this comment

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

Probably the only exception where VisitorState is not the last parameter :).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's to appease the "consistent overloads" rule. The alternative is to find another method name.

Copy link
Member

Choose a reason for hiding this comment

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

No it's fine, just found it funny that indeed the overload rule caused the first exception :).

.build());
}

private static boolean isAtLeastAsVisible(Element symbol, Element reference) {
Copy link
Member

Choose a reason for hiding this comment

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

Was thinking that the name modifier in this method name would be nice as addition, but also fine with leaving it as is.

Copy link
Member Author

Choose a reason for hiding this comment

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

The modifier is a syntactic means of influencing visibility, but for the purpose of this method that doesn't seem like a relevant detail.

Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 39
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 2 39

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

@Stephan202 Stephan202 force-pushed the sschroevers/prefer-varargs-alternatives branch from 7043cd0 to d602a2b Compare December 14, 2024 13:56
Copy link
Member Author

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

Rebased and added a commit. @mohamedsamehsalah WDYT? :)

.flatMap(e -> trySuggestCallingCustomAlternative(tree, argument, state, e.getValue()));
}

private static Optional<SuggestedFix> trySuggestCallingCustomAlternative(
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's to appease the "consistent overloads" rule. The alternative is to find another method name.

.build());
}

private static boolean isAtLeastAsVisible(Element symbol, Element reference) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The modifier is a syntactic means of influencing visibility, but for the purpose of this method that doesn't seem like a relevant detail.

" assertThat(ImmutableList.of()).containsExactlyInAnyOrderElementsOf(Set.of());",
" assertThat(ImmutableList.of()).containsSequence(Arrays.asList());",
" assertThat(ImmutableList.of()).containsSubsequence(ImmutableList.of(1));",
" assertThat(ImmutableList.of()).doesNotContainAnyElementsOf(ImmutableMultiset.of(1));",
Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, the number is per statement here, just like in the identification test above. Will tweak here, but leave the rest as-is.

pom.xml Outdated
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.16.23</version>
Copy link
Member Author

Choose a reason for hiding this comment

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

Well, maybe the age of this PR has something to do with that? 🙃

Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 39
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 2 39

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

Copy link
Contributor

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

Clean 🧼

(Sorry this slipped form my notifications 🙏 )

Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 39
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExplicitArgumentEnumeration 2 39

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

@Stephan202
Copy link
Member Author

Changed the scope of the new dependency. @rickie: also here, feel free to merge if you agree with the final changes.

@rickie rickie merged commit 1b8ffd8 into master Dec 16, 2024
16 checks passed
@rickie rickie deleted the sschroevers/prefer-varargs-alternatives branch December 16, 2024 08:15
@rickie
Copy link
Member

rickie commented Dec 16, 2024

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.

3 participants