Skip to content

Remove extracting(Function) from Iterable assertions#3854

Open
PatrickWalter214 wants to merge 3 commits intoassertj:mainfrom
PatrickWalter214:gh-1499-extracting-ambiguous-signature-kotlin
Open

Remove extracting(Function) from Iterable assertions#3854
PatrickWalter214 wants to merge 3 commits intoassertj:mainfrom
PatrickWalter214:gh-1499-extracting-ambiguous-signature-kotlin

Conversation

@PatrickWalter214
Copy link

@PatrickWalter214 PatrickWalter214 commented Jun 14, 2025

In Kotlin, the call to extracting with a lambda for an iterable assert is ambiguous. This is due to the extracting method existing for ThrowingExtractor and Function, which have the same effective signature, as checked exceptions do not exist in Kotlin. We opt to continue using the extracting method for ThrowingExtractor, since it is the more flexible functional interface, as it supports that the lambda provided can throw an exception.

Check List:

@scordio scordio self-assigned this Jun 15, 2025
@scordio scordio added the event: Hack.Commit.Push A topic worked on during a Hack.Commit.Push event label Jun 15, 2025
In Kotlin the call to extracting with a lambda for an iterable assert is ambiguous. This is due to the extracting method existing for ThrowingExtractor and Function, which have the same effective signature, as checked exceptions do not exist in Kotlin. We opt to continue using the extracting method for ThrowingExtractor, since it is the more flexible functional interface, as it supports that the lambda provided can throw an exception.
@PatrickWalter214 PatrickWalter214 force-pushed the gh-1499-extracting-ambiguous-signature-kotlin branch from 53df5dd to fe69a89 Compare June 17, 2025 17:13
@scordio scordio added the language: Kotlin An issue related to using AssertJ with Kotlin label Nov 8, 2025
@scordio scordio changed the title BREAKING CHANGE: Remove Function support when extracting from Iterable Remove extracting(Function) from Iterable assertions Nov 8, 2025
@scordio scordio force-pushed the main branch 2 times, most recently from b2b071f to 2dab02c Compare November 8, 2025 18:05
Copy link
Member

@scordio scordio left a comment

Choose a reason for hiding this comment

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

Many thanks @PatrickWalter214 for your efforts, and sorry for such a big delay!

There are a couple of things I'd like to do differently, but I'm taking care of them directly.

* @return a new assertion object whose object under test is the list of values extracted
*/
@CheckReturnValue
public <V> AbstractListAssert<?, List<? extends V>, V, ObjectAssert<V>> extracting(Function<? super ELEMENT, V> extractor) {
Copy link
Member

@scordio scordio Nov 21, 2025

Choose a reason for hiding this comment

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

As discussed today with @filiphr, removing the overload accepting Function will break compatibility with all the existing Function implementations that cannot be easily transformed into a ThrowingExtractor, such as those coming from third parties.

A better strategy is likely to keep extracting(Function) and add to ThrowingExtractor factory methods that ease wrapping code that throws exceptions, similar to how the Spring Framework does.

I'll analyze the topic again and come up with a better proposal.

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

Labels

event: Hack.Commit.Push A topic worked on during a Hack.Commit.Push event language: Kotlin An issue related to using AssertJ with Kotlin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ambiguous signature for extracting() when using Kotlin

2 participants