Supposedly unreachable AssertionError is actually reachable

some-java-user-99206970363698485155 at vodafonemail.de some-java-user-99206970363698485155 at vodafonemail.de
Sun Oct 20 13:13:33 UTC 2024


Hello,

jextract generated code contains multiple times this pattern when 
handling the `Throwable` declared by `MethodHandle#invokeExact`:
```
try {
     mh.invokeExact(...);
} catch (Throwable ex) {
     throw new AssertionError("should not reach here", ex);
}
```

The problem is that this actually seems to be reachable:

  * When for example a closed Arena is used, or a confined Arena is used
    by a different thread, see for example
    https://github.com/tree-sitter/java-tree-sitter/issues/44#issuecomment-2402356147
    Maybe in some cases this represents incorrect usage of the jextract
    generated code, but it seems at least in some cases (e.g. usage from
    wrong thread) an AssertionError is inappropriate.
  * Probably when a JVM error occurs


So maybe it would be better to generate code like this?
```
try {
     mh.invokeExact(...);
} catch (Error | RuntimeException ex) {
     throw ex;
} catch (Throwable ex) {
     throw new AssertionError("should not reach here", ex);
}
```


Side note: https://bugreport.java.com/bugreport/start_form currently 
does not support reporting jextract issues; when selecting "Component: 
Tools Issues", the "Subcomponent" dropdown does not offer "jextract". Is 
that intended?


Kind regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jextract-dev/attachments/20241020/98aafecf/attachment.htm>


More information about the jextract-dev mailing list