r/java • • Oct 04 '25

Jackson 3.0.0 is released!

https://central.sonatype.com/artifact/tools.jackson/jackson-bom/versions
212 Upvotes

107 comments sorted by

View all comments

Show parent comment

3

u/cogman10 Oct 05 '25

The issue, especially with generics and where lambdas would be used, is there are multiple non-related exception types that could ultimately get involved.

Imagine code that looks something like this:

ids.stream()
  .map(this::loadFromDatabase) // 1
  .peek(this::storeInRedis)          // 2
  .toList();                                    // 3

Now imagine that loadFromDatabase throws a checked DataBaseException and storeInRedis throws a checked RedisException. What could the function signature at 2 or 3 look like? Ideally you'd want to see something equivalent to Stream func() throws RedisException, DatabaseException but how do you communicate that with the generics system?

And I think that's the crux of the language design issues with checked exceptions and generics.

1

u/davidalayachew Oct 06 '25

What could the function signature at 2 or 3 look like? Ideally you'd want to see something equivalent to Stream func() throws RedisException, DatabaseException but how do you communicate that with the generics system?

And I think that's the crux of the language design issues with checked exceptions and generics.

Yep, you've clearly highlighted the problem here.

The solution (in my mind) is clearly that Exceptions should be special-classed to permit unions in generics. So that, the exact thing you say can come into existence.

I think if we could denote a union of exception types in generics, this problem would dissolve to nothing. But maybe I am not thinking it through well enough.