[Hibernate-JIRA] Created: (HHH-5703) EJB3PostLoadEventListener, as created by EventListenerConfigurator, throws NullPointerException.
by Eduardo Born (JIRA)
EJB3PostLoadEventListener, as created by EventListenerConfigurator, throws NullPointerException.
------------------------------------------------------------------------------------------------
Key: HHH-5703
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5703
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.6
Reporter: Eduardo Born
EJB3PostLoadEventListener is created by EventListenerConfigurator with its default constructor:
listenerConfig.setPostLoadEventListeners(
new PostLoadEventListener[] { new EJB3PostLoadEventListener(), new DefaultPostLoadEventListener() }
);
The problem is that it has a callbackHandler field called which remains null, and there is no check in the postLoad method before invoking callbackHandler.postLoad( entity );. This causes a NullPointerException to be thrown there in a few situations.
The fix is simple. H+In the EJB3PostLoadEventListener's postLoad() method, replace:
public void onPostLoad(PostLoadEvent event) {
Object entity = event.getEntity();
callbackHandler.postLoad( entity );
}
by:
public void onPostLoad(PostLoadEvent event) {
if (callbackHandler == null) return;
Object entity = event.getEntity();
callbackHandler.postLoad( entity );
}
This would prevent the NullPointerException to be thrown when there is no callbackHandler.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 8 months
[Hibernate-JIRA] Created: (HHH-5702) Hibernate always registers JACC event listeners regardless of whether that is enabled or not which causes unecessary exceptions to be thrown.
by Eduardo Born (JIRA)
Hibernate always registers JACC event listeners regardless of whether that is enabled or not which causes unecessary exceptions to be thrown.
---------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-5702
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5702
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.6
Reporter: Eduardo Born
Hibernate always registers JACC event listeners regardless of whether JACC has been enabled or not (by defining the property hibernate.jacc.enabled in the configurations).
The JACC even listeners cause exceptions to be thrown in several situations when Hibernate is not running as part of a container. The most common exception I've seen so far is the "java.lang.IllegalArgumentException: unknown handler key"
Hibernate should only register the JACC listeners when JACC is enabled.
The fix seems to be in the EventListenerConfigurator class. A simple check for the hibernate.jacc.enabled property should be done before adding any of the JACC event listeners (JACCPreDeleteEventListener, JACCPreLoadEventListener, JACCPreUpdateEventListener, JACCPreInsertEventListener).
I believe a simple check like
if ( properties.containsKey( AvailableSettings.JACC_ENABLED ) ) {
...
}
should be performed before adding them.
In my case these listeners cause exceptions like these to be thrown in a few situations:
java.lang.IllegalArgumentException: unknown handler key
at javax.security.jacc.PolicyContext.getContext(PolicyContext.java:280)
at org.hibernate.secure.JACCPermissions$PolicyContextActions$2.getContextSubject(JACCPermissions.java:111)
at org.hibernate.secure.JACCPermissions.getContextSubject(JACCPermissions.java:120)
at org.hibernate.secure.JACCPermissions.checkPermission(JACCPermissions.java:59)
at org.hibernate.secure.JACCPreLoadEventListener.onPreLoad(JACCPreLoadEventListener.java:53)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:149)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:898)
...so I have to manually remove these listeners.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 8 months