-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Nested Embedded fails Validation with NPE
PostPosted: Mon Jan 26, 2009 5:07 pm 
Newbie

Joined: Wed Dec 03, 2008 8:55 pm
Posts: 2
We have a use case where we have nested @Embedded objects.

E.g., EntityA contains an EmbeddedB and EmbeddedB contains an EmbeddedC.

At save time, validation throws a NullPointException.
Code:

at org.hibernate.validator.event.ValidateEventListener.validateSubElements(ValidateEventListener.java:161)
   at org.hibernate.validator.event.ValidateEventListener.validateSubElements(ValidateEventListener.java:166)
   at org.hibernate.validator.event.ValidateEventListener.validateSubElements(ValidateEventListener.java:166)
   at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:138)
   at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:172)
   at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:178)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:72)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
   at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:64)



I think that the issue might be because there is no null check on the entity in validateSubElements. In the validate, it returns if the entity == null. But there is no such check when it recursively validates sub elements. I have included two different ways that the problem could be fixed.

The issue is either with ValidateEventListener.java line 159 or line 166.
Code:

private void validateSubElements(
         ValidatableElement element, Object entity, List<InvalidValue> consolidatedInvalidValues
   ) {
      if ( element != null /* && entity != null */) { // this would fix it
         for ( ValidatableElement subElement : element.subElements ) {
            Object component = subElement.getter.get( entity );
            InvalidValue[] invalidValues = subElement.validator.getInvalidValues( component );
            for ( InvalidValue invalidValue : invalidValues ) {
               consolidatedInvalidValues.add( invalidValue );
            }
                                if (component != null) { // and so would this
                     validateSubElements( subElement, component, consolidatedInvalidValues );
                                }
         }
      }
   }


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 5:34 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Is this still an issue? Could you provide a test case for this? Note, however, that the next release of Hibernate Validator will be based on a new implementation based on JSR-303.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.