You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2026/10/21 08:49:54 UTC

(tomcat) branch 10.1.x updated: Review "Fix NullPointerException in ChannelException.getMessage() ..."

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

markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new 38ea651d5a Review "Fix NullPointerException in ChannelException.getMessage() ..."
38ea651d5a is described below

commit 38ea651d5a805bb89b759d8d8f5397df3bf39c89
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Oct 21 09:49:06 2026 +0100

    Review "Fix NullPointerException in ChannelException.getMessage() ..."
    
    Improve message formatting.
---
 .../apache/catalina/tribes/ChannelException.java   | 25 ++++++++++++++++------
 .../catalina/tribes/TestChannelException.java      |  2 +-
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/catalina/tribes/ChannelException.java b/java/org/apache/catalina/tribes/ChannelException.java
index 5565906f8f..784b831492 100644
--- a/java/org/apache/catalina/tribes/ChannelException.java
+++ b/java/org/apache/catalina/tribes/ChannelException.java
@@ -91,18 +91,29 @@ public class ChannelException extends Exception {
      */
     @Override
     public String getMessage() {
-        // The detail message is null when the exception is created without a
-        // message and without a cause. Use the class name as the base, in line
-        // with Throwable.toString(), to keep getMessage() null-safe
+        /*
+         * The detail message is null when the exception is created without a message and without a cause. Only append
+         * the message when present to keep getMessage() null-safe. Note that Throwable.toString() will prepend the
+         * class name.
+         */
+        StringBuilder buf = new StringBuilder();
         String base = super.getMessage();
-        StringBuilder buf = new StringBuilder(base != null ? base : getClass().getName());
+        if (base != null) {
+            buf.append(base);
+            buf.append("; ");
+        }
         if (faultyMembers == null || faultyMembers.isEmpty()) {
-            buf.append("; No faulty members identified.");
+            buf.append("No faulty members identified.");
         } else {
-            buf.append("; Faulty members:");
+            buf.append("Faulty members: ");
+            boolean first = true;
             for (FaultyMember mbr : faultyMembers) {
+                if (first) {
+                    first = false;
+                } else {
+                    buf.append("; ");
+                }
                 buf.append(mbr.getMember().getName());
-                buf.append("; ");
             }
         }
         return buf.toString();
diff --git a/test/org/apache/catalina/tribes/TestChannelException.java b/test/org/apache/catalina/tribes/TestChannelException.java
index 9319fd8c43..98732fb651 100644
--- a/test/org/apache/catalina/tribes/TestChannelException.java
+++ b/test/org/apache/catalina/tribes/TestChannelException.java
@@ -34,7 +34,7 @@ public class TestChannelException {
         ChannelException e = new ChannelException();
         String message = e.getMessage();
         Assert.assertNotNull(message);
-        Assert.assertTrue(message, message.contains(ChannelException.class.getName()));
+        Assert.assertTrue(e.toString(), e.toString().contains(ChannelException.class.getName()));
         Assert.assertTrue(message, message.contains("No faulty members identified."));
         Assert.assertNotNull(e.toString());
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org