-->
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.  [ 5 posts ] 
Author Message
 Post subject: EnumType.nullsafeSet() throws NullPointerException (beta4)
PostPosted: Tue Aug 09, 2005 2:09 pm 
Newbie

Joined: Tue Aug 09, 2005 1:49 pm
Posts: 2
Ironic, I know...

I'm not sure if this should go in the main forum or in this forum, but since this class is only distributed with the annotations package, I've posted it here.

Since updating to the Annotations beta4 release, I am now getting a NullPointerException during session flush:

java.lang.NullPointerException
at org.hibernate.type.EnumType.nullSafeSet(EnumType.java:120)
at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:141)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1617)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1594)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1850)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
...

Here's the code for nullSafeSet(), beta4 release:
Code:
   public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
      if (!guessed) guessType( st, index );
      if (value == null) {
         if (IS_TRACE_ENABLED) log.debug("Binding null to parameter: " + index);
         st.setNull( index, sqlType );
      }
      boolean isOrdinal = isOrdinal(sqlType);
      if (isOrdinal) {
         int ordinal = ( (Enum) value ).ordinal();
         if ( IS_TRACE_ENABLED ) {
            log.debug("Binding '" + ordinal + "' to parameter: " + index);
         }
         st.setObject( index, new Integer(ordinal), sqlType );
      }
      else {
         String enumString = ( (Enum) value ).name();
         if ( IS_TRACE_ENABLED ) {
            log.debug("Binding '" + enumString + "' to parameter: " + index);
         }
         st.setObject( index, enumString, sqlType );
      }
   }


With casual inspection, it is quite clear that this method is going to crash every time value is null. The source code for the beta3 version of method reveals that it previously handled null correctly, but the it has been completely rewritten in beta4.

Anyone else had this problem? I searched for "EnumType" and "nullsafeSet" in the issue tracker and could not find any matching issues. I'll try hacking my local copy of Hibernate and see if that clears it up.


Top
 Profile  
 
 Post subject: EnumType.nullsafeSet() throws NullPointerException (beta4)
PostPosted: Thu Aug 11, 2005 1:58 am 
Newbie

Joined: Mon Sep 13, 2004 6:02 pm
Posts: 12
Location: Seattle, WA
Did you end up filing a bug on this? This definitely looks like a problem. I haven't actually tried this code yet, since I was having trouble getting nullSafeGet to correctly guess my backing type using Oracle. I just submitted a patch for that bug. The fix for this looks trivial; just return early after the call to st.setNull. I can update my patch and add this fix as a "rider", since I'm in this code already...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 2:12 am 
Newbie

Joined: Mon Sep 13, 2004 6:02 pm
Posts: 12
Location: Seattle, WA
As promised, I updated my patch to ANN-63 to include a fix for this. If you haven't already patched your local version, give my patch a try to see if that works for you.

http://opensource.atlassian.com/project ... Data.patch


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 5:20 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Fixed. I'm a bit ashamed of this one :-/

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 2:46 pm 
Newbie

Joined: Tue Aug 09, 2005 1:49 pm
Posts: 2
Thanks guys! Shaug, I didn't use your patch specifically, but I did recompile EnumType with an else clause around the non-null portion of nullSafeSet, and it worked for me. I was preparing to log a bug/fix on it and decided to check the forum one last time, and by then you and emmanuel had replied.

I think this is the first time I ever participated in an open-source project, and I like it. Without the source code, I would have had to develop a workaround for problem (not so difficult in this case, just make sure none of the enums are NULL), and might still be stuck.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.