[
https://issues.apache.org/jira/browse/SLING-7241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16265116#comment-16265116
]
ASF GitHub Bot commented on SLING-7241:
---------------------------------------
npeltier closed pull request #1: SLING-7241 Fix SciptEngineManager
URL: https://github.com/apache/sling-org-apache-sling-pipes/pull/1
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/src/main/java/org/apache/sling/pipes/PipeBindings.java
b/src/main/java/org/apache/sling/pipes/PipeBindings.java
index b50ab57..923302d 100644
--- a/src/main/java/org/apache/sling/pipes/PipeBindings.java
+++ b/src/main/java/org/apache/sling/pipes/PipeBindings.java
@@ -74,8 +74,16 @@
* public constructor, built from pipe's resource
* @param resource pipe's configuration resource
*/
- public PipeBindings(Resource resource){
- engine.setContext(scriptContext);
+ public PipeBindings(Resource resource) throws Exception {
+ //In some contexts the nashorn engine cannot be obtained. Do fallback
to system classloader.
+ if(engine == null){
+ engine = new
ScriptEngineManager(null).getEngineByName("nashorn");
+ //Check if nashorn can still not be instantiated
+ if(engine == null){
+ throw new Exception("Can not instantiate nashorn
scriptengine. Check JVM version & capabilities.");
+ }
+ }
+ engine.setContext(scriptContext);
//add path bindings where path.MyPipe will give MyPipe current
resource path
getBindings().put(PATH_BINDING, pathBindings);
diff --git a/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
b/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
index aff153b..864812c 100644
--- a/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
+++ b/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
@@ -45,13 +45,13 @@ public void setup() throws PersistenceException {
context.load().json("/container.json", PATH_PIPE);
}
- private PipeBindings getDummyTreeBinding(){
+ private PipeBindings getDummyTreeBinding() throws Exception{
Resource resource = context.resourceResolver().getResource(PATH_PIPE +
"/" + ContainerPipeTest.NN_DUMMYTREE);
return new PipeBindings(resource);
}
@Test
- public void testEvaluateSimpleString() throws ScriptException {
+ public void testEvaluateSimpleString() throws Exception {
PipeBindings bindings = getDummyTreeBinding();
String simple = "simple string";
String evaluated = (String)bindings.evaluate(simple);
@@ -59,7 +59,7 @@ public void testEvaluateSimpleString() throws ScriptException
{
}
@Test
- public void computeEcma5Expression() {
+ public void computeEcma5Expression() throws Exception {
PipeBindings bindings = getDummyTreeBinding();
Map<String,String> expressions = new HashMap<>();
expressions.put("blah ${blah} blah", "'blah ' + blah + ' blah'");
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> [pipes] Nashorn ScriptEngine in PipeBindings is null
> ----------------------------------------------------
>
> Key: SLING-7241
> URL: https://issues.apache.org/jira/browse/SLING-7241
> Project: Sling
> Issue Type: Bug
> Components: Extensions
> Affects Versions: Pipes 1.0.4
> Environment: java.runtime.name = Java(TM) SE Runtime Environment
> java.runtime.version = 1.8.0_144-b01
> Reporter: Björn Csott
> Priority: Minor
> Attachments: error.log
>
>
> Under some unclear circumstances the ScriptEngine in PipeBindings does not
> get initialized.
> There is a solution out there to attach Nashorn to the system bundle. Appart
> from that I was able to fix it by using a different constructor:
> ScriptEngineManager(null).
> The issue can be reproduced by deploying
> https://github.com/bcsott/migration-tool
> When it fails the following is written to stderror.log:
> ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory:
> Provider jdk.nashorn.api.scripting.NashornScriptEngineFactory not found
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)