db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Mahler <thm...@web.de>
Subject Re: PATCH for OjbStoreConnector
Date Sat, 24 Jan 2004 10:49:50 GMT
Hi Gus,

sorry I missed your original post on the user list. It's much safer to 
post patches to the dev list as it has less traffic.

I think you are right that it's better to throw an explantory exception 
rather than return null.

So I'll check in your patch asap.

thanks for your patience,
Thomas

Gus Heck wrote:
> I posted this to the Users list with the subject: Re: NPE in OjbExtent 
> (solved)
> 
> Since it seems to have gone unnoticed, I am resubmtting it here. This 
> patch fixes what I think is probably a bug in OjbStoreConnecter. 
> Basically, OjbStoreConnector operates by grabbing a persistance broker 
> when a transaction is begun and sticking it in the instance variable 
> broker. When the transaction finnishes  broker is set to null. This  
> means that  getBroker returns null if there is no transaction in 
> progress, which is very likely to cause null pointer exceptions if a 
> transactional action is used outside of a transaction. Unfortunately a 
> null pointer exception could mean anything and in my case I temporarily 
> came to the conclusion that something was broken in OJB. Only after 
> putting the code down for several weeks to work on other projects did I 
> notice that I hadn't started a transaction. (I noticed it because I 
> finally said to my self, "Ok self, if noone else wants this fixed, I had 
> better find a way to fix it and submit a patch". Once I understood how 
> OjbStoreConnetor worked it became obvious that no transaction was in 
> progress).
> 
> I propose org.apache.ojb.jdori.sql.OjbStoreConnector.getBroker() should 
> throw a JDOUserException("No Transaction in Progress.")  rather than 
> returning null. This would make the nature of the problem much clearer 
> than a NullPointerException thrown when the broker instance that was 
> returned as null is used.
> 
> - Gus
> 
> Index: src/jdori/org/apache/ojb/jdori/sql/OjbStoreConnector.java
> ===================================================================
> RCS file: 
> /home/cvspublic/db-ojb/src/jdori/org/apache/ojb/jdori/sql/OjbStoreConnector.java,v 
> 
> retrieving revision 1.1
> diff -u -r1.1 OjbStoreConnector.java
> --- src/jdori/org/apache/ojb/jdori/sql/OjbStoreConnector.java   24 Dec 
> 2002 12:06:01 -0000      1.1
> +++ src/jdori/org/apache/ojb/jdori/sql/OjbStoreConnector.java   21 Jan 
> 2004 20:52:23 -0000
> @@ -62,6 +62,8 @@
> 
> import com.sun.jdori.Connector;
> 
> +import javax.jdo.JDOUserException;
> +
> /**
> * OjbStoreConnector represents a OJB PB connection
> *
> @@ -214,6 +216,9 @@
>     */
>    public PersistenceBroker getBroker()
>    {
> +        if (broker == null) {
> +            throw new JDOUserException("No transaction in progress.");
> +        }
>        return broker;
>    }
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message