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

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 3dd842ffd [LANG-1841] Return false for null in 
StrBuilder.equalsIgnoreCase (#1912)
3dd842ffd is described below

commit 3dd842ffdb3ee2298a922227e39ad78221e5481a
Author: wenwenwu999-maker <[email protected]>
AuthorDate: Fri Dec 4 21:01:42 2026 +0800

    [LANG-1841] Return false for null in StrBuilder.equalsIgnoreCase (#1912)
    
    Check for null before reading the other builder size, matching the equals 
overload and the documented argument contract. Cover both empty and non-empty 
receivers.
    
    Assisted-By: OpenAI Codex
---
 src/main/java/org/apache/commons/lang3/text/StrBuilder.java     | 2 +-
 src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java 
b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
index 2257c2bae..74cbedf67 100644
--- a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
@@ -1901,7 +1901,7 @@ public boolean equalsIgnoreCase(final StrBuilder other) {
         if (this == other) {
             return true;
         }
-        if (this.size != other.size) {
+        if (other == null || this.size != other.size) {
             return false;
         }
         final char[] thisBuf = this.buffer;
diff --git a/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java 
b/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java
index 6958ab676..10f3d8ad9 100644
--- a/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java
@@ -38,6 +38,8 @@
 import org.apache.commons.lang3.AbstractLangTest;
 import org.apache.commons.lang3.ArrayUtils;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 /**
  * Tests for {@link org.apache.commons.lang3.text.StrBuilder}.
@@ -710,6 +712,12 @@ void testEqualsIgnoreCase() {
         assertTrue(sb1.equalsIgnoreCase(sb2));
     }
 
+    @ParameterizedTest
+    @ValueSource(strings = {"", "abc"})
+    void testEqualsIgnoreCaseNull(final String contents) {
+        assertFalse(new StrBuilder(contents).equalsIgnoreCase(null));
+    }
+
     @Test
     void testGetChars () {
         final StrBuilder sb = new StrBuilder();

Reply via email to