Zhong Hao (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOGQ2OTE0MzEw...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16525?atlOrigin=eyJpIjoiOGQ2OT...
) HHH-16525 (
https://hibernate.atlassian.net/browse/HHH-16525?atlOrigin=eyJpIjoiOGQ2OT...
) PersistentAttributesEnhancer.addCompositeOwnerInterface does not rethrow exceptions. (
https://hibernate.atlassian.net/browse/HHH-16525?atlOrigin=eyJpIjoiOGQ2OT...
)
Issue Type: Bug Assignee: Unassigned Components: hibernate-core Created: 26/Apr/2023 22:40
PM Priority: Major Reporter: Zhong Hao (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
PersistentAttributesEnhancer.java:addCompositeOwnerInterface has the following code:
private void addCompositeOwnerInterface(CtClass managedCtClass) throws NotFoundException,
CannotCompileException {
...
if ( enhancementContext.isCompositeClass( managedCtClass ) ) {
// if a composite has an embedded field we need to implement the TRACKER_CHANGER_NAME
method as well
MethodWriter.write(
managedCtClass,
"public void %1$s(String name) {%n" +
" if (%2$s != null) { %2$s.callOwner(\".\" + name); }%n}",
EnhancerConstants.TRACKER_CHANGER_NAME,
EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME
);
}
}
MethodWriter.write can throw CannotCompileException.
In this class, when MethodWriter.write , the other method rethrow EnhancementException:
protected CtMethod generateFieldReader(
...
try{
...
reader = MethodWriter.write(
managedCtClass, "public %s %s() {%n%s%n return %s;%n}",
persistentField.getType().getName(),
readerName,
typeDescriptor.buildReadInterceptionBodyFragment( fieldName ),
declared ? declaredReadFragment : superReadFragment
);
}catch (CannotCompileException cce) {
final String msg = String.format(
"Could not enhance entity class [%s] to add field reader method [%s]",
managedCtClass.getName(),
readerName
);
throw new EnhancementException( msg, cce );
}
catch (NotFoundException nfe) {
final String msg = String.format(
"Could not enhance entity class [%s] to add field reader method [%s]",
managedCtClass.getName(),
readerName
);
throw new EnhancementException( msg, nfe );
}
}
It is confusing. If calling code catches EnhancementException to handle errors, it will
miss the errors occuring in addCompositeOwnerInterface.
Can this problem be fixed?
(
https://hibernate.atlassian.net/browse/HHH-16525#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16525#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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100223- sha1:02266b8 )