question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FileUpload: Requires Nashorn Engine

See original GitHub issue

Describe the defect The FileUpload component requires the Nashorn Engine. With JEP 372 this engine was removed from the JDK 15.

Environment:

  • PF Version: 8.0
  • JSF + version: MyFaces 2.3.1
  • Affected browsers: Chrome, but this seems server-side

To Reproduce Steps to reproduce the behavior:

  1. Install JDK 15
  2. Upload WAR on Wildfly 19+
  3. upload a txt.file
  4. See error
13:06:59,538 WARNING [org.primefaces.util.FileUploadUtils] (default task-17) The type of the uploaded file test.txt could not be validated: javax.script.ScriptException: java.lang.NullPointerException: JavaScript ScriptEngine not available via the context ClassLoader or the extension ClassLoader.
	at org.primefaces.util.FileUploadUtils.isValidFileName(FileUploadUtils.java:176)
	at org.primefaces.util.FileUploadUtils.isValidType(FileUploadUtils.java:143)
	at org.primefaces.util.FileUploadUtils.isValidFile(FileUploadUtils.java:297)
	at org.primefaces.component.fileupload.NativeFileUploadDecoder.decodeAdvanced(NativeFileUploadDecoder.java:101)
	at org.primefaces.component.fileupload.NativeFileUploadDecoder.decode(NativeFileUploadDecoder.java:53)
	at org.primefaces.component.fileupload.FileUploadRenderer.decode(FileUploadRenderer.java:59)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIComponentBase.decode(UIComponentBase.java:509)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIInput.decode(UIInput.java:798)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:886)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIInput.processDecodes(UIInput.java:692)
	at com.sun.jsf-impl@2.3.9.SP08//com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:606)
	at com.sun.jsf-impl@2.3.9.SP08//com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:159)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIComponent.visitTree(UIComponent.java:1456)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIForm.visitTree(UIForm.java:355)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
	at com.sun.jsf-impl@2.3.9.SP08//com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:400)
	at com.sun.jsf-impl@2.3.9.SP08//com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:261)
	at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:65)
	at javax.faces.api@3.0.0.SP02//javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:228)
	at org.omnifaces.context.OmniPartialViewContext.processPartial(OmniPartialViewContext.java:122)
	at javax.faces.api@3.0.0.SP02//javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:1008)
	at com.sun.jsf-impl@2.3.9.SP08//com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:55)
	at com.sun.jsf-impl@2.3.9.SP08//com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
	at com.sun.jsf-impl@2.3.9.SP08//com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
	at javax.faces.api@3.0.0.SP02//javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:707)
	at javax.faces.api@3.0.0.SP02//javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
	at io.opentracing.contrib.opentracing-jaxrs2//io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter.doFilter(SpanFinishingFilter.java:52)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
	at org.wildfly.extension.undertow@19.1.0.Final//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
	at io.undertow.core@2.1.0.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
	at io.undertow.core@2.1.0.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.core@2.1.0.Final//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
	at io.undertow.core@2.1.0.Final//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
	at io.undertow.core@2.1.0.Final//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
	at io.undertow.core@2.1.0.Final//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
	at io.undertow.core@2.1.0.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at org.wildfly.extension.undertow@19.1.0.Final//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
	at io.undertow.core@2.1.0.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at org.wildfly.extension.undertow@19.1.0.Final//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
	at io.undertow.core@2.1.0.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
	at org.wildfly.extension.undertow@19.1.0.Final//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
	at org.wildfly.extension.undertow@19.1.0.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1541)
	at org.wildfly.extension.undertow@19.1.0.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1541)
	at org.wildfly.extension.undertow@19.1.0.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1541)
	at org.wildfly.extension.undertow@19.1.0.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1541)
	at org.wildfly.extension.undertow@19.1.0.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1541)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
	at io.undertow.servlet@2.1.0.Final//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
	at io.undertow.core@2.1.0.Final//io.undertow.server.Connectors.executeRootHandler(Connectors.java:370)
	at io.undertow.core@2.1.0.Final//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
	at org.jboss.threads@2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
	at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
	at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.NullPointerException: JavaScript ScriptEngine not available via the context ClassLoader or the extension ClassLoader.
	... 81 more

Expected behavior Working file upload if the nashorn type validator is not present or an output for a workaround like remove allowTypes on JDK 15+

Example XHTML

<h:form
    enctype="multipart/form-data"
>
    <p:fileUpload
        mode="advanced"
        auto="true"
        allowTypes="/(\.|\/)txt$/"
    />
</h:form>

P.S.

It does work without allowTypes

<h:form
    enctype="multipart/form-data"
>
    <p:fileUpload
        mode="advanced"
        auto="true"
    />
</h:form>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:29 (23 by maintainers)

github_iconTop GitHub Comments

2reactions
jasonex7commented, Aug 18, 2022

Good point. @commodis can you add this to your PF app and see if it works.

<dependency>
  <groupId>org.mozilla</groupId>
  <artifactId>rhino</artifactId>
  <version>1.7.13</version>
</dependency>

it should detect the Rhino JS engine since its pluggable and validate using Rhino on JDK15+ right now. We might not need to do anything except update our documentation?

I just tried adding the Rhino Depependency to the maven pom.xml. Even though it is located at /WEB-INF/lib/rhino-1.7.13.jar the class loader does not pick the library up. Hence probably the same exception as in the first post was thrown.

To anyone trying to workaround this problem in PrimeFaces 8.x with Java 15+, the correct dependency you have to add to your pom.xml is the following:

<dependency>
    <groupId>org.mozilla</groupId>
    <artifactId>rhino-engine</artifactId>
    <version>1.7.14</version>
</dependency>

That dependency has the corresponding SPI file in META-INF/services path.

1reaction
julioAzocarcommented, Aug 15, 2022

solucion se actualiza primefaces de 8.0 a 11.0.0 y no arrojo mas error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Primefaces 8.0 fileupload + JDK 11 -> Nashorn engine warning
Hi! I am using Primefaces 8.0 and JDK 11 latest. When I use Primefaces fileupload component I am getting this error message:
Read more >
FileUpload: Requires Nashorn Engine - Bountysource
The FileUpload component requires the Nashorn Engine. With JEP 372 this engine was removed from the JDK 15. Environment: PF Version: 8.0; JSF...
Read more >
JavaScript Connector - Temenos Quantum Documentation
You can upload custom JavaScript files to Kony Fabric. ... If Java version 1.7 or 1.8, then it uses Nashorn JavaScript engine; If...
Read more >
Reuse Nashorn ScriptEngine in Servlet - java - Stack Overflow
I want to execute a JavaScript within a servlet. Is it possible to reuse the same Scripting Engine across all servlet invocations? Servlet...
Read more >
Use Nashorn Engine To Do Server-Side Rendering with React
Use Nashorn Engine To Do Server-Side Rendering with React ... So the fundamental capabilities Nashorn need to provide is showing in.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found