graphql-java-tools icon indicating copy to clipboard operation
graphql-java-tools copied to clipboard

Checked Exception in field resolver results in UndeclaredThrowableExceptions

Open apae89 opened this issue 4 years ago • 0 comments

Description

Hi,

I'm not quite sure if it's a bug, but I found a strange behavior after updating to version 6.1.0. Since this version checked exceptions thrown in field resolver functions are getting wrapped by an UndeclaredThrowableException. The corresponding change came with this commit: https://github.com/graphql-java-kickstart/graphql-java-tools/pull/391/commits/950e291f39102c7f773cdb8e2e74a7ee827c5f58

Is there any particular reason for this implementation?

According to Oracle's documentation such an exception should only be thrown if a method throws a checked exception in its body that is not declared in the method's signature.

Expected behavior

Checked exceptions are not getting wrapped by an UndeclaredThrowableException, but only thrown as RuntimeExceptions and Errors.

Actual behavior

Checked exceptions are are getting wrapped by an UndeclaredThrowableException.

Steps to reproduce the bug

  1. Define a query in the GQL scheme
type Query {
    testQuery: String
}
  1. Implement a corresponding resolver function and throw a checked Exception
    public String testQuery() throws Exception {
        throw new Exception();
    }

apae89 avatar Jan 21 '21 14:01 apae89