Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"IllegalStateException: null" in Function.call #195

Closed
AlexanderMakarov opened this issue May 29, 2015 · 3 comments
Closed

"IllegalStateException: null" in Function.call #195

AlexanderMakarov opened this issue May 29, 2015 · 3 comments

Comments

@AlexanderMakarov
Copy link

Not sure that it is issue of library itself (maybe issue of using). But issue description absolutely not clear ("null"), even after sources investigation.

I have using Rhino to call JS function from few files from few threads (any file from any thread). Structure is:

  • "globalScope": is Scriptable. Used as common scope. Created on initialization with

    context = Context.enter();
    globalScope = (Scriptable) context.initStandardObjects();
    ... (ScriptableObject.putProperty(globalScope, ...)
    
  • "scopesCache": is HashMap<String, Scriptable>. Used to store scriptable-per-file. Each Scriptable cached on first call (of function from file). Used as

    Object calledFunction = oneFromScopesCache.get(funcName, oneFromScopesCache);
    ((Function) calledFunction).call(context, globalScope, thisScope, funcArgs);

In last line I catch:

java.lang.IllegalStateException: null
at org.mozilla.javascript.ScriptRuntime.storeScriptable(ScriptRuntime.java:4197) ~[runner.jar:2.7.0-SNAPSHOT]
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2426) ~[runner.jar:2.7.0-SNAPSHOT]
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2405) ~[runner.jar:2.7.0-SNAPSHOT]
at xxx ~[na:na]
at xxx ~[na:na]
at xxx callFunctionInGlobalScope(JavaScriptManager.java:170) ~[runner.jar:2.7.0-SNAPSHOT]

As I see it related to scratchScriptable in context

Note:

  1. Repro is not 100%. If try to run it manually not reproduced at all. But on intensive using (js handled HTTP requests, js functions called each other from few scopesCache) it reproduced oftenly.

  2. To put Scriptable into scopesCache used code:

    Scriptable scriptScope = context.newObject(globalScope);
    scriptScope.setParentScope(globalScope);
    script.exec(context, scriptScope);
    scopesCache.put("xxx", scriptScope)

@eshepelyuk
Copy link
Contributor

Hello
I am not sure neither about the exact reason of the error nor about your usage scenario, but I would recommend not to share scope object. Instead, you can cache compiled script or function instances and create new scope for each particular request. Scopes as far as I see are not intended to be shared in multi thread environments.

P S. You also may use mailing list to duplicate your question there.

@AlexanderMakarov
Copy link
Author

Thank you. I have tried your advise. But in this case I see performance degradation (about 5-10 times), seems like because I need to call script.exec in each request.

I have created topic https://groups.google.com/forum/#!topic/mozilla-rhino/WSqxDRLoeVE. Possible it has better issue repro steps description (and your advice implementation).

Should I close this issue? java.lang.IllegalStateException: null still not clear and "Scopes as far as I see are not intended to be shared in multi thread environments" not described in documentation AFAIK.

@AlexanderMakarov
Copy link
Author

Issue solved for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants