0

Environment:

  • wildfly 22
  • java 11
  • jakarta 8
  • jsf 2.3
  • primefaces 10

Migrating from Primefaces 6.2 to 10.

I am having a NPE on loading server with an app, and on render login.xhtml it throws java.lang.NullPoinerException. I found no clue on error log. Any idea where the problem is?

login.xhtml

<!DOCTYPE html>
<html lang="#{localeBean.locale}"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>#{msgs.appcode}</title>
</h:head>

<h:body>
    <h:form id="frmLogin">
        <p:inputText id="j_username" placeholder="#{msgs.user}"
                     value="#{loginBean.username}"
                     autocomplete="off">
        </p:inputText>
        <p:inputText id="j_password" type="password"
                     placeholder="#{msgs.password}"
                     value="#{loginBean.password}"
                     autocomplete="off"
                     converter="charArrayConverter"/>
        <p:commandButton id="btnButton"
                         value="#{msgs.login}"
                         action="#{loginBean.login}"/>
    </h:form>
</h:body>
</html>

LoginBean.java

@Named("loginBean")
@RequestScoped
public class LoginBean implements Serializable {

    private static final long serialVersionUID = 1689411186706761477L;

    @Inject
    Logger logger;

    @Inject
    private HttpServletRequest request;

    private String username;
    private char[] password;
    private Messages msgs;

    @Inject
    @ManagedProperty(value = "#{sessionBean}")
    private SessionBean sessionBean;

    public LoginBean() {
    }

    @PostConstruct
    private void init() {
        logger.info("loginBean");
    }

    public void login() {
        try {
            if (request.getUserPrincipal() == null) {
                request.login(username, String.valueOf(password));
            }
        } catch (ServletException ex) {
            logger.error("Error login failed", ex);
            navigate(Pages.LOGINERROR.getPage());
            return;
        }
        navigate(Pages.INDEX.getPage());
    }
...

Error log

21:36:43,292 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-1) Error Rendering View[/login.xhtml]: java.lang.NullPointerException
    at [email protected]//com.sun.faces.cdi.ManagedPropertyProducer.evaluateExpressionGet(ManagedPropertyProducer.java:87)
    at [email protected]//com.sun.faces.cdi.ManagedPropertyProducer.lambda$new$0(ManagedPropertyProducer.java:60)
    at [email protected]//com.sun.faces.cdi.CdiProducer.create(CdiProducer.java:105)
    at [email protected]//com.sun.faces.cdi.ManagedPropertyProducer.create(ManagedPropertyProducer.java:38)
    at [email protected]//org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:64)
    at [email protected]//org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
    at [email protected]//org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
    at [email protected]//org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:694)
    at [email protected]//org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:794)
    at [email protected]//org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
    at [email protected]//org.jboss.weld.util.Beans.injectBoundFields(Beans.java:336)
    at [email protected]//org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:347)
...
21:36:43,298 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /app/login.xhtml: java.lang.RuntimeException: javax.servlet.ServletException
    at [email protected]//io.undertow.servlet.handlers.security.ServletFormAuthenticationMechanism.servePage(ServletFormAuthenticationMechanism.java:172)
    at [email protected]//io.undertow.security.impl.FormAuthenticationMechanism.sendChallenge(FormAuthenticationMechanism.java:183)
    at [email protected]//io.undertow.security.impl.SecurityContextImpl$ChallengeSender.transition(SecurityContextImpl.java:301)
    at [email protected]//io.undertow.security.impl.SecurityContextImpl$ChallengeSender.transition(SecurityContextImpl.java:319)
    at [email protected]//io.undertow.security.impl.SecurityContextImpl$ChallengeSender.access$300(SecurityContextImpl.java:284)
...
Caused by: javax.servlet.ServletException
    at [email protected]//javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:725)
    at [email protected]//javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
    at [email protected]//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
    at [email protected]//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:81)
    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]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at [email protected]//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
    at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:251)
    at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.dispatchToPath(ServletInitialHandler.java:186)
    at [email protected]//io.undertow.servlet.spec.RequestDispatcherImpl.forwardImpl(RequestDispatcherImpl.java:227)
    at [email protected]//io.undertow.servlet.spec.RequestDispatcherImpl.forwardImplSetup(RequestDispatcherImpl.java:149)
    at [email protected]//io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:111)
    at [email protected]//io.undertow.servlet.handlers.security.ServletFormAuthenticationMechanism.servePage(ServletFormAuthenticationMechanism.java:170)
    ... 48 more
Caused by: java.lang.NullPointerException
    at [email protected]//com.sun.faces.cdi.ManagedPropertyProducer.evaluateExpressionGet(ManagedPropertyProducer.java:87)
    at [email protected]//com.sun.faces.cdi.ManagedPropertyProducer.lambda$new$0(ManagedPropertyProducer.java:60)
    at [email protected]//com.sun.faces.cdi.CdiProducer.create(CdiProducer.java:105)
    at [email protected]//com.sun.faces.cdi.ManagedPropertyProducer.create(ManagedPropertyProducer.java:38)
    at [email protected]//org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:64)

Error on Context path with explorer

Context Path:
/app

Servlet Path:
/index.xhtml

Path Info:
null

Query String:
null

Stack Trace:

javax.servlet.ServletException
    at [email protected]//javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:725)
    at [email protected]//javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
    at [email protected]//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
    at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
    at [email protected]//io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:173)
    at [email protected]//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at io.opentracing.contrib.opentracing-jaxrs2//io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter.doFilter(SpanFinishingFilter.java:52)
    at [email protected]//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at deployment.app.war//es.app.light.business.security.boundary.WebAuthenticator.doFilter(WebAuthenticator.java:81)
    at [email protected]//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at [email protected]//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
    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.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    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:59)
    at [email protected]//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at [email protected]//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at [email protected]//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at [email protected]//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    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:61)
    at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at [email protected]//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
    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:269)
    at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
    at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
    at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
    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.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
    at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
    at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
    at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
    at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
    at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
    at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
    at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
    at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
    at [email protected]//io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
    at [email protected]//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:841)
    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:1280)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
    at [email protected]//com.sun.faces.cdi.ManagedPropertyProducer.evaluateExpressionGet(ManagedPropertyProducer.java:87)
    at [email protected]//com.sun.faces.cdi.ManagedPropertyProducer.lambda$new$0(ManagedPropertyProducer.java:60)
    at [email protected]//com.sun.faces.cdi.CdiProducer.create(CdiProducer.java:105)
    at [email protected]//com.sun.faces.cdi.ManagedPropertyProducer.create(ManagedPropertyProducer.java:38)
    at [email protected]//org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:64)

SessionBean.java

@Named
@SessionScoped
public class SessionBean implements Serializable {

    ...

    private Logger logger;

    @Inject
    private UserProvider userPdr;
    
    @Inject
    @ManagedProperty(value = "#{localeBean}")
    private LocaleBean localeB;

    ...

    private User user;

    public SessionBean() {
        logger = LoggerFactory.getLogger(this.getClass());
    }

    @PostConstruct
    private void init() {
        try {
            dealWithSession();
            
            if(user == null) {
                user = getUser();
            }
        } catch (Exception e) {
            logger.error("Exception init {0}", e.getMessage());
        }
    }
...

LocaleBean.java

@Named
@SessionScoped
public class LocaleBean implements Serializable {

    private static final long serialVersionUID = 1511093313205693034L;

    private Locale locale;
    private final List<Locale> locales = new ArrayList<>();

    Logger logger;
    
    @PostConstruct
    public void init() {
        logger = LoggerFactory.getLogger(this.getClass());

        try {
            locales.add(new Locale("es", "ES"));
            locales.add(new Locale("ca", "ES"));

            Locale userLocale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
            if (locales.contains(userLocale)) {
                locale = locales.get(locales.indexOf(userLocale));
            } else {
                locale = locales.get(0);
            }
        } catch (Exception e) {
            logger.error("Exception: {0}", e.getMessage());
        }
    }
...
3
  • 1
    The error messages seem to point to the @ManagedProperty line. Couldn't you just @Inject private SessionBean sessionBean; and deleted the @ManagedProperty line completely? Commented Apr 19, 2021 at 22:43
  • I commented out all property sessionBean and the same error ¿? no idea! Commented Apr 20, 2021 at 6:17
  • I think that you get NPE on String.valueOf(password), because password is null when you render the page. Commented Apr 20, 2021 at 7:43

1 Answer 1

0

It was a custom theme incompatibility with pu:menu and p:menu in PF10 so I had to update theme to a PF10 compatible version.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.