Reply To: NPE in RewritePhaseListener.handlePhaseOperation

Splash Forums Rewrite Users NPE in RewritePhaseListener.handlePhaseOperation Reply To: NPE in RewritePhaseListener.handlePhaseOperation

#25466

Luke
Participant

So I grabbed your source code and built 2.0.9.Final-SNAPSHOT.

I added log messages to RewritePhaseListener:


                @Override
                  public void performInSubflow(ServletRewrite<?, ?> rewriteEvent, EvaluationContext context)
                  {
                     try {
                        operation.performOperation((HttpServletRewrite) rewriteEvent, context);
System.out.println("rewrite.getRequest = " + rewriteEvent.getRequest());
System.out.println("rewrite.getRequest.getAttribute = " + rewriteEvent.getRequest().getAttribute(RewriteLifecycleContext.LIFECYCLE_CONTEXT_KEY));
                        List<RewriteResultHandler> resultHandlers = ((HttpRewriteLifecycleContext) ((HttpServletRewrite) rewriteEvent)
                                 .getRequest().getAttribute(RewriteLifecycleContext.LIFECYCLE_CONTEXT_KEY))
                                 .getResultHandlers();
System.out.println("resultHandlers = " + resultHandlers);
                        int handlerCount = resultHandlers.size();
                        for (int i = 0; i < handlerCount; i++)
                        {
                          RewriteResultHandler handler = resultHandlers.get(i);
                           System.out.println("operation.getEvent = " + operation.getEvent());
                           if (handler.handles(operation.getEvent()))
                              handler.handleResult(operation.getEvent());
                        }
                     }
                     catch (Exception e) {
                                 if (e instanceof NullPointerException) {
                                                                System.err.println("NullPointerException caught");
                                 }
                                 else { 
                                throw new RewriteException("Failed to handle PhaseOperation [" + operation + "]", e);
                      }
                     }
                  }

               });
      return flow;
   }

The debug output indicates the InboundRewrite POST causes the NullPointerException to be thrown. If I catch the NPE (and not rethrow it), application navigations work correctly. I am not sure what is null. I assume the NPE is bubbling up from the handler methods. I hope this helps. I still contend this is a timing problem, because I never get an error on weblogic 12c apps. The tomcat derivatives like JBoss and Glassfish throw the errors. Also, IE 11 never causes the NPE to be thrown regardless of server.



23:58:31,363 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) rewrite.getRequest = http://localhost:8080/captor/glossary.jsf

23:58:31,363 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) rewrite.getRequest.getAttribute = org.ocpsoft.rewrite.servlet.impl.HttpRewriteContextImpl@682e8f6

23:58:31,363 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) resultHandlers = [org.ocpsoft.rewrite.servlet.impl.HttpRewriteResultHandler@7a9b0ccb]

23:58:31,363 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) operation.getEvent = InboundRewrite [POST url=http://localhost:8080/captor/project/2/glossary?cid=4, flow=UN_HANDLED, dispatchResource=/glossary.jsf]

23:58:31,363 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) NullPointerException caught