You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2021/02/03 11:03:41 UTC

[myfaces-tobago] branch tobago-4.x updated: fix: NullPointerException while AJAX exception handling issue: TOBAGO-2068

This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch tobago-4.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/tobago-4.x by this push:
     new 0f09703  fix: NullPointerException while AJAX exception handling issue: TOBAGO-2068
0f09703 is described below

commit 0f09703dc07d4cea76560677fbda885a6a409aeb
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Wed Feb 3 12:02:33 2021 +0100

    fix: NullPointerException while AJAX exception handling
    issue: TOBAGO-2068
---
 .../apache/myfaces/tobago/util/WebXmlUtils.java    | 70 ++++++++++++----------
 1 file changed, 37 insertions(+), 33 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/util/WebXmlUtils.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/util/WebXmlUtils.java
index 11cbb1d..22ccbce 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/util/WebXmlUtils.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/util/WebXmlUtils.java
@@ -52,10 +52,12 @@ public class WebXmlUtils {
 
     String location = null;
 
-    Class<?> exceptionClass = exception.getClass();
-    while (exceptionClass != null && location == null) {
-      location = ERROR_PAGE_LOCATIONS.get(exceptionClass);
-      exceptionClass = exceptionClass.getSuperclass();
+    if (exception != null) {
+      Class<?> exceptionClass = exception.getClass();
+      while (exceptionClass != null && location == null) {
+        location = ERROR_PAGE_LOCATIONS.get(exceptionClass);
+        exceptionClass = exceptionClass.getSuperclass();
+      }
     }
 
     if (location == null) {
@@ -76,37 +78,39 @@ public class WebXmlUtils {
       String location500 = null;
 
       for (final Document document : webXmls) {
-        final NodeList errorPages = document.getElementsByTagName("error-page");
-
-        for (int i = 0; i < errorPages.getLength(); i++) {
-          final Node errorPage = errorPages.item(i);
-
-          String errorCode = null;
-          String exceptionType = null;
-          String location = null;
-
-          final NodeList children = errorPage.getChildNodes();
-          for (int j = 0; j < children.getLength(); j++) {
-            final Node child = children.item(j);
-            final String name = child.getNodeName();
-
-            if ("error-code".equals(name)) {
-              errorCode = child.getFirstChild().getNodeValue().trim();
-            } else if ("exception-type".equals(name)) {
-              exceptionType = child.getFirstChild().getNodeValue().trim();
-            } else if ("location".equals(name)) {
-              location = child.getFirstChild().getNodeValue().trim();
+        if (document != null) {
+          final NodeList errorPages = document.getElementsByTagName("error-page");
+
+          for (int i = 0; i < errorPages.getLength(); i++) {
+            final Node errorPage = errorPages.item(i);
+
+            String errorCode = null;
+            String exceptionType = null;
+            String location = null;
+
+            final NodeList children = errorPage.getChildNodes();
+            for (int j = 0; j < children.getLength(); j++) {
+              final Node child = children.item(j);
+              final String name = child.getNodeName();
+
+              if ("error-code".equals(name)) {
+                errorCode = child.getFirstChild().getNodeValue().trim();
+              } else if ("exception-type".equals(name)) {
+                exceptionType = child.getFirstChild().getNodeValue().trim();
+              } else if ("location".equals(name)) {
+                location = child.getFirstChild().getNodeValue().trim();
+              }
             }
-          }
 
-          if (exceptionType != null) {
-            final Class<Throwable> key = (Class<Throwable>) Class.forName(exceptionType);
-            final String value = normalizePath(externalContext, location);
-            ERROR_PAGE_LOCATIONS.put(key, value);
-          } else if ("500".equals(errorCode)) {
-            location500 = location;
-          } else if (errorCode == null && exceptionType == null) {
-            locationDefault = location;
+            if (exceptionType != null) {
+              final Class<Throwable> key = (Class<Throwable>) Class.forName(exceptionType);
+              final String value = normalizePath(externalContext, location);
+              ERROR_PAGE_LOCATIONS.put(key, value);
+            } else if ("500".equals(errorCode)) {
+              location500 = location;
+            } else if (errorCode == null && exceptionType == null) {
+              locationDefault = location;
+            }
           }
         }
       }