You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Carsten Ziegeler <cz...@s-und-n.de> on 2002/04/23 10:10:11 UTC

[Bug?]: ExcaliburComponentManager ignoring Exceptions

Hi,

it just took me days to find a problem in my application, because of
this code in lookup method of the ExcaliburComponentManager:

            if( m_parentManager != null )
            {
                try
                {
                    return m_parentManager.lookup( role );
                }
                catch( Exception e )
                {
                    // ignore.  If the exception is thrown, we try to
                    // create the component next
                }
            }

If I have a hierarchy of CMs and an exception occurs in the parent
CM this is silently ignored and later on in the lookup method an
exception with the message "component not found" is generated.

If I have a bug in my component which is correctly found by the
parent CM but unfortunately throws a NPE in the compose() method,
I will never get aware of this.

Why isn't the exception rethrown? Can we change this?

Carsten

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Peter Donald <pe...@apache.org>.
On Tue, 23 Apr 2002 23:58, Carsten Ziegeler wrote:
> Peter Donald wrote:
> > On Tue, 23 Apr 2002 20:21, Carsten Ziegeler wrote:
> > > In my case the parent CM catches the NPE of the component and
> > > rethrows it as a ComponentException. So if I change the above
> > > line to catch only ComponentExceptions it's not better.
> > >
> > > What about changing it to:
> > >
> > > if( m_parentManager != null && m_parentManager.hasComponent( role ) )
> > > {
> > >     return parentManager.lookup( role );
> > > }
> >
> > +1 from me - but then again I don't use the ECM :)
>
> Sorry for my english, but do you mean, you will not use the ECM *if* I
> change the code? Or do you mean, you don't use the ECM at all?

I don't use it at all so I may not know what I am takling about :)

-- 
Cheers,

Peter Donald


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Berin Loritsch wrote:
> <snip very good explanation/>
> 
Many thanks again Berin for the explanation. Ok, this makes now
sense for me, too.

Thanks,
Carsten

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Berin Loritsch <bl...@apache.org>.
Carsten Ziegeler wrote:


<snip/>


> I'm currently totally confused about the ECM code. If you look at the
> lookup method and compare it with the hasComponent() method, I see
> a big difference.
> 
> The hasComponent() only tests if the handler for the role is available
> and if not passes the request on to the parent CM.
> The lookup method tests if it has a handler, if not uses the parent CM
> and if the parent is not able to serve the request, the strange part
> begins. It starts with:
>             if( null != m_roles )
>             {
>                 final String className =
> m_roles.getDefaultClassNameForRole( role );
> ...
> Why is this only in the lookup method, but not in the hasComponent()?

The hasComponent() method is used to look up to see if an optional
exists.  The ECM assumes that if you did not specify the component in
the configuration file, you did not want it.  THerefore, the
hasComponent() simply returns if the component exists in the system
at present.

The lookup() method is a bit more accomodating in that it doesn't want
to leave you empty handed if it can help it.  If you lookup() a role
instead of checking if it exists first, the ECM assumes you _really_
want the component even if you didn't specify it in the config file.
It looks at the RoleManager to see if it can provide a default
implementation for you.  If not, it still throws an exception.

Subsequent calls for hasComponent() will return true for the specific
role.

There are two reasons for this approach:

1) hasComponent() should be side-effect free and quick
2) We need to have the option to not have a component loaded if we
    don't want it.

In Cocoon, there are alot of defaults for components--but we don't
always want the HSQL server loaded.  We do always want a parser,
but many times the default parser is just fine.

Required components are just looked up, and a failure to find that
component results in a failure for the component that tried to find
it.  Optional components are checked to see if they exist yet, and
only looked up if they do.


> 
> PS: It's not my best day today, so sorry if I ask dumb questions.

Not dumb at all.


-- 

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


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Berin Loritsch wrote:
>
> Carsten Ziegeler wrote:
> > Peter Donald wrote:
> >
> >>On Tue, 23 Apr 2002 20:21, Carsten Ziegeler wrote:
> >>
> >>>In my case the parent CM catches the NPE of the component and
> >>>rethrows it as a ComponentException. So if I change the above
> >>>line to catch only ComponentExceptions it's not better.
> >>>
> >>>What about changing it to:
> >>>
> >>>if( m_parentManager != null && m_parentManager.hasComponent( role ) )
> >>>{
> >>>    return parentManager.lookup( role );
> >>>}
> >>
> >>+1 from me - but then again I don't use the ECM :)
> >>
> >
> > Sorry for my english, but do you mean, you will not use the ECM *if* I
> > change the code? Or do you mean, you don't use the ECM at all?
>
> He means he does not currently use the code, and has no plans to.
> He is not saying anything about the life of the code.
>
Thanks, Berin.

I'm currently totally confused about the ECM code. If you look at the
lookup method and compare it with the hasComponent() method, I see
a big difference.

The hasComponent() only tests if the handler for the role is available
and if not passes the request on to the parent CM.
The lookup method tests if it has a handler, if not uses the parent CM
and if the parent is not able to serve the request, the strange part
begins. It starts with:
            if( null != m_roles )
            {
                final String className =
m_roles.getDefaultClassNameForRole( role );
...
Why is this only in the lookup method, but not in the hasComponent()?

PS: It's not my best day today, so sorry if I ask dumb questions.

Carsten


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Berin Loritsch <bl...@apache.org>.
Carsten Ziegeler wrote:
> Peter Donald wrote:
> 
>>On Tue, 23 Apr 2002 20:21, Carsten Ziegeler wrote:
>>
>>>In my case the parent CM catches the NPE of the component and
>>>rethrows it as a ComponentException. So if I change the above
>>>line to catch only ComponentExceptions it's not better.
>>>
>>>What about changing it to:
>>>
>>>if( m_parentManager != null && m_parentManager.hasComponent( role ) )
>>>{
>>>    return parentManager.lookup( role );
>>>}
>>
>>+1 from me - but then again I don't use the ECM :)
>>
> 
> Sorry for my english, but do you mean, you will not use the ECM *if* I
> change the code? Or do you mean, you don't use the ECM at all?

He means he does not currently use the code, and has no plans to.
He is not saying anything about the life of the code.



-- 

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


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Peter Donald wrote:
> 
> On Tue, 23 Apr 2002 20:21, Carsten Ziegeler wrote:
> > In my case the parent CM catches the NPE of the component and
> > rethrows it as a ComponentException. So if I change the above
> > line to catch only ComponentExceptions it's not better.
> >
> > What about changing it to:
> >
> > if( m_parentManager != null && m_parentManager.hasComponent( role ) )
> > {
> >     return parentManager.lookup( role );
> > }
> 
> +1 from me - but then again I don't use the ECM :)
> 
Sorry for my english, but do you mean, you will not use the ECM *if* I
change the code? Or do you mean, you don't use the ECM at all?

Carsten

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Peter Donald <pe...@apache.org>.
On Tue, 23 Apr 2002 20:21, Carsten Ziegeler wrote:
> In my case the parent CM catches the NPE of the component and
> rethrows it as a ComponentException. So if I change the above
> line to catch only ComponentExceptions it's not better.
>
> What about changing it to:
>
> if( m_parentManager != null && m_parentManager.hasComponent( role ) )
> {
>     return parentManager.lookup( role );
> }

+1 from me - but then again I don't use the ECM :)

-- 
Cheers,

Peter Donald


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Peter Donald wrote:
> 
> On Tue, 23 Apr 2002 18:10, Carsten Ziegeler wrote:
> > Hi,
> >
> > it just took me days to find a problem in my application, because of
> > this code in lookup method of the ExcaliburComponentManager:
> >
> >             if( m_parentManager != null )
> >             {
> >                 try
> >                 {
> >                     return m_parentManager.lookup( role );
> >                 }
> >                 catch( Exception e )
> 
> 
> Maybe change the above liine to only catch ComponentExceptions ?
> 
Ok, my example was not complete :(

In my case the parent CM catches the NPE of the component and
rethrows it as a ComponentException. So if I change the above
line to catch only ComponentExceptions it's not better.

What about changing it to:

if( m_parentManager != null && m_parentManager.hasComponent( role ) )
{
    return parentManager.lookup( role );
}


Carsten

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Peter Donald <pe...@apache.org>.
On Tue, 23 Apr 2002 18:10, Carsten Ziegeler wrote:
> Hi,
>
> it just took me days to find a problem in my application, because of
> this code in lookup method of the ExcaliburComponentManager:
>
>             if( m_parentManager != null )
>             {
>                 try
>                 {
>                     return m_parentManager.lookup( role );
>                 }
>                 catch( Exception e )


Maybe change the above liine to only catch ComponentExceptions ?

-- 
Cheers,

Peter Donald


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Peter Royal wrote:
> 
> I guess the question is: When should at CM atttempt to check its 
> parent CM 
> for the component, when it finds that it has no ComponentHandler for the 
> component, or when it finds that it has no ComponentHandler *and* can't 
> create the ComponentHandler itself? This would be swapping the 
> m_parentManager and m_roles checks inside of the ECM.
> 
> The only pitfall would be the case where the current CM *and* the 
> parent CM 
> have the ability to create the ComponentHandler, but the parent CM has 
> managed to create it first. By swapping the two it would get 
> created on the 
> child before checking the parent.

I'm not that familiar with the internals of a CM, but if it is possible
that a child CM has a different set of roles (m_roles) than the parent CM
then this check should be done before checking the parent.

So in this case we should revert the check and could then also clean up
the exception handling.

Carsten

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Peter Royal <pr...@apache.org>.
On Thursday 25 April 2002 01:52 am, Carsten Ziegeler wrote:
> > If the parent CM doesn't (and isn't expected) to have the component, we
> > expect a ComponentException there on the 1st lookup() since the
> > ComponentHandler for the component has yet to be created. (These are
> > components defined only in the roles file, not in the config).
>
> But a CM can throw a ComponentException in other cases as well, for
> example if it catches another exception and rethrows a ComponentException.

ahh, true.

I guess the question is: When should at CM atttempt to check its parent CM 
for the component, when it finds that it has no ComponentHandler for the 
component, or when it finds that it has no ComponentHandler *and* can't 
create the ComponentHandler itself? This would be swapping the 
m_parentManager and m_roles checks inside of the ECM.

The only pitfall would be the case where the current CM *and* the parent CM 
have the ability to create the ComponentHandler, but the parent CM has 
managed to create it first. By swapping the two it would get created on the 
child before checking the parent.
-pete

-- 
peter royal -> proyal@apache.org

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Peter Royal wrote:
> 
> I think it should be more like this. The current code is now:
> 
>                 catch( Exception e )
>                 {
>                     if( getLogger().isWarnEnabled() )
>                     {
>                         final String message =
>                            "ComponentManager exception from 
> parent CM during 
> lookup.";
>                         getLogger().warn( message, e );
>                     }
>                     // ignore.  If the exception is thrown, we try to
>                     // create the component next
>                 }
> 
> Which is logging spurious exceptions in my case. 
> 
Yes, I changed it that way.

> If the parent CM doesn't (and isn't expected) to have the component, we 
> expect a ComponentException there on the 1st lookup() since the 
> ComponentHandler for the component has yet to be created. (These are 
> components defined only in the roles file, not in the config).
> 
But a CM can throw a ComponentException in other cases as well, for 
example if it catches another exception and rethrows a ComponentException.

Thanks
Carsten


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Peter Royal <pr...@apache.org>.
On Tuesday 23 April 2002 04:33 am, Leo Sutic wrote:
> Maybe the intent was:
>
>              if( m_parentManager != null )
>              {
>                  try
>                  {
>                      return m_parentManager.lookup( role );
>                  }
>                  catch( ComponentException e ) << Only catch
> ComponentExceptions, not RuntimeE*
>                  {
>                      // ignore.  If the exception is thrown, we try to
>                      // create the component next
>                  }
>              }
>
> Anyone else?

I think it should be more like this. The current code is now:

                catch( Exception e )
                {
                    if( getLogger().isWarnEnabled() )
                    {
                        final String message =
                           "ComponentManager exception from parent CM during 
lookup.";
                        getLogger().warn( message, e );
                    }
                    // ignore.  If the exception is thrown, we try to
                    // create the component next
                }

Which is logging spurious exceptions in my case. 

If the parent CM doesn't (and isn't expected) to have the component, we 
expect a ComponentException there on the 1st lookup() since the 
ComponentHandler for the component has yet to be created. (These are 
components defined only in the roles file, not in the config).

Perhaps changing it to catch ComponentException's and log those with debug() 
and keep the now-current behavior for all other exceptions (Such as the NPE 
that spawned the thread).
-pete

-- 
peter royal -> proyal@apache.org

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [Bug?]: ExcaliburComponentManager ignoring Exceptions

Posted by Leo Sutic <le...@inspireinfrastructure.com>.

> From: Carsten Ziegeler [mailto:cziegeler@s-und-n.de]
>
> Hi,
>
> it just took me days to find a problem in my application, because of
> this code in lookup method of the ExcaliburComponentManager:
>
>             if( m_parentManager != null )
>             {
>                 try
>                 {
>                     return m_parentManager.lookup( role );
>                 }
>                 catch( Exception e )
>                 {
>                     // ignore.  If the exception is thrown, we try to
>                     // create the component next
>                 }
>             }
>
> If I have a hierarchy of CMs and an exception occurs in the parent
> CM this is silently ignored and later on in the lookup method an
> exception with the message "component not found" is generated.
>
> If I have a bug in my component which is correctly found by the
> parent CM but unfortunately throws a NPE in the compose() method,
> I will never get aware of this.
>
> Why isn't the exception rethrown? Can we change this?

Maybe the intent was:

             if( m_parentManager != null )
             {
                 try
                 {
                     return m_parentManager.lookup( role );
                 }
                 catch( ComponentException e ) << Only catch
ComponentExceptions, not RuntimeE*
                 {
                     // ignore.  If the exception is thrown, we try to
                     // create the component next
                 }
             }

Anyone else?

/LS


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>