You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Andreas Hartmann <an...@apache.org> on 2008/12/23 23:04:22 UTC

NPE in AbstractCachingProcessingPipeline when called from a Cron job

Hi Cocoon devs,

I'm using the current head of the Cocoon 2.1.x branch.

When calling a pipeline from a ServiceableCronJob, I'm getting the 
following exception:


Caused by: java.lang.NullPointerException
	at java.util.Hashtable.put(Hashtable.java:396)
	at 
org.apache.excalibur.store.impl.MRUMemoryStore.hold(MRUMemoryStore.java:216)
	at 
org.apache.excalibur.store.impl.MRUMemoryStore.store(MRUMemoryStore.java:190)
	at 
org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.generateLock(AbstractCachingProcessingPipeline.java:255)



The offending lines in AbstractCachingProcessingPipeline are:

   Object lock = 
env.getObjectModel().get(HttpEnvironment.HTTP_REQUEST_OBJECT);
   if (lock == null){
     lock = 
env.getObjectModel().get(AbstractCommandLineEnvironment.CLI_REQUEST_ID);
   }
   try {
       transientStore.store(lockKey, lock);
   } catch (IOException e) {


When called from the cron job, the values for both keys – 
HTTP_REQUEST_OBJECT and CLI_REQUEST_ID – are null.

Just a random thought: Since the BackgroundEnvironment initializes the 
CommandLineRequest, would it make sense to set the value for the 
CLI_REQUEST_ID in the object model too?

Thanks a lot in advance!

-- Andreas


-- 
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch


Re: NPE in AbstractCachingProcessingPipeline when called from a Cron job

Posted by Andreas Hartmann <an...@apache.org>.
Hi Joerg,

Joerg Heinicke schrieb:
> Andreas Hartmann wrote:
> 
>> Hi Cocoon devs,
>>
>> I'm using the current head of the Cocoon 2.1.x branch.
>>
>> When calling a pipeline from a ServiceableCronJob, I'm getting the 
>> following exception:

[…]

>> When called from the cron job, the values for both keys – 
>> HTTP_REQUEST_OBJECT and CLI_REQUEST_ID – are null.
>>
>> Just a random thought: Since the BackgroundEnvironment initializes the 
>> CommandLineRequest, would it make sense to set the value for the 
>> CLI_REQUEST_ID in the object model too?
> 
> Isn't that the same problem Thorsten had [1]?

> [1] http://marc.info/?t=121932134400001&r=1&w=4

thanks for the pointer!

Having read the thread, I guess my patch will be dangerous because 
multiple concurrent background requests (which, in contast to command 
line requests, can occur) would lock on the same object.

Maybe we'd have to introduce a dedicated BackgroundRequest which 
supports multiple concurrent threads?

-- Andreas


Re: NPE in AbstractCachingProcessingPipeline when called from a Cron job

Posted by Joerg Heinicke <jo...@gmx.de>.
Andreas Hartmann wrote:

> Hi Cocoon devs,
> 
> I'm using the current head of the Cocoon 2.1.x branch.
> 
> When calling a pipeline from a ServiceableCronJob, I'm getting the 
> following exception:
> 
> 
> Caused by: java.lang.NullPointerException
>     at java.util.Hashtable.put(Hashtable.java:396)
>     at 
> org.apache.excalibur.store.impl.MRUMemoryStore.hold(MRUMemoryStore.java:216) 
> 
>     at 
> org.apache.excalibur.store.impl.MRUMemoryStore.store(MRUMemoryStore.java:190) 
> 
>     at 
> org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.generateLock(AbstractCachingProcessingPipeline.java:255) 
> 
> The offending lines in AbstractCachingProcessingPipeline are:
> 
>   Object lock = 
> env.getObjectModel().get(HttpEnvironment.HTTP_REQUEST_OBJECT);
>   if (lock == null){
>     lock = 
> env.getObjectModel().get(AbstractCommandLineEnvironment.CLI_REQUEST_ID);
>   }
>   try {
>       transientStore.store(lockKey, lock);
>   } catch (IOException e) {
> 
> 
> When called from the cron job, the values for both keys – 
> HTTP_REQUEST_OBJECT and CLI_REQUEST_ID – are null.
> 
> Just a random thought: Since the BackgroundEnvironment initializes the 
> CommandLineRequest, would it make sense to set the value for the 
> CLI_REQUEST_ID in the object model too?

Isn't that the same problem Thorsten had [1]?

Joerg

[1] http://marc.info/?t=121932134400001&r=1&w=4

Re: NPE in AbstractCachingProcessingPipeline when called from a Cron job

Posted by Andreas Hartmann <an...@apache.org>.
Andreas Hartmann schrieb:
> When calling a pipeline from a ServiceableCronJob, I'm getting the 
> following exception:

[…]

> Just a random thought: Since the BackgroundEnvironment initializes the 
> CommandLineRequest, would it make sense to set the value for the 
> CLI_REQUEST_ID in the object model too?

Here's the patch that solves the issue for me:


Index: 
src/java/org/apache/cocoon/environment/background/BackgroundEnvironment.java
===================================================================
--- 
src/java/org/apache/cocoon/environment/background/BackgroundEnvironment.java 
(revision 729139)
+++ 
src/java/org/apache/cocoon/environment/background/BackgroundEnvironment.java 
(working copy)
@@ -22,6 +22,7 @@
  import org.apache.cocoon.environment.Context;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
+import 
org.apache.cocoon.environment.commandline.AbstractCommandLineEnvironment;
  import org.apache.cocoon.environment.commandline.CommandLineContext;
  import org.apache.cocoon.environment.commandline.CommandLineRequest;
  import org.apache.cocoon.environment.commandline.CommandLineResponse;
@@ -65,6 +66,7 @@
          this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
                               new CommandLineResponse());
          this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT, ctx);
+ 
this.objectModel.put(AbstractCommandLineEnvironment.CLI_REQUEST_ID, "");
      }

      /**
@@ -89,6 +91,7 @@
                               new CommandLineResponse());
          this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT,
                               new 
CommandLineContext(context.getAbsolutePath()));
+ 
this.objectModel.put(AbstractCommandLineEnvironment.CLI_REQUEST_ID, new 
String(uri));
      }

      /**


-- Andreas