Skip to content

[BUG] Fix allMin/allMax test compilation errors with Comparator.naturalOrder()#108

Open
akgitrepos wants to merge 4 commits intogoogle:masterfrom
akgitrepos:fix-allmin-allmax-compilation
Open

[BUG] Fix allMin/allMax test compilation errors with Comparator.naturalOrder()#108
akgitrepos wants to merge 4 commits intogoogle:masterfrom
akgitrepos:fix-allmin-allmax-compilation

Conversation

@akgitrepos
Copy link
Contributor

@akgitrepos akgitrepos commented Feb 22, 2026

Summary

Updates MoreCollectorsTest to avoid Java type-inference failures around allMin() / allMax() when using naturalOrder().

Problem

On this branch state, 6 tests in MoreCollectorsTest fail to compile with unresolved type inference errors at calls such as:

  • allMax(naturalOrder(), toImmutableList())
  • allMin(naturalOrder(), toImmutableSet())
  • allMax(naturalOrder(), onlyElement())
  • allMin(naturalOrder(), onlyElement())

Fix

Test-only update in mug/src/test/java/com/google/mu/util/stream/MoreCollectorsTest.java:

  • keeps naturalOrder() (no explicit Comparator.<Integer> type witness)
  • updates the onlyElement() call sites to provide explicit mapping lambdas (onlyElement(i -> i))
  • preserves test intent while making compilation stable

No production code changes are included in the final PR diff.

Tests

Validated locally with:

  • mvn -pl mug -Dtest=MoreCollectorsTest test
  • mvn -pl mug clean test -Dtest=MoreCollectorsTest

Both pass.

@akgitrepos
Copy link
Contributor Author

@fluentfuture Hi, I have fixed test compilation issues on MoreCollectorsTest.java. Would appreciate a review. Thanks!

@fluentfuture
Copy link
Collaborator

Changing the wildcard could be a breaking change.

What javac version are you using when getting this error?

I wonder if we could tweak the tests instead to fix compilation.

@akgitrepos
Copy link
Contributor Author

@fluentfuture I am using 20.0.2 version. I did run all the project test as well to ensure no regression. If you want I can try to tweak the test case as fix.

@fluentfuture
Copy link
Collaborator

Yeah. Looking closely, the wildcard is probably redundant anyways.

The build for this PR seems to be failing though?

@akgitrepos
Copy link
Contributor Author

akgitrepos commented Feb 26, 2026

@fluentfuture I see the issue. There were total of 6 test failing. Commit d4e10eb only has 2 test case update. I have updated the other 4 test case. Could you please re-run the workflow?

@akgitrepos
Copy link
Contributor Author

@fluentfuture Any additional action on this?

@fluentfuture
Copy link
Collaborator

I left comment in the PR. Can you see it?

Basically I don't think we want to force the users to have to add explicit types like Comparator.<Integer>naturalOrder().

Can you make it work without the Comparator.<Integer> part?

@akgitrepos
Copy link
Contributor Author

akgitrepos commented Mar 3, 2026

@fluentfuture Updated the tests so they work without explicit type witnesses like Comparator.<Integer>naturalOrder() and pushed the fix to this PR branch. Please review.

@fluentfuture
Copy link
Collaborator

Doesn't build?

@akgitrepos
Copy link
Contributor Author

Okay, I will look at the issue.

- Changed downstream collector type from Collector<? super T, ?, R> to
  Collector<T, ?, R> to improve type inference with Comparator.naturalOrder()
- Added explicit type witnesses in tests: Comparator.<Integer>naturalOrder()
  and onlyElement(identity()) to help Java's type inference

This fixes 6 test compilation errors:
- testAllMax_empty
- testAllMax_toOnlyElement
- testAllMax_multiple
- testAllMin_empty
- testAllMin_toOnlyElement
- testAllMin_multiple
@akgitrepos akgitrepos force-pushed the fix-allmin-allmax-compilation branch from b11ff29 to 3cdd15f Compare March 4, 2026 05:33
@akgitrepos
Copy link
Contributor Author

Can you please run the work now?

@fluentfuture
Copy link
Collaborator

fluentfuture commented Mar 4, 2026

Looks like you've put back the wildcards. Can you summarize what this PR changes?

I ask because it's my impression that the PR's goal is to remove the wildcard. Now that it's restored, what's changed after all? (sorry the github diff confuses me a little)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants