You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Jeremy Quinn <je...@media.demon.co.uk> on 2003/10/29 12:36:22 UTC

NPEs in FlowLayer

Hi All

I am getting mysterious NPEs in the flowlayer, while working with the  
flow version of  'authentication-fw'.

Not only are they odd, they are completely inconsistent.
They tend to happen after a script redirects after eg. a bad login.


eg.

"file:/Users/jermq/Checkouts/Secure/cocoon-2.1/build/webapp/arches- 
public/flow/authentication.js", line 91: uncaught JavaScript exception:
at failure  
(file:/Users/jermq/Checkouts/Secure/cocoon-2.1/build/webapp/arches- 
public/flow/authentication.js, Line 91):
java.lang.NullPointerException

line 91 is:	cocoon.log.info ("FAILED");

HUH? Other log calls in my script are working fine!

the stacktrace is:

Original Exception: java.lang.NullPointerException
         at  
org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon$FOM_Log.jsFu 
nction_info(FOM_Cocoon.java:757)
         at inv4.invoke()
         at  
org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:523)
         at  
org.mozilla.javascript.FunctionObject.call(FunctionObject.java:438)
         at  
org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1244)

etc.

is FOM_Cocoon getting a null logger under certain circumstances ?

I also had a null logger in a component I am writing .....

The logger was null during all the lifecycle methods : configure,  
service, initialise, dispose etc.

I am also getting inconsistent NPEs while calling: cocoon.sendPage

I also get a weird exception while throwing errors from flowscript:

	"file:/Users/jermq/Checkouts/Secure/cocoon-2.1/build/webapp/arches- 
public/flow/authentication.js", line 104: Invalid JavaScript value of  
type org.mozilla.javascript.UniqueTag

line 104 is:		throw new Error("No failure redirection parameter given");


I have a fully up-to date CVS and apart from the 'throw new Error()'  
business, these problems were not happening last week.

	
Thanks for any help ....

regards Jeremy


Re: NPEs in FlowLayer

Posted by Ugo Cei <u....@cbim.it>.
Christopher Oliver wrote:
> Ugo Cei wrote:
> Sorry, but I don't agree. NPE's are indications of bugs. Hiding those 
> with checks for null doesn't help matters, IMO.

I have my share of doubts when it comes to these matters. This is my 
line of reasoning:

The Flowscript is a core component of Cocoon. We should apply defensive 
programming in order to protect the core from potentially buggy or 
malicious client code.

I am assuming that:

1. JXForms is "client code" and not part of the core.
2. The bug is in JXForms.

In any case, it is clearly a prerequisite of FOM_Cocoon.invalidate that 
the "request" member variable is not null. Given that, even if we find 
the bug that is causing the present problems, we cannot guarantee that 
there aren't more lurking somewhere, how do we verify that the 
prerequisite always holds?

A. Do we add a null check and log a message if the check fails?
B. Do we let the code throw an NPE without an explaining message?
C. Do we catch the NPE and rethrow some other kind of runtime exception?
D. Do we "assert request != null" and hope everybody is using Java 1.4? 
(just joking)

I agree with you that option A might hide some bugs, but I don't like 
option B either. While we wait for Java 1.3 to be considered obsolete 
and unsupported, maybe option C is the best one. What do you think?

	Ugo




Re: NPEs in FlowLayer

Posted by Christopher Oliver <re...@verizon.net>.
Ugo Cei wrote:

> Jeremy Quinn wrote:
>
>> I will login successfully, logout, then login again, the second time 
>> around, I get NPEs from cocoon.log.info. NPEs that I did not get the 
>> first time around.
>
>
> I suggest that you add some more null checks in FOM_Cocoon, if you 
> have identified the source lines that dereference nulls in your case. 
> Defensive programming is A Good Thing (TM).
>
>     Ugo
>
>
Sorry, but I don't agree. NPE's are indications of bugs. Hiding those 
with checks for null doesn't help matters, IMO.

My $0.02,

Chris


Re: NPEs in FlowLayer

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Wednesday, October 29, 2003, at 05:10 PM, Christopher Oliver wrote:

> Can you recreate this problem with a simple example you can post to 
> the list?

I'll do my best to ....

Thanks

regards Jeremy

> Jeremy Quinn wrote:
>
>>
>> On Wednesday, October 29, 2003, at 04:28 PM, Ugo Cei wrote:
>>
>>> Jeremy Quinn wrote:
>>>
>>>> I will login successfully, logout, then login again, the second 
>>>> time around, I get NPEs from cocoon.log.info. NPEs that I did not 
>>>> get the first time around.
>>>
>>>
>>> I suggest that you add some more null checks in FOM_Cocoon, if you 
>>> have identified the source lines that dereference nulls in your 
>>> case. Defensive programming is A Good Thing (TM).
>>
>>
>> :)
>>
>> Yeah, but something has broken to cause them ..... I only put them in 
>> because I am trying to see why my request params are sometimes 
>> (incorrectly) null ..... when Flow calls Flow Pipelines internally, 
>> something very strange starts happening ..... you begin to loose bits 
>> of the infrastructure after you come out the other side.
>>
>> nasty business!!
>>
>> Is anybody else attempting to do development of FlowScripts ATM with 
>> the current CVS and finding these problems? (Or is it just us two?).
>>
>> regards Jeremy
>>
>>
>
>


Re: NPEs in FlowLayer

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Wednesday, October 29, 2003, at 05:10 PM, Christopher Oliver wrote:

> Can you recreate this problem with a simple example you can post to 
> the list?

I tried a simple replication of the problem, but so far, it still 
behaves properly.
Still looking into it.

regards Jeremy

> Jeremy Quinn wrote:
>
>>
>> On Wednesday, October 29, 2003, at 04:28 PM, Ugo Cei wrote:
>>
>>> Jeremy Quinn wrote:
>>>
>>>> I will login successfully, logout, then login again, the second 
>>>> time around, I get NPEs from cocoon.log.info. NPEs that I did not 
>>>> get the first time around.
>>>
>>>
>>> I suggest that you add some more null checks in FOM_Cocoon, if you 
>>> have identified the source lines that dereference nulls in your 
>>> case. Defensive programming is A Good Thing (TM).
>>
>>
>> :)
>>
>> Yeah, but something has broken to cause them ..... I only put them in 
>> because I am trying to see why my request params are sometimes 
>> (incorrectly) null ..... when Flow calls Flow Pipelines internally, 
>> something very strange starts happening ..... you begin to loose bits 
>> of the infrastructure after you come out the other side.
>>
>> nasty business!!
>>
>> Is anybody else attempting to do development of FlowScripts ATM with 
>> the current CVS and finding these problems? (Or is it just us two?).
>>
>> regards Jeremy
>>
>>
>
>


Re: NPEs in FlowLayer

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Wednesday, October 29, 2003, at 05:10 PM, Christopher Oliver wrote:

> Can you recreate this problem with a simple example you can post to 
> the list?

Sorry, I have no sample yet ... it is difficult to simplify ...

What appears to be happening :

I am using the FlowScript version of authentication-fw, which defaults 
to using a pipeline to provide authentication xml to the framework.

The job of this pipeline (called by 
o.a.c.webapps.authentication.components.PipelineAuthenticator) is to 
look up a user with a username and password, and output xml to signify 
success or failure.

Our user data is in SQL. I wanted to be able to use Hibernate to lookup 
and generate the authentication xml. So instead of having a traditional 
pipeline with something like the SQL Transformer in it, or XSP, I made 
one using FlowScript and JXTemplate.

The problems only seems to appear when the authentication pipeline is 
provided by FlowScript.

After the this pipeline has run and control returns to the original 
login FlowScript, several of the cocoon.* FOM properties have become 
null.

Thanks

regards Jeremy


> Jeremy Quinn wrote:
>
>>
>> On Wednesday, October 29, 2003, at 04:28 PM, Ugo Cei wrote:
>>
>>> Jeremy Quinn wrote:
>>>
>>>> I will login successfully, logout, then login again, the second 
>>>> time around, I get NPEs from cocoon.log.info. NPEs that I did not 
>>>> get the first time around.
>>>
>>>
>>> I suggest that you add some more null checks in FOM_Cocoon, if you 
>>> have identified the source lines that dereference nulls in your 
>>> case. Defensive programming is A Good Thing (TM).
>>
>>
>> :)
>>
>> Yeah, but something has broken to cause them ..... I only put them in 
>> because I am trying to see why my request params are sometimes 
>> (incorrectly) null ..... when Flow calls Flow Pipelines internally, 
>> something very strange starts happening ..... you begin to loose bits 
>> of the infrastructure after you come out the other side.
>>
>> nasty business!!
>>
>> Is anybody else attempting to do development of FlowScripts ATM with 
>> the current CVS and finding these problems? (Or is it just us two?).
>>
>> regards Jeremy
>>
>>
>
>


Re: NPEs in FlowLayer

Posted by Christopher Oliver <re...@verizon.net>.
Can you recreate this problem with a simple example you can post to the 
list?

Jeremy Quinn wrote:

>
> On Wednesday, October 29, 2003, at 04:28 PM, Ugo Cei wrote:
>
>> Jeremy Quinn wrote:
>>
>>> I will login successfully, logout, then login again, the second time 
>>> around, I get NPEs from cocoon.log.info. NPEs that I did not get the 
>>> first time around.
>>
>>
>> I suggest that you add some more null checks in FOM_Cocoon, if you 
>> have identified the source lines that dereference nulls in your case. 
>> Defensive programming is A Good Thing (TM).
>
>
> :)
>
> Yeah, but something has broken to cause them ..... I only put them in 
> because I am trying to see why my request params are sometimes 
> (incorrectly) null ..... when Flow calls Flow Pipelines internally, 
> something very strange starts happening ..... you begin to loose bits 
> of the infrastructure after you come out the other side.
>
> nasty business!!
>
> Is anybody else attempting to do development of FlowScripts ATM with 
> the current CVS and finding these problems? (Or is it just us two?).
>
> regards Jeremy
>
>



Re: NPEs in FlowLayer

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Wednesday, October 29, 2003, at 04:28 PM, Ugo Cei wrote:

> Jeremy Quinn wrote:
>> I will login successfully, logout, then login again, the second time 
>> around, I get NPEs from cocoon.log.info. NPEs that I did not get the 
>> first time around.
>
> I suggest that you add some more null checks in FOM_Cocoon, if you 
> have identified the source lines that dereference nulls in your case. 
> Defensive programming is A Good Thing (TM).

:)

Yeah, but something has broken to cause them ..... I only put them in 
because I am trying to see why my request params are sometimes 
(incorrectly) null ..... when Flow calls Flow Pipelines internally, 
something very strange starts happening ..... you begin to loose bits 
of the infrastructure after you come out the other side.

nasty business!!

Is anybody else attempting to do development of FlowScripts ATM with 
the current CVS and finding these problems? (Or is it just us two?).

regards Jeremy


Re: NPEs in FlowLayer

Posted by Ugo Cei <u....@cbim.it>.
Jeremy Quinn wrote:
> I will login successfully, logout, then login again, the second time 
> around, I get NPEs from cocoon.log.info. NPEs that I did not get the 
> first time around.

I suggest that you add some more null checks in FOM_Cocoon, if you have 
identified the source lines that dereference nulls in your case. 
Defensive programming is A Good Thing (TM).

	Ugo


-- 
Ugo Cei - Consorzio di Bioingegneria e Informatica Medica
P.le Volontari del Sangue, 2 - 27100 Pavia - Italy
Phone: +39.0382.525100 - E-mail: u.cei@cbim.it


Re: NPEs in FlowLayer

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Wednesday, October 29, 2003, at 12:10 PM, Ugo Cei wrote:

> Jeremy Quinn wrote:
>> Hi All
>> I am getting mysterious NPEs in the flowlayer, while working with the 
>>  flow version of  'authentication-fw'.
>> Not only are they odd, they are completely inconsistent.
>> They tend to happen after a script redirects after eg. a bad login.
>
> I've just committed a workaround for a case where I was getting NPEs. 
> Looks like, in some cases, an already invalidated instance of 
> FOM_Cocoon is being reused, but of course all its fields have already 
> been set to null.
>
> My patch is just a workaround, since this situation should never 
> happen, but I haven't been able to determine the real cause. Besides, 
> adding a couple extra null checks isn't going to hurt anyway, and 
> should the situation arise, you'll get a message on System.err (not 
> via the Logger, since it's already been nulled as well).
>
> You might also check Vadim's commit of yesterday to see if it's 
> relevant.

Thanks Ugo

I just tried the update, but am still getting very unpredictable 
behaviour.

I will login successfully, logout, then login again, the second time 
around, I get NPEs from cocoon.log.info. NPEs that I did not get the 
first time around.

Och! its doing ma heed in!

FlowScript does seem to be very broken ATM, because all this worked 
fine last week.

regards Jeremy


Re: NPEs in FlowLayer

Posted by Ugo Cei <u....@cbim.it>.
Jeremy Quinn wrote:
> Hi All
> 
> I am getting mysterious NPEs in the flowlayer, while working with the  
> flow version of  'authentication-fw'.
> 
> Not only are they odd, they are completely inconsistent.
> They tend to happen after a script redirects after eg. a bad login.

I've just committed a workaround for a case where I was getting NPEs. 
Looks like, in some cases, an already invalidated instance of FOM_Cocoon 
is being reused, but of course all its fields have already been set to null.

My patch is just a workaround, since this situation should never happen, 
but I haven't been able to determine the real cause. Besides, adding a 
couple extra null checks isn't going to hurt anyway, and should the 
situation arise, you'll get a message on System.err (not via the Logger, 
since it's already been nulled as well).

You might also check Vadim's commit of yesterday to see if it's relevant.

	Ugo

-- 
Ugo Cei - Consorzio di Bioingegneria e Informatica Medica
P.le Volontari del Sangue, 2 - 27100 Pavia - Italy
Phone: +39.0382.525100 - E-mail: u.cei@cbim.it