NPE in JSR-223-NetRexx support

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

NPE in JSR-223-NetRexx support

Rony G. Flatscher (wu-wien)
Hi there,

while doing some initial explorative experiments with JSR-223 I stumbled over a NPE in NetRexx with the following Java program that lists all javax.script languages and interrogates the most important information about them:
import java.util.List;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;

public class ListScriptEngines {
  public static void main(String args[]) {
    ScriptEngineManager manager = new ScriptEngineManager();
    List<ScriptEngineFactory> factories = manager.getEngineFactories();
    for (ScriptEngineFactory factory : factories) {
      System.out.println("getEngineName:\t             "+factory.getEngineName());
      System.out.println("\tgetEngineVersion:          "+factory.getEngineVersion());
      System.out.println("\tgetLanguageName:           "+factory.getLanguageName());
      System.out.println("\tgetLanguageVersion:        "+factory.getLanguageVersion());
      System.out.println("\tgetExtensions:             "+factory.getExtensions());
      System.out.println("\tgetMimeTypes:              "+factory.getMimeTypes());
      System.out.println("\tgetNames:                  "+factory.getNames());
      System.out.print  ("\tgetParameter(\"THREADING\"): ");
      System.out.println(factory.getParameter("THREADING"));
      System.out.println("----------------------");
    }
  }
}

Running it yields the following output (leaving JavaScript for comparison):
F:\work\svn\bsf4oorexx\trunk\bsf4oorexx.dev\source_java\jsr223tests>java ListScriptEngines
getEngineName:               Mozilla Rhino
        getEngineVersion:          1.7 release 3 PRERELEASE
        getLanguageName:           ECMAScript
        getLanguageVersion:        1.8
        getExtensions:             [js]
        getMimeTypes:              [application/javascript, application/ecmascript, text/javascript, text/ecmascript]
        getNames:                  [js, rhino, JavaScript, javascript, ECMAScript, ecmascript]
        test nul                ): null
        getParameter("THREADING"): MULTITHREADED
----------------------
getEngineName:               NetRexx Script Engine
        getEngineVersion:          V1.0.0
        getLanguageName:           NetRexx
        getLanguageVersion:        3.03
        getExtensions:             [.nrx]
        getMimeTypes:              [text/plain, text/NetRexx, application/NetRexx]
        getNames:                  [NetRexx, netrexx]
        getParameter("THREADING"): Exception in thread "main" java.lang.NullPointerException
        at org.netrexx.jsr223.NetRexxScriptEngineFactory.getParameter(Unknown Source)
        at ListScriptEngines.main(ListScriptEngines.java:50)
Posting here, because I do not know where to file the bug otherwise and being a little bit tight on time.

---rony

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: NPE in JSR-223-NetRexx support

rvjansen
Hi Rony,

thanks for reporting this. I reproduced and opened issue https://kenai.com/jira/browse/NETREXX-117 for you. I also fixed it. It is in rev 509 of trunk. I don’t know if you build from source. If Kermit agrees with my fix I’ll resolve the issue in JIRA and will put up a new build of the hitherto unreleased 3.04 on the web page.

best regards,

René.

On 29 apr. 2015, at 19:44, rony <[hidden email]> wrote:

Hi there,

while doing some initial explorative experiments with JSR-223 I stumbled over a NPE in NetRexx with the following Java program that lists all javax.script languages and interrogates the most important information about them:


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: NPE in JSR-223-NetRexx support

Kermit Kiser
Actually the error was in the NetRexxScriptEngineFactory getParameter method which is supposed to return an object rather than an object.toString. Here is the info from the Java 7 docs for ScriptEngineFactory which shows that the "THREADING" null value is correct for non threaded jsr223 implementations:
Object getParameter(String key)
Returns the value of an attribute whose meaning may be implementation-specific. Keys for which the value is defined in all implementations are:
  • ScriptEngine.ENGINE
  • ScriptEngine.ENGINE_VERSION
  • ScriptEngine.NAME
  • ScriptEngine.LANGUAGE
  • ScriptEngine.LANGUAGE_VERSION

The values for these keys are the Strings returned by getEngineName, getEngineVersion, getName, getLanguageName and getLanguageVersion respectively.

A reserved key, THREADING, whose value describes the behavior of the engine with respect to concurrent execution of scripts and maintenance of state is also defined. These values for the THREADING key are:

  • null - The engine implementation is not thread safe, and cannot be used to execute scripts concurrently on multiple threads.
  • "MULTITHREADED" - The engine implementation is internally thread-safe and scripts may execute concurrently although effects of script execution on one thread may be visible to scripts on other threads.
  • "THREAD-ISOLATED" - The implementation satisfies the requirements of "MULTITHREADED", and also, the engine maintains independent values for symbols in scripts executing on different threads.
  • "STATELESS" - The implementation satisfies the requirements of
  • "THREAD-ISOLATED". In addition, script executions do not alter the mappings in the Bindings which is the engine scope of the ScriptEngine. In particular, the keys in the Bindings and their associated values are the same before and after the execution of the script.
Implementations may define implementation-specific keys.
Parameters:
key - The name of the parameter
Returns:
The value for the given parameter. Returns null if no value is assigned to the key.
-------------  Here is a NetRexx version of Rony's test code:     ------------------------

import java.util.List;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;

class ListScriptEngines
 method main( args=String[]) static
    manager = ScriptEngineManager();
    factories = manager.getEngineFactories();
    factory=ScriptEngineFactory
    loop factory over factories
      Say "getEngineName:\t             " factory.getEngineName()
      Say "\tgetEngineVersion:          " factory.getEngineVersion()
      Say "\tgetLanguageName:           " factory.getLanguageName()
      Say "\tgetLanguageVersion:        " factory.getLanguageVersion()
      Say "\tgetExtensions:             " factory.getExtensions()
      Say "\tgetMimeTypes:              " factory.getMimeTypes()
      Say "\tgetNames:                  " factory.getNames()
      Say "\tgetParameter(\"THREADING\"): "
      Say factory.getParameter("THREADING")
      if factory.getParameter("THREADING")=null then say "its null"
      Say "----------------------"
      end
------------------------------------------------------------------------------------------------------------

I am currently researching JSR199, the Java Compiler API, to see if I can implement it for NetRexx compiles. If successful, the changes may allow us to implement more JSR223 features perhaps including multi-threading. I can see a possible need for that in server environments. Meanwhile the NPE fix is committed on trunk at rev 510.

-- Kermit

On 4/29/2015 11:23 AM, René Jansen wrote:
Hi Rony,

thanks for reporting this. I reproduced and opened issue https://kenai.com/jira/browse/NETREXX-117 for you. I also fixed it. It is in rev 509 of trunk. I don’t know if you build from source. If Kermit agrees with my fix I’ll resolve the issue in JIRA and will put up a new build of the hitherto unreleased 3.04 on the web page.

best regards,

René.

On 29 apr. 2015, at 19:44, rony <[hidden email]> wrote:

Hi there,

while doing some initial explorative experiments with JSR-223 I stumbled over a NPE in NetRexx with the following Java program that lists all javax.script languages and interrogates the most important information about them:



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/