[JIRA] (HHH-16403) Avoid wrapping Errors thrown by getters/setters
by Yoann Rodière (JIRA)
Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOGQ0NjQzNTEz... ) / Improvement ( https://hibernate.atlassian.net/browse/HHH-16403?atlOrigin=eyJpIjoiOGQ0Nj... ) HHH-16403 ( https://hibernate.atlassian.net/browse/HHH-16403?atlOrigin=eyJpIjoiOGQ0Nj... ) Avoid wrapping Errors thrown by getters/setters ( https://hibernate.atlassian.net/browse/HHH-16403?atlOrigin=eyJpIjoiOGQ0Nj... )
Issue Type: Improvement Assignee: Unassigned Created: 30/Mar/2023 04:36 AM Priority: Major Reporter: Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
It seems that if a getter throws an Error, org.hibernate.property.access.spi.GetterMethodImpl will wrap it as any other exception:
@Override
public Object get(Object owner) {
try {
return getterMethod.invoke( owner, ArrayHelper.EMPTY_OBJECT_ARRAY );
}
catch (InvocationTargetException ite) {
throw new PropertyAccessException(
ite, // !!!! ite.getCause() could be an Error!
"Exception occurred inside",
false,
containerClass,
propertyName
);
}
... 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/t...
( https://hibernate.atlassian.net/browse/HHH-16403#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16403#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100219- sha1:6a6077b )
1 year, 9 months