From c4a0c6bb16bf4cd9d91483d29b45ea2c30d1ee0b Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Sat, 16 Nov 2024 12:54:55 -0400 Subject: [PATCH] Fix #5528: isErrorPage() check in RestoreViewPhase fails when thrown exception has a null message --- .../sun/faces/lifecycle/RestoreViewPhase.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/impl/src/main/java/com/sun/faces/lifecycle/RestoreViewPhase.java b/impl/src/main/java/com/sun/faces/lifecycle/RestoreViewPhase.java index 74af50b913..ecf59e79b5 100644 --- a/impl/src/main/java/com/sun/faces/lifecycle/RestoreViewPhase.java +++ b/impl/src/main/java/com/sun/faces/lifecycle/RestoreViewPhase.java @@ -42,10 +42,6 @@ import java.util.Set; import java.util.logging.Logger; -import com.sun.faces.util.FacesLogger; -import com.sun.faces.util.MessageUtils; -import com.sun.faces.util.Util; - import jakarta.el.MethodExpression; import jakarta.faces.FacesException; import jakarta.faces.application.ProtectedViewException; @@ -70,6 +66,10 @@ import jakarta.faces.view.ViewDeclarationLanguage; import jakarta.faces.view.ViewMetadata; +import com.sun.faces.util.FacesLogger; +import com.sun.faces.util.MessageUtils; +import com.sun.faces.util.Util; + /** * Lifetime And Scope *

@@ -78,7 +78,9 @@ */ public class RestoreViewPhase extends Phase { - private static final String WEBAPP_ERROR_PAGE_MARKER = "jakarta.servlet.error.message"; + private static final String WEBAPP_ERROR_MESSAGE_MARKER = "jakarta.servlet.error.message"; // RequestDispatcher.ERROR_MESSAGE + private static final String WEBAPP_ERROR_EXCEPTION_MARKER = "jakarta.servlet.error.exception"; // RequestDispatcher.ERROR_EXCEPTION + private static final Logger LOGGER = FacesLogger.LIFECYCLE.getLogger(); private static final Set SKIP_ITERATION_HINT = EnumSet.of(SKIP_ITERATION); @@ -430,11 +432,12 @@ private void notifyAfter(FacesContext context, Lifecycle lifecycle) { * Use this method to determine if the current request is an error page to avoid the above condition. * * @param context the FacesContext for the current request - * @return true if WEBAPP_ERROR_PAGE_MARKER is found in the request, otherwise return - * false + * @return true if WEBAPP_ERROR_MESSAGE_MARKER or WEBAPP_ERROR_EXCEPTION_MARKER + * is found in the request, otherwise return false */ private static boolean isErrorPage(FacesContext context) { - return context.getExternalContext().getRequestMap().get(WEBAPP_ERROR_PAGE_MARKER) != null; + Map requestMap = context.getExternalContext().getRequestMap(); + return requestMap.get(WEBAPP_ERROR_MESSAGE_MARKER) != null || requestMap.get(WEBAPP_ERROR_EXCEPTION_MARKER) != null; } }