I currently have a JSF application running on Wildfly 32.0.1 with Java 21, Mojarra 4.0.7 and Omnifaces 4.4.1.
Some of the pages allow the user to upload a file.
As long as there are no input validation errors, everything works as it should. The problem occurs when the user forgets to enter a required value and the input file has already been uploaded. In this case, the following exception is thrown:
11:20:58,866 ERROR [io.undertow.request] (default task-9) UT005023: Exception handling request to /mywebapp/test/attachmentTest.xhtml: jakarta.servlet.ServletException: java.lang.InstantiationException: io.undertow.servlet.spec.PartImpl
at [email protected]//jakarta.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:709)
at [email protected]//jakarta.faces.webapp.FacesServlet.service(FacesServlet.java:449)
at [email protected]//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at [email protected]//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at [email protected]//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
at [email protected]//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at [email protected]//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.lambda$handleRequest$1(ElytronRunAsHandler.java:68)
at [email protected]//org.wildfly.security.auth.server.FlexibleIdentityAssociation.runAsFunctionEx(FlexibleIdentityAssociation.java:103)
at [email protected]//org.wildfly.security.auth.server.Scoped.runAsFunctionEx(Scoped.java:161)
at [email protected]//org.wildfly.security.auth.server.Scoped.runAs(Scoped.java:73)
at [email protected]//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.handleRequest(ElytronRunAsHandler.java:67)
at [email protected]//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
at [email protected]//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
at [email protected]//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:53)
at [email protected]//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at [email protected]//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at [email protected]//io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:60)
at [email protected]//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at org.wildfly.security.elytron-web.undertow-server-servlet@4.1.0.Final//org.wildfly.elytron.web.undertow.server.servlet.CleanUpHandler.handleRequest(CleanUpHandler.java:38)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:44)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:51)
at [email protected]//io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:276)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:132)
at [email protected]//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at [email protected]//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1421)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1421)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1421)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1421)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1421)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:256)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:101)
at [email protected]//io.undertow.server.Connectors.executeRootHandler(Connectors.java:393)
at [email protected]//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:859)
at [email protected]//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at [email protected]//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.IllegalStateException: java.lang.InstantiationException: io.undertow.servlet.spec.PartImpl
at [email protected]//jakarta.faces.component.StateHolderSaver.restore(StateHolderSaver.java:129)
at [email protected]//jakarta.faces.component.ComponentStateHelper.restoreState(ComponentStateHelper.java:321)
at [email protected]//jakarta.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1232)
at [email protected]//jakarta.faces.component.UIOutput.restoreState(UIOutput.java:235)
at [email protected]//jakarta.faces.component.UIInput.restoreState(UIInput.java:1284)
at [email protected]//com.sun.faces.application.view.FaceletPartialStateManagementStrategy.lambda$restoreView$1(FaceletPartialStateManagementStrategy.java:357)
at [email protected]//com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:125)
at [email protected]//jakarta.faces.component.UIComponent.visitTree(UIComponent.java:1266)
at [email protected]//jakarta.faces.component.UIComponent.visitTree(UIComponent.java:1278)
at [email protected]//jakarta.faces.component.UIForm.visitTree(UIForm.java:344)
at [email protected]//jakarta.faces.component.UIComponent.visitTree(UIComponent.java:1278)
at [email protected]//jakarta.faces.component.UIComponent.visitTree(UIComponent.java:1278)
at [email protected]//com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreView(FaceletPartialStateManagementStrategy.java:346)
at [email protected]//com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:90)
at [email protected]//com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:258)
at [email protected]//com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:126)
at [email protected]//jakarta.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:96)
at [email protected]//jakarta.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:96)
at deployment.myapp.ear.mywebapp.war//org.omnifaces.viewhandler.OmniViewHandler.restoreView(OmniViewHandler.java:128)
at [email protected]//com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:162)
at [email protected]//com.sun.faces.lifecycle.Phase.doPhase(Phase.java:72)
at [email protected]//com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:96)
at [email protected]//com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:131)
at [email protected]//jakarta.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:691)
... 46 more
Caused by: java.lang.InstantiationException: io.undertow.servlet.spec.PartImpl
at java.base/java.lang.Class.newInstance(Class.java:719)
at [email protected]//jakarta.faces.component.StateHolderSaver.restore(StateHolderSaver.java:127)
... 69 more
Caused by: java.lang.NoSuchMethodException: io.undertow.servlet.spec.PartImpl.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3761)
at java.base/java.lang.Class.newInstance(Class.java:706)
... 70 more
I already tried using the o:inputFile
from Omnifaces, but the behaviour is the same.
Page Bean
package com.test;
import java.io.Serializable;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import jakarta.servlet.http.Part;
@Named
@ViewScoped
public class AttachmentTest implements Serializable
{
private static final long serialVersionUID = 1L;
private String description;
private Part uploadedFile;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Part getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(Part uploadedFile) {
this.uploadedFile = uploadedFile;
}
public String doSomething() {
// do something with uploaded file;
return "attachmentTest";
}
}
View
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="jakarta.faces.core"
xmlns:ui="jakarta.faces.facelets"
xmlns:h="jakarta.faces.html"
xmlns:a="jakarta.faces.passthrough">
<h:head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
</h:head>
<h:body>
<h:form enctype="multipart/form-data">
<div>
<label for="description">Description</label>
<h:inputText id="description" value="#{attachmentTest.description}" required="true" requiredMessage="Required value"/>
<h:message for="description"/>
</div>
<div>
<label for="uploadedFile">Attachment</label>
<h:inputFile id="uploadedFile" value="#{attachmentTest.uploadedFile}"/>
<h:message for="uploadedFile"/>
</div>
<div>
<h:commandButton action="#{attachmentTest.doSomething}" value="Do Something"/>
</div>
</h:form>
</h:body>
</html>
Scenario
- User uploads file on form and does not enter description (required input)
- Form validation fails because a required value was not set
- User enters description
- User uploads file
- User submits form
- Exception is thrown
Is there a way around this problem?
Is this a bug or am I missing something here?
Any help would be greatly appreciated!
Thank you!
3