Skip to content

Comments

Add Stream templates for CollectionRules and StringRules#2119

Open
timtebeek wants to merge 1 commit intoPicnicSupermarket:masterfrom
timtebeek:stream-templates-for-string-and-collection-rules
Open

Add Stream templates for CollectionRules and StringRules#2119
timtebeek wants to merge 1 commit intoPicnicSupermarket:masterfrom
timtebeek:stream-templates-for-string-and-collection-rules

Conversation

@timtebeek
Copy link
Contributor

@github-actions
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@coderabbitai
Copy link

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

Two new Refaster rules are added: SetOfVarargs in CollectionRules converts Stream.of().collect(toUnmodifiableSet()) to Set.of(), and StringJoinDelimiterVarargs in StringRules replaces Stream join operations with String.join(). Corresponding test cases are added for both rules.

Changes

Cohort / File(s) Summary
CollectionRules Implementation
error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java
Adds new nested rule SetOfVarargs\ that rewrites Stream.of(...).collect(toUnmodifiableSet()) to Set.of(...) for optimized unmodifiable set construction.
StringRules Implementation
error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java
Adds new nested rule StringJoinDelimiterVarargs that rewrites Stream joining operations to String.join(delimiter, varargs) pattern.
CollectionRules Test Cases
error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java, CollectionRulesTestOutput.java
Adds test method testSetOfVarargs() with before/after patterns demonstrating Stream.of() to Set.of() transformation, includes necessary imports for Set and toUnmodifiableSet.
StringRules Test Cases
error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestInput.java, StringRulesTestOutput.java
Adds test method testStringJoinDelimiterVarargs() with before/after patterns demonstrating Stream-based joining to String.join() transformation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add Stream templates for CollectionRules and StringRules' accurately and concisely summarizes the main change: adding new Stream-based refaster templates to two rule files.
Description check ✅ Passed The description is related to the changeset by referencing a replaced pull request and indicating this is a collaborative implementation, which is relevant context for the Stream template additions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java`:
- Around line 213-227: The SetOfVarargs refaster rule changes duplicate handling
(Stream.of(...).collect(toUnmodifiableSet()) silently deduplicates, whereas
Set.of(...) throws IllegalArgumentException on duplicates); update the
SetOfVarargs block to include an XXX comment noting this behavioral change and
the risk of introducing runtime IllegalArgumentException when input contains
duplicate elements, following the existing comment style used elsewhere in this
file (see similar XXX notes near other rules) and place it immediately above the
rule (or above the AfterTemplate) so reviewers and users are aware of the
caveat.
ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b784401 and 49e52ea.

📒 Files selected for processing (6)
  • error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java
  • error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java
  • error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java
  • error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java
  • error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestInput.java
  • error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestOutput.java

Comment on lines +213 to +227
/** Prefer {@link Set#of(Object[])} over more contrived alternatives. */
// XXX: Ideally we rewrite both of these expressions directly to `ImmutableSet.of(..)` (and
// locate this rule in `ImmutableSetRules`), but for now this rule is included as-is for use with
// OpenRewrite.
static final class SetOfVarargs<T> {
@BeforeTemplate
Set<T> before(@Repeated T elements) {
return Stream.of(Refaster.asVarargs(elements)).collect(toUnmodifiableSet());
}

@AfterTemplate
Set<T> after(@Repeated T elements) {
return Set.of(Refaster.asVarargs(elements));
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if there are any existing rules in this repo that document behavioral differences
# around Set.of vs toUnmodifiableSet, or duplicate-handling caveats.
rg -n -C3 'Set\.of|toUnmodifiableSet|duplicate' --type=java -g '!**/test/**' | head -80

Repository: PicnicSupermarket/error-prone-support

Length of output: 10039


🏁 Script executed:

# Also get the full context of the file to see the XXX notes pattern mentioned
cat -n error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java | head -250

Repository: PicnicSupermarket/error-prone-support

Length of output: 10407


🏁 Script executed:

# Search specifically for XXX or TODO comments in the CollectionRules file to understand documentation style
rg -n 'XXX|TODO' error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java

Repository: PicnicSupermarket/error-prone-support

Length of output: 1147


🏁 Script executed:

# Search for tests of SetOfVarargs rule
find . -name "*.java" -type f -exec grep -l "SetOfVarargs" {} \;

Repository: PicnicSupermarket/error-prone-support

Length of output: 391


🏁 Script executed:

# Check if there are any conditions/matchers on the rule that prevent duplicates
grep -B 5 -A 15 "class SetOfVarargs" error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java

Repository: PicnicSupermarket/error-prone-support

Length of output: 929


🏁 Script executed:

# Check the test input file for SetOfVarargs tests
grep -B 5 -A 10 "SetOfVarargs\|Stream.of.*toUnmodifiableSet" error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java

Repository: PicnicSupermarket/error-prone-support

Length of output: 493


🏁 Script executed:

# Check the test output file for SetOfVarargs tests
grep -B 5 -A 10 "SetOfVarargs\|Stream.of.*toUnmodifiableSet\|Set\.of" error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java | head -100

Repository: PicnicSupermarket/error-prone-support

Length of output: 3130


Add a comment documenting the duplicate-handling behavioral change in the SetOfVarargs rule.

The rewrite from Stream.of(...).collect(toUnmodifiableSet()) to Set.of(...) introduces a semantic difference: Set.of() throws IllegalArgumentException on duplicate values, while toUnmodifiableSet() deduplicates silently. For example, Stream.of(1, 1).collect(toUnmodifiableSet()) succeeds, but Set.of(1, 1) throws an exception.

Add an XXX comment documenting this caveat, following the pattern established elsewhere in this file (e.g., lines 196–197, 326, 590–605).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java`
around lines 213 - 227, The SetOfVarargs refaster rule changes duplicate
handling (Stream.of(...).collect(toUnmodifiableSet()) silently deduplicates,
whereas Set.of(...) throws IllegalArgumentException on duplicates); update the
SetOfVarargs block to include an XXX comment noting this behavioral change and
the risk of introducing runtime IllegalArgumentException when input contains
duplicate elements, following the existing comment style used elsewhere in this
file (see similar XXX notes near other rules) and place it immediately above the
rule (or above the AfterTemplate) so reviewers and users are aware of the
caveat.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant