uschindler commented on PR #14633: URL: https://github.com/apache/lucene/pull/14633#issuecomment-2866499124
I have a suggestion. I used the same approach in the expressions module to patch the stack trace and rethrowing exceptions (to include the source code of the exception into the stack trace). So basically at moment you always use code like this: ```java } catch (Throwable t) { IOUtils.closeWhileSuppressingExceptions(t, docIn, posIn, payIn); throw t; } ``` It would be much nicer like this: ```java } catch (Throwable t) { throw IOUtils.closeWhileSuppressingExceptions(t, docIn, posIn, payIn); } ``` This can be done by using generics on the method: ```java public static <T extends Throwable> T closeWhileSuppressingExceptions(T ex, Iterable<? extends Closeable> objects) { for (Closeable object : objects) { try { if (object != null) { object.close(); } } catch (Throwable e) { ex.addSuppressed(e); } } return ex; } ``` This allows the compiler to still take record of the exceptions and the code looks much better because you actually see that the method modifies the exception. If you don't want to use the return type, you can still rethrow the conventional way. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org