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

rmaucher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 109f216c1520c83d61d3ee62657e367ce6e95b6a
Author: opencode <[email protected]>
AuthorDate: Mon Oct 12 23:16:34 2026 +0200

    Fail fast when the compressible MIME type list is set to null
    
    The setCompressibleMimeType() method of CompressionConfig stored the
    provided value without any validation. A null value was therefore
    accepted silently and only caused a NullPointerException later, when
    getCompressibleMimeTypes() lazily tokenized the stored value while a
    response was being prepared, turning the response into an error.
    
    The setter now rejects a null value immediately with an
    IllegalArgumentException and a localized message, before the stored
    value or the parsed list cache are modified. Note that no configuration
    path is affected: the attribute value from server.xml cannot be null
    and the attribute is not exposed as a JMX attribute. Unlike the sibling
    setters for the user agent and encoding restrictions, the compressible
    MIME type list has no defined null semantics, so a fail-fast exception
    was preferred over inventing some.
---
 java/org/apache/coyote/CompressionConfig.java      |  5 +++++
 java/org/apache/coyote/LocalStrings.properties     |  1 +
 .../coyote/TestCompressionConfigSetters.java       | 25 ++++++++++++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/java/org/apache/coyote/CompressionConfig.java 
b/java/org/apache/coyote/CompressionConfig.java
index 5b30da26f4..a7f1b7b50e 100644
--- a/java/org/apache/coyote/CompressionConfig.java
+++ b/java/org/apache/coyote/CompressionConfig.java
@@ -203,8 +203,13 @@ public class CompressionConfig {
      * Sets the comma-separated list of MIME types eligible for compression.
      *
      * @param valueS comma-separated MIME type string
+     *
+     * @throws IllegalArgumentException If the provided value is null
      */
     public void setCompressibleMimeType(String valueS) {
+        if (valueS == null) {
+            throw new 
IllegalArgumentException(sm.getString("compressionConfig.compressibleMimeTypeNull"));
+        }
         compressibleMimeType = valueS;
         compressibleMimeTypes = null;
     }
diff --git a/java/org/apache/coyote/LocalStrings.properties 
b/java/org/apache/coyote/LocalStrings.properties
index a575f15789..bf625956e7 100644
--- a/java/org/apache/coyote/LocalStrings.properties
+++ b/java/org/apache/coyote/LocalStrings.properties
@@ -59,6 +59,7 @@ asyncStateMachine.invalidAsyncState=Calling [{0}] is not 
valid for a request wit
 asyncStateMachine.stateChange=Changing async state from [{0}] to [{1}]
 
 compressionConfig.ContentEncodingParseFail=Failed to parse Content-Encoding 
header when checking to see if compression was already in use
+compressionConfig.compressibleMimeTypeNull=The compressible MIME type list 
cannot be set to null
 compressionConfig.invalidCompressionValue=The value [{0}] provided for the 
compression attribute is not valid. Compression has been disabled.
 
 continueResponseTiming.invalid=The value [{0}] is not a valid configuration 
option for continueResponseTiming
diff --git a/test/org/apache/coyote/TestCompressionConfigSetters.java 
b/test/org/apache/coyote/TestCompressionConfigSetters.java
index 73d25f72f6..a3223aae6e 100644
--- a/test/org/apache/coyote/TestCompressionConfigSetters.java
+++ b/test/org/apache/coyote/TestCompressionConfigSetters.java
@@ -75,4 +75,29 @@ public class TestCompressionConfigSetters {
         compressionConfig.setCompression(null);
         Assert.assertEquals("off", compressionConfig.getCompression());
     }
+
+    @Test
+    public void testSetCompressibleMimeType() {
+        CompressionConfig compressionConfig = new CompressionConfig();
+
+        compressionConfig.setCompressibleMimeType("text/html, 
application/json");
+        Assert.assertArrayEquals(new String[] { "text/html", 
"application/json" },
+                compressionConfig.getCompressibleMimeTypes());
+    }
+
+    @Test
+    public void testSetCompressibleMimeTypeNull() {
+        CompressionConfig compressionConfig = new CompressionConfig();
+
+        try {
+            compressionConfig.setCompressibleMimeType(null);
+            Assert.fail("Expected an IllegalArgumentException for a null 
value");
+        } catch (IllegalArgumentException iae) {
+            // Expected
+        }
+
+        // The previously configured value must be unchanged
+        Assert.assertNotNull(compressionConfig.getCompressibleMimeType());
+        Assert.assertEquals("text/html", 
compressionConfig.getCompressibleMimeTypes()[0]);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to