apache / apache/polaris

Review and Replace Collectors.toList() with Stream.toList() Where Mutability Is Not Required

Open
#4,757 1 comment 0 reactions 0 assignees View on GitHub
enhancement stale
Dominant language
Java
Stars
2.1k
Forks
522
Avg merge
1d 17h
Merged PRs (30d)
137

Description

### Is your feature request related to a problem? Please describe.

Several locations in the codebase use stream.collect(Collectors.toList()) even when the resulting list is not modified after creation.

Since Polaris targets modern Java versions that support Stream.toList(), these usages introduce unnecessary boilerplate and reduce consistency with modern Java practices.

Reviewing and updating these occurrences would improve readability and simplify stream operations while preserving existing behavior where mutability is not required.

### Describe the solution you'd like

Review usages of Collectors.toList() across the codebase and replace them with Stream.toList() where the returned list is not modified after creation.

Each occurrence should be evaluated individually to ensure that mutability is not required, since Stream.toList() returns an unmodifiable list.

Example:

Before:
List names =
users.stream()
.map(User::getName)
.collect(Collectors.toList());

After:
List names =
users.stream()
.map(User::getName)
.toList();

Acceptance criteria:
- Safe usages of Collectors.toList() are identified.
- Replacements are made only where behavior remains unchanged.
- Existing tests continue to pass.
- No regressions related to list mutability are introduced.

### Describe alternatives you've considered

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with a repository-wide search for Collectors.toList() and inspect each result for later list mutation before changing it. Use the existing test suite to verify behavior, especially around mutability; done means only safe usages use Stream.toList(), mutable-list behavior is preserved, and tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.