COCOON-1579 describes a continuation issue when using rhino 1.6 in cocoon 2.1.10+. The workaround is to replace rhino 1.6 with the previous version. Before compiling cocoon, please follow this steps:

For Cocoon 2.1:

  1. Download rhino1.5r4-continuations-R26.jar and locate it on "$COCOON/lib/core" folder.

  2. Delete js-1.6R5.jar from "$COCOON/lib/core".
  3. Change the jar location (<lib/>) for rhino on $COCOON/lib/jars.xml from

  <file>
    <title>Continuations-based JavaScript engine</title>
    <description>Rhino is an implementation of JavaScript in Java.</description>
    <used-by>Control flow</used-by>
    <lib>core/js-1.6R5.jar</lib>
    <homepage>http://svn.cocoondev.org/repos/rhino+cont/</homepage>    
  </file>

to

  <file>
    <title>Continuations-based JavaScript engine</title>
    <description>Rhino is an implementation of JavaScript in Java.</description>
    <used-by>Control flow</used-by>
    <lib>core/rhino1.5r4-continuations-R26.jar</lib>
    <homepage>http://svn.cocoondev.org/repos/rhino+cont/</homepage>    
  </file>

4. Revert the code changes for rhino1.6 which are 2 and are commented in the code base:

public Object jsFunction_getComponent(String id)
    throws Exception {
    // To use rhino1.5r4-continuations-R26.jar as a workaround for COCOON-1579: Uncomment the next line and comment the original return.
    // return getServiceManager().lookup(id);
    return org.mozilla.javascript.Context.javaToJS(getServiceManager().lookup(id), getParentScope());
}

script = ctx.compileReader(
    // To use rhino1.5r4-continuations-R26.jar as a workaround for COCOON-1579: Uncomment the next line.
    // getRootScope(null), //scope
    new StringReader(jsText), // in
    sourceName == null ? "<unknown>" : sourceName, // sourceName
    DomHelper.getLineLocation(element), // lineNo
    null // securityDomain
);

5. Then you can build cocoon by running the script (build.bat or build.sh)


For Cocoon 2.2:

1.Download rhino1.5r4-continuations-R26.jar and deploy it in your local maven repo with the next command

 mvn deploy:deploy-file -Durl=file:///m2-repo -DrepositoryId=some.id -Dfile=/path-to-rhino-jar/rhino1.5r4-continuations-R26.jar -DgroupId=rhino -DartifactId=js -Dversion=1.5r4-continuations  -Dpackaging=jar

2. Change the rhino's dependency to one recently created, in "$COCOON/parent/pom.xml"

<dependency>
 <groupId>rhino</groupId>
 <artifactId>js</artifactId>
 <version>1.6R7</version>
</dependency>

<dependency>
 <groupId>rhino</groupId>
 <artifactId>js</artifactId>
 <version>1.5r4-continuations</version>
</dependency>

3. Change the code to use rhino 1.5r4-continuations api. These are the changes:

cocoon/components/flow/javascript/LocationTrackingDebugger.java

import org.mozilla.javascript.NativeFunction;

if (ex.sourceName() != null) {
    return new LocationImpl(ex.getName(), ex.sourceName(), ex.lineNumber(), ex.columnNumber());

if (ex.getSourceName() != null) {
    return new LocationImpl(ex.getName(), ex.getSourceName(), ex.getLineNumber(), ex.getColumnNumber());

public void handleCompilationDone(Context cx, DebuggableScript fnOrScript, String source)

public void handleCompilationDone(Context cx, DebuggableScript fnOrScript, StringBuffer source)

public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript)

public DebugFrame enterFrame(Context cx, Scriptable scope, Scriptable thisObj, Object[] args, DebuggableScript fnOrScript)

public void onLineChange(Context cx, int lineNumber)

public void onLineChange(Context cx, int lineNumber, boolean breakpoint)

if (script.isFunction()) {
    name = script.getFunctionName();
} else {
    name = "[script]";
}

Scriptable obj = script.getScriptable();
name = obj instanceof NativeFunction ? ((NativeFunction)obj).getFunctionName() : "Top-level script";
if (name == null || name.length() == 0) {
    name = "[unnamed]";
}

cocoon/components/flow/javascript/fom/FOM_Cocoon.java:

return org.mozilla.javascript.Context.javaToJS(currentCall.webAppContext.getBean(id),                                                       getParentScope());

return currentCall.webAppContext.getBean(id);

return org.mozilla.javascript.Context.javaToJS(obj, getParentScope());

return obj;

result = org.mozilla.javascript.Context.javaToJS(result, start);

result = wrap(start, result, null);

cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java:

import java.io.StringReader;

Script compiledScript = cx.compileReader(reader, src.getURI(), 1, null);

Script compiledScript = cx.compileReader(scope, reader, src.getURI(), 1, null);

fun = context.compileString(funName, null, 1, null).exec (context, thrScope);

fun = context.compileReader (thrScope, new StringReader(funName), null, 1, null).exec (context, thrScope);

cocoon/components/flow/javascript/fom/FOM_WebContinuation.java

return org.mozilla.javascript.Context.javaToJS(
                wk.getAttribute(name),
                getParentScope());

return org.mozilla.javascript.Context.toObject(
                wk.getAttribute(name),
                getParentScope());

return org.mozilla.javascript.Context.javaToJS(
                wk.getAttributeNames(),
                getParentScope());

return org.mozilla.javascript.Context.toObject(
                wk.getAttributeNames(),
                getParentScope());

forms/util/JavaScriptHelper.java, Uncomment line 65

// To use rhino1.5r4-continuations-R26.jar as a workaround for COCOON-1579: Uncomment the next line.
// getRootScope(null), //scope

// To use rhino1.5r4-continuations-R26.jar as a workaround for COCOON-1579: Uncomment the next line.
getRootScope(null), //scope

cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java

compiledScript = cx.compileReader(reader, src.getURI(), 1, null );
   to
{{{
compiledScript = cx.compileReader(scope, reader, src.getURI(), 1, null);

compiledScript = cx.compileReader(reader, src.getURI() + INTERCEPTION_POSTFIX, 1, null );

compiledScript = cx.compileReader(scope, reader, src.getURI()  + INTERCEPTION_POSTFIX, 1, null);

if (ee.sourceName() != null) {
    Context.reportRuntimeError(msg,
                               ee.sourceName(),
                               ee.lineNumber(),
                               ee.lineSource(),
                               ee.columnNumber());

if (ee.getSourceName() != null) {
    Context.reportRuntimeError(msg,
                               ee.getSourceName(),
                               ee.getLineNumber(),
                               ee.getLineSource(),
                               ee.getColumnNumber());

if (ee.sourceName() != null) {
    Context.reportRuntimeError(msg,
                               ee.sourceName(),
                               ee.lineNumber(),
                               ee.lineSource(),
                               ee.columnNumber());

if (ee.getSourceName() != null) {
    Context.reportRuntimeError(msg,
                               ee.getSourceName(),
                               ee.getLineNumber(),
                               ee.getLineSource(),
                               ee.getColumnNumber());

components/language/markup/xsp/JSGenerator.java, change in line 111

script = context.compileReader(new FileReader(file), file.toString(), 1, null);

script = context.compileReader(global, new FileReader(file), file.toString(), 1, null);

java/org/apache/cocoon/el/impl/javascript/JavaScriptExpression.java

import java.io.StringReader;

this.script = ctx.compileString(getExpression(), "", 1, null);

this.script = ctx.compileReader(getScope(rootScope), new StringReader(getExpression()), "", 1, null);
} catch (Exception e) {
   if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
   } else{
        throw new RuntimeException("Runtime exception.", e);
   }

java/org/apache/cocoon/el/impl/javascript/JavaScriptTestCase.java change line 40,

assertEquals(new Integer(3), result);

assertEquals(new Double(3), result);

4. Build cocoon with maven ( mvn -P allblocks clean install )

WorkaroundForCOCOON-1579 (last edited 2009-09-20 23:42:34 by localhost)