From 8d69a59bcf918ac2e09a869f922cbff490782713 Mon Sep 17 00:00:00 2001 From: iroqueta Date: Mon, 15 Dec 2025 15:12:32 -0300 Subject: [PATCH 1/2] Fix strcmp treating null and empty strings as equal Previously, strcmp could return equality when comparing a null value with an empty string. This happened because rtrim(null) returned an empty string, causing null and "" to be treated as equivalent during comparison. This change preserves the semantic difference between null and empty strings by handling null values explicitly and delegating comparison to Comparator.nullsFirst after trimming. Behavior: - null is considered less than any non-null String - empty strings are not equal to null - trailing whitespace is ignored during comparison Issue: 207440 --- common/src/main/java/com/genexus/CommonUtil.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/genexus/CommonUtil.java b/common/src/main/java/com/genexus/CommonUtil.java index 56f1dcfd8..36050900b 100644 --- a/common/src/main/java/com/genexus/CommonUtil.java +++ b/common/src/main/java/com/genexus/CommonUtil.java @@ -19,6 +19,7 @@ import java.math.BigInteger; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Comparator; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -853,8 +854,12 @@ public static boolean dateCompare( Date left , Date right) public static int strcmp( String left , String right ) { - return rtrim(left).compareTo(rtrim(right)); - } + return Comparator.nullsFirst(String::compareTo) + .compare( + left == null ? null : rtrim(left), + right == null ? null : rtrim(right) + ); + } public static boolean strcmp2( String left , String right ) From ea660f5dc88c3c936e7ed666fb1f874377ea916a Mon Sep 17 00:00:00 2001 From: iroqueta Date: Thu, 18 Dec 2025 18:17:39 -0300 Subject: [PATCH 2/2] A json with a string field with value "null" was being serialized as "" --- common/src/main/java/com/genexus/CommonUtil.java | 2 +- java/src/test/java/com/genexus/TestCommonUtil.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/genexus/CommonUtil.java b/common/src/main/java/com/genexus/CommonUtil.java index 36050900b..02d44a005 100644 --- a/common/src/main/java/com/genexus/CommonUtil.java +++ b/common/src/main/java/com/genexus/CommonUtil.java @@ -2809,7 +2809,7 @@ else if (className.equals("long") || className.equals("java.lang.Long") || class } else if (className.equals("string") || className.indexOf("java.lang.String") != -1) { - return objStr.equals("null") ? null : objStr; + return (obj == JSONObject.NULL)? null : objStr; } else if (className.equals("double") || className.equals("java.lang.Double") || className.equals("[D")) { diff --git a/java/src/test/java/com/genexus/TestCommonUtil.java b/java/src/test/java/com/genexus/TestCommonUtil.java index 970cfd1fc..6e7765d5e 100644 --- a/java/src/test/java/com/genexus/TestCommonUtil.java +++ b/java/src/test/java/com/genexus/TestCommonUtil.java @@ -295,7 +295,7 @@ public void testConvertObjectTo() { try{ Class stringClass = Class.forName("java.lang.String"); result = CommonUtil.convertObjectTo(obj, stringClass, true); - Assert.assertEquals(null, result); + Assert.assertEquals("null", result); } catch (Exception e){ Assert.fail("Test failed " + e); }