Recent Changes - Search:

edit SideBar

JSClassLoaderProblem

The problem is that some of the Robot demos were failing to find Ptolemy classes.

In particular, exporting two models in a row by editing $PTII/ptolemy/configs/models.txt so that it contains:

$CLASSPATH/ptolemy/actor/lib/vertx/demo/TokenTransmissionTime/Receiver.xml
$CLASSPATH/ptolemy/demo/Robot/RandomWalkIntruder.xml

and then running

cd $PTII/ptolemy/vergil/basic/export/test/junit
make long_test
resulted in the second model failing with:

####### 2 Mon Sep 07 10:52:28 PDT 2015 $PTII/bin/ptinvoke ptolemy.vergil.basic.export.Expor\
tModel -force htm -run -openComposites -timeOut 30000 -whiteBackground ptolemy/demo/Robot/Ra\
ndomWalkIntruder.xml $PTII/ptolemy/demo/Robot/RandomWalkIntruder
reading configuration
Updating local copy of the accessors repository.
In "/Users/cxh/ptII/org/terraswarm/accessor/accessors", about to execute:
    svn update --accept postpone
Updating '.':
At revision 295.
All Done
Updated accessor repository.
ptolemy.kernel.util.InternalErrorException: Element <param name="script" value="
    //
function fire() {
    var store = get(storeLocation);
    var theKey = get(key);
    var toRemove = get(remove);
    var theValue = get(value);
    var url = store + '/get?id=' + theKey;
    var produce;
    try {
        if (toRemove) {
            if (theKey != "
") {
                produce = readURL(url);
                url = store + '/delete?id=' + theKey;
                readURL(url);
                if (produce != "
") {
                    send(produce, result);
                }
            }
        } else {
            // toRemove == false. If there is a value, use it to set.
            if (theValue != "
") {
                // FIXME: Escape theValue to make a valid URL.
                url = store + '/set?id=' + encodeURIComponent(theKey) + '&value=' + encodeUR\
IComponent(theValue);
                readURL(url);
                send(theValue, result);
            } else {
                var valueFromStore = decodeURIComponent(readURL(url));
                send(valueFromStore, result);
            }
        }
    } catch (exception) {
        send(exception.toString(), error);
    }
}
    //
  "
/> caused an exception to be thrown.
  in .RandomWalkIntruder.KeyValueStore2
Because:
Error evaluating expression:

    // ...
  in .RandomWalkIntruder.KeyValueStore2.script
Because:
Failed to load $CLASSPATH/ptolemy/actor/lib/jjs/localFunctions.js.
  in .RandomWalkIntruder.KeyValueStore2
Because:
Error: Error loading ptolemy.data.ArrayToken classptolemy.data.ArrayToken java.class.path pr\
operty: /Users/cxh/ptII:../../../../../..:/Users/cxh/ptII/lib/junit-4.8.2.jar:/Users/cxh/ptI\
I/lib/JUnitParams-0.4.0.jar:/Users/cxh/ptII/lib/ptjacl.jar::/Users/cxh/ptII/ptolemy/actor/pt\
alon/antlr/antlr.jar::/Users/cxh/ptII/lib/jetty-all-8.1.5-v20120716.jar:/Users/cxh/ptII/lib/\
javax.servlet-api-3.0.1.jar:/Users/cxh/ptII/lib/smack.jar:
...
webcam-capture-0.3.10.jar:/Users/cxh/ptII/lib/slf4j-api-1.7.2.jar:/Users/cxh/ptII/lib/bridj-0.6.2.\
jar::/Users/cxh/ptII/lib/slf4j-nop-1.7.12.jar user.dir property (current working directory): /User\
s/cxh/ptII/ptolemy/vergil/basic/export/test/junit in <eval> at line number 399 at column number 4
  in .RandomWalkIntruder.KeyValueStore2.script
Because:
Error evaluating expression:

    // ...
  in .RandomWalkIntruder.KeyValueStore2.script
Because:
...

and then the stack trace repeats many times.

A clue is that this change fixed a similar problem:

* [r73033] /trunk/ptolemy/actor/gui/ConfigurationApplication.java,
/trunk/ptolemy/actor/gui/GenerateCopyrights.java,
/trunk/ptolemy/actor/gui/HTMLAbout.java,
/trunk/ptolemy/actor/gui/HTMLViewerTableau.java,
/trunk/ptolemy/actor/gui/JNLPUtilities.java,
/trunk/ptolemy/actor/gui/QueryUtilities.java,
/trunk/ptolemy/actor/ptalon/PtalonActor.java,
/trunk/ptolemy/cg/gui/CodeGeneratorGUI.java,
/trunk/ptolemy/cg/kernel/generic/CodeGeneratorUtilities.java,
/trunk/ptolemy/cg/kernel/generic/program/procedural/c/CCodeGenerator.java,
/trunk/ptolemy/util/ClassUtilities.java,
/trunk/ptolemy/util/StringUtilities.java,
/trunk/ptolemy/vergil/actor/DocBuilderGUI.java,
/trunk/ptolemy/verification/gui/MathematicalModelConverterGUI.java:
Unfortunately, Thread.currentThread().getContextClassLoader() can
return null. This happened when
/ptolemy/actor/lib/vertx/demo/TokenTransmissionTime/Sender.xml
failed and subsequent calls to
ConfigurationApplication.openModelOrEntity() would fail because
the configuration could not be found. So, we have our own
getResource() that handles this.

There were two fixes for the above:

  1. Use a version of getResource() that properly handles this issue
  2. While exporting models, don't run vertx/demo/TokenTransmissionTime/Sender.xml

In our current failure, we are running vertx/demo/TokenTransmissionTime/Receiver.xml, which hangs because there is no input and is stopped by the export process after 30 seconds.

Probably what is happening here is that getContextClassLoader() is returning null when called by Nashorn.

A workaround would be to check this early on and set it to the default class loader if necessary.

A solution was to modify MoMLParser.parse(URL base, String systemID, Reader reader) so that it invokes

       if (Thread.currentThread().getContextClassLoader() == null) {
            Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
        }
Edit - History - Print - Recent Changes - Search
Page last modified on September 07, 2015, at 11:30 AM