[code-reflection] RFR: throw instead returning when erasing checked to unchecked exception

Paul Sandoz psandoz at openjdk.org
Wed Jan 17 21:17:48 UTC 2024


On Wed, 17 Jan 2024 10:08:14 GMT, Hannes Greule <hgreule at openjdk.org> wrote:

> As discussed in https://mail.openjdk.org/pipermail/babylon-dev/2024-January/000006.html, I change the `erase` method to `eraseAndThrow` and added a test as suggested. I ensured that the test fails without my change and does not fail with it.

test/jdk/java/lang/reflect/code/interpreter/TestThrowing.java line 49:

> 47:         } catch (Throwable throwable) {
> 48:             Assert.assertEquals(throwable.getClass(), expectedExceptionType);
> 49:         }

I believe you can replace the try statement with:
 ```java
Assert.assertThrows(expectedExceptionType, 
    () -> Interpreter.invoke(method.getCodeModel().orElseThrow(), List.of()));

test/jdk/java/lang/reflect/code/interpreter/TestThrowing.java line 55:

> 53:     static Object[][] testData() throws NoSuchMethodException {
> 54:         return new Object[][]{
> 55:                 {"throwsError", Error.class},

Suggestion, up to you. Use specific exception to this test, there by differentiating between generic ones that might be thrown in error e.g., create `static class TestError extends Error {}`

-------------

PR Review Comment: https://git.openjdk.org/babylon/pull/2#discussion_r1456334099
PR Review Comment: https://git.openjdk.org/babylon/pull/2#discussion_r1456337693


More information about the babylon-dev mailing list