It seems that if a getter throws an Error, org.hibernate.property.access.spi.GetterMethodImpl will wrap it as any other exception:
... this is basically the equivalent of {{catch (Throwable t) { throw new MyException(t); } }}... My understanding was that in Java in general, it is discouraged to try to handle Errors, which should rather be propagated directly. From the javadoc of Error:
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch
And it makes sense when you think about OutOfMemoryError for example; when that happens, the best solution is probably to propagate it directly, so that any caller can detect there's something very wrong and that ongoing processes (batch process, ...) should abort everything without delay (e.g. no "log the error and report it at the end of the batch" or "log the error and retry"). So, Hibernate should:
- Unwrap InvocationTargetException and use its cause instead of the exception itself; it doesn’t bring anything.
- Never wrap {{Error}}s and just re-throw them directly.
See also https://hibernate.zulipchat.com/#narrow/stream/132094-hibernate-orm-dev/topic/GetterMethodImpl.20wraps.20Errors |