Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checked Exceptions are not causing a failure event #529

Closed
ferencbeutel4711 opened this issue Apr 27, 2021 · 12 comments · Fixed by #534
Closed

Checked Exceptions are not causing a failure event #529

ferencbeutel4711 opened this issue Apr 27, 2021 · 12 comments · Fixed by #534
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ferencbeutel4711
Copy link

ferencbeutel4711 commented Apr 27, 2021

Hi,

If a checked exception is thrown inside of a .item() - handler, it does not cause a failure event.

kotlin example

Uni.createFrom().item { throw Exception("checked exception") }
.onFailure(f -> println(f))

The above uni will never print the error (and pretty sure it will also never terminate, since this issue caused deadlocks in our application). If a RuntimeException is thrown, everything is fine.

@cescoffier
Copy link
Contributor

Oh, I didn't know that about Kotlin.
For Java we have the "Unchecked" utility classes (https://smallrye.io/smallrye-mutiny/guides/unchecked), but if Kotlin can write such a code, we should be able to catch the thrown exception.

Any Kotlin user that knows the type of exception thrown in this case.

CC @jponge

@cescoffier
Copy link
Contributor

Oh, BTW, the second line should be:

.onFailure().invoke(f -> println(f))

@jponge
Copy link
Member

jponge commented Apr 28, 2021

Ok so in Kotlin there is no notion of checked exception, and when you throw a java.lang.Exception (or any other checked exception) then MultiCreate#item will not handle them, only runtime exceptions.

This actually makes sense, because a supplier cannot throw a checked exception, so you can't write this in Java:

Multi<Integer> multi = Multi.createFrom().item(() -> {
  throw new Exception("boom");
});

...but this is fine for Kotlin which is more permissive here.

@jponge
Copy link
Member

jponge commented Apr 28, 2021

I'm tempted to say this is not a bug, because in Java you can't have this, this is specific to Kotlin and its laxer type checking wrt exception control flow.

@Ladicek
Copy link
Contributor

Ladicek commented Apr 28, 2021

Java has made "sneaky throws" really easy -- here's my favorite implementation:

public class SneakyThrow {
    private SneakyThrow() {
    }

    /**
     * This method can and should be used as part of a {@code throw} statement,
     * such as: {@code throw sneakyThrow(exception);}. It is guaranteed to never return normally,
     * and this style of usage makes sure that the Java compiler is aware of that.
     */
    @SuppressWarnings("unchecked")
    public static <E extends Throwable> RuntimeException sneakyThrow(Throwable e) throws E {
        throw (E) e;
    }
}

So you can have this in Java, really easily: throw sneakyThrow(new Exception("boom"));

@jponge
Copy link
Member

jponge commented Apr 28, 2021

Yes this is evilish @Ladicek 😆

@jponge
Copy link
Member

jponge commented Apr 28, 2021

So it's interesting, perhaps we need to catch better "just in case"

@jponge
Copy link
Member

jponge commented Apr 28, 2021

I'm looking into it.

@jponge jponge changed the title checked Exceptions are not causing a failure event Checked Exceptions are not causing a failure event Apr 28, 2021
@jponge jponge linked a pull request Apr 28, 2021 that will close this issue
@jponge jponge added the bug Something isn't working label Apr 28, 2021
@jponge jponge self-assigned this Apr 28, 2021
@jponge jponge added this to the 0.17.0 milestone Apr 28, 2021
@jponge
Copy link
Member

jponge commented Apr 28, 2021

I opened #534 to fix that.

@jponge
Copy link
Member

jponge commented Apr 28, 2021

Thanks @ferencbeutel4711 for reporting

@ferencbeutel4711
Copy link
Author

hey guys, thank you so much for the quick fix!
We are using Mutiny via Quarkus, do you know how the usual release process works in that scenario?

@jponge
Copy link
Member

jponge commented Apr 28, 2021

It will be part of 0.17, we tend to release about once a month, then it's upgraded in Quarkus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants