You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Marcus Crafter <cr...@managesoft.com> on 2003/10/15 17:45:49 UTC

Safe to release null?

Hi All,

Hope all is going well!

Just wanted to ask a quick question. Is it actually considered safe to
release null?

The framework API doesn't mention it, but I've noticed that both ECM and
Fortress have code in their ServiceManager.release() implementations
that can handle receiving a null reference.

Is this feature more of a safety net, or was there previously a clear
decision to allow null to be released?

Cheers,

Marcus


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


Re: Safe to release null?

Posted by Berin Loritsch <bl...@apache.org>.
Marcus Crafter wrote:

> Hi Berin,
> 
> Great, thanks for the explanation.
> 
> Mind if I add a small note to the javadocs for ServiceManager/Selector
> detailing this?

Go for it.  DOn't even need to ask about something like this.

-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


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


Re: Safe to release null?

Posted by Marcus Crafter <cr...@managesoft.com>.
Hi Berin,

Great, thanks for the explanation.

Mind if I add a small note to the javadocs for ServiceManager/Selector
detailing this?

Cheers,

Marcus

On Wed, 2003-10-15 at 17:55, Berin Loritsch wrote:
> Marcus Crafter wrote:
> 
> > Hi All,
> > 
> > Hope all is going well!
> > 
> > Just wanted to ask a quick question. Is it actually considered safe to
> > release null?
> 
> Should be.
> 
> > 
> > The framework API doesn't mention it, but I've noticed that both ECM and
> > Fortress have code in their ServiceManager.release() implementations
> > that can handle receiving a null reference.
> 
> Yep.
> 
> > 
> > Is this feature more of a safety net, or was there previously a clear
> > decision to allow null to be released?
> 
> It was a clear decision.  If we require non-null references, then we must
> throw an exception if the client violates that contract--which also violates
> the principle that releasing should not have adverse affects.  For components
> that do not need releasing (i.e. singleton components), there is no effect.
> Same for null references.


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


Re: Safe to release null?

Posted by Berin Loritsch <bl...@apache.org>.
Marcus Crafter wrote:

> Hi All,
> 
> Hope all is going well!
> 
> Just wanted to ask a quick question. Is it actually considered safe to
> release null?

Should be.

> 
> The framework API doesn't mention it, but I've noticed that both ECM and
> Fortress have code in their ServiceManager.release() implementations
> that can handle receiving a null reference.

Yep.

> 
> Is this feature more of a safety net, or was there previously a clear
> decision to allow null to be released?

It was a clear decision.  If we require non-null references, then we must
throw an exception if the client violates that contract--which also violates
the principle that releasing should not have adverse affects.  For components
that do not need releasing (i.e. singleton components), there is no effect.
Same for null references.

-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


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


RE: Safe to release null?

Posted by Marcus Crafter <cr...@managesoft.com>.
Hi Leo,

On Wed, 2003-10-15 at 17:54, Leo Sutic wrote:
> Yes. There was a clear decision to allow it so one could write:
> 
> 
>    MyComponent comp = null;
>    try {
>         comp = mgr.lookup (...);
> 
>         ....
> 
>    } finally {
>         mgr.release (comp);
>    }
> 
> without having to put in a null check.

Great, thanks mate - that example was exactly what I was asking :)

Cheers,

Marcus


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


RE: Safe to release null?

Posted by Leo Sutic <le...@inspireinfrastructure.com>.
Yes. There was a clear decision to allow it so one could write:


   MyComponent comp = null;
   try {
        comp = mgr.lookup (...);

        ....

   } finally {
        mgr.release (comp);
   }

without having to put in a null check.

/LS

> -----Original Message-----
> From: Marcus Crafter [mailto:crafterm@managesoft.com] 
> Sent: den 15 oktober 2003 17:46
> To: dev@avalon.apache.org
> Subject: Safe to release null?
> 
> 
> Hi All,
> 
> Hope all is going well!
> 
> Just wanted to ask a quick question. Is it actually 
> considered safe to release null?
> 
> The framework API doesn't mention it, but I've noticed that 
> both ECM and Fortress have code in their 
> ServiceManager.release() implementations that can handle 
> receiving a null reference.
> 
> Is this feature more of a safety net, or was there previously 
> a clear decision to allow null to be released?
> 
> Cheers,
> 
> Marcus
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
> For additional commands, e-mail: dev-help@avalon.apache.org
> 
> 
> 


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