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

8258216: Allow Nashorn to operate when not loaded as a JPMS module #9

Merged
merged 3 commits into from
Dec 23, 2020

Conversation

szegedi
Copy link
Collaborator

@szegedi szegedi commented Dec 16, 2020

Allow Nashorn to operate when not loaded as a JPMS module


Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed

Issue

  • JDK-8258216: Allow Nashorn to operate when not loaded as a JPMS module

Download

$ git fetch https://git.openjdk.java.net/nashorn pull/9/head:pull/9
$ git checkout pull/9

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 16, 2020

👋 Welcome back attila! A progress list of the required criteria for merging this PR into main will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Dec 16, 2020
Copy link
Member

@sundararajana sundararajana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have was non-modular nashorn tested? Don't the tests assume that nashorn is run as module?

@szegedi
Copy link
Collaborator Author

szegedi commented Dec 17, 2020

Well, I did some light testing on the command line myself. I have this minimal application:

import javax.script.*;

public class X {
    public static void main(String[] args) throws ScriptException {
        ScriptEngineManager factory = new ScriptEngineManager(); 
        ScriptEngine engine = factory.getEngineByName("nashorn"); 
        engine.eval("print('Hello, World!');");
    }
}

and running it from Nashorn directory (after JAR is built) with:

java -classpath build/nashorn/dist/nashorn.jar:build/nashorn/dependencies/asm-7.3.1.jar:build/nashorn/dependencies/asm-util-7.3.1.jar X.java

Before the changes it obviously causes:

Exception in thread "main" java.lang.ExceptionInInitializerError
	at org.openjdk.nashorn.api.scripting.NashornScriptEngine$1.run(NashornScriptEngine.java:128)
	at org.openjdk.nashorn.api.scripting.NashornScriptEngine$1.run(NashornScriptEngine.java:124)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at org.openjdk.nashorn.api.scripting.NashornScriptEngine.<init>(NashornScriptEngine.java:124)
	at org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory.getScriptEngine(NashornScriptEngineFactory.java:150)
	at java.scripting/javax.script.ScriptEngineManager.getEngineByName(ScriptEngineManager.java:241)
	at X.main(X.java:6)
Caused by: java.lang.IllegalArgumentException: Null module name
	at java.base/jdk.internal.module.Checks.requireModuleName(Checks.java:46)
	...

while running it after the changes outputs

Hello, World!

as expected.

You're right that ant test target runs all the tests with Nashorn loaded as a module; that's still the preferred way. I'm doing this to foster adoption as there's a report that Nashorn doesn't work when Spring Boot based apps load it (as SB uses classpath to load app depedencies) and the referenced JBS issue was also filed by a person who seems to be on the JAX-RS expert group and is an Eclipse committer, so I suspect there might be something there too (not confirmed.) I might try to modify the test script locally for a one-time run; I'd be reluctant to add module/non-module to the test matrix.

@@ -58,6 +58,7 @@
protected static final String SCRIPTS_PKG_INTERNAL = "org/openjdk/nashorn/internal/scripts";

static final Module NASHORN_MODULE = Context.class.getModule();
static final boolean modular = NASHORN_MODULE.getName() != null;
Copy link

@efge efge Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @efge, thanks for making a comment in an OpenJDK project!

All comments and discussions in the OpenJDK Community must be made available under the OpenJDK Terms of Use. If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please Use "Add GitHub user efge for the summary.

If you are not an OpenJDK Author, Committer or Reviewer, simply check the box below to accept the OpenJDK Terms of Use for your comments.

Your comment will be automatically restored once you have accepted the OpenJDK Terms of Use.

@szegedi
Copy link
Collaborator Author

szegedi commented Dec 20, 2020

Have was non-modular nashorn tested? Don't the tests assume that nashorn is run as module?

@sundararajana I created a test-demodulator branch in my own fork of the repo building on top of this branch that's running tests with Nashorn on classpath instead of on module path.
You'll notice I moved two tests into "currently failing" in that branch as they're directly testing the module system. All other tests pass. Note that that branch is very hacky and is only meant to demonstrate the correctness of this code one time, it will not be submitted as a PR. As I said, I'd rather not add non-modular execution to the test matrix in general, at least not for now.

@szegedi szegedi merged commit 24f9901 into openjdk:main Dec 23, 2020
@szegedi szegedi deleted the demodulator branch December 23, 2020 08:44
Copy link
Member

@sundararajana sundararajana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

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

Successfully merging this pull request may close these issues.

3 participants