You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/09/24 16:39:20 UTC

(maven-filtering) branch master updated: fix: handle missing property values in PropertyUtils

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

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-filtering.git


The following commit(s) were added to refs/heads/master by this push:
     new af24207  fix: handle missing property values in PropertyUtils
af24207 is described below

commit af2420708c103e19eec4bd6567bae834d96d110f
Author: Efe <go...@gmail.com>
AuthorDate: Thu Sep 24 19:39:13 2026 +0300

    fix: handle missing property values in PropertyUtils
    
    - Guard setProperty() against null return from getPropertyValue()
      to avoid NullPointerException when a property key exists but has no value
    - Remove dead null-guard on propValue in loadPropertyFile (path is unreachable)
    - Fix test to actually exercise the null-property NPE path
---
 .../java/org/apache/maven/shared/filtering/PropertyUtils.java |  3 +++
 .../org/apache/maven/shared/filtering/PropertyUtilsTest.java  | 11 +++++++++++
 2 files changed, 14 insertions(+)

diff --git a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
index f5046df..232b24d 100644
--- a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
+++ b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
@@ -177,6 +177,9 @@ public final class PropertyUtils {
         valueChain.add(k);
 
         String v = p.getProperty(k);
+        if (v == null) {
+            return null;
+        }
         String defaultValue = v;
         StringBuilder ret = new StringBuilder();
         int idx, idx2;
diff --git a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
index b41708f..1b8b0be 100644
--- a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
@@ -20,6 +20,7 @@ package org.apache.maven.shared.filtering;
 
 import java.io.IOException;
 import java.io.Writer;
+import java.lang.reflect.Method;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -34,6 +35,7 @@ import org.slf4j.Logger;
 import static org.apache.maven.api.di.testing.MavenDIExtension.getBasedir;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
@@ -90,6 +92,15 @@ class PropertyUtilsTest {
         assertThrows(Exception.class, () -> PropertyUtils.loadPropertyFile(nonExistent, true, false));
     }
 
+    @Test
+    void missingPropertyValue() throws Exception {
+        Method getPropertyValue =
+                PropertyUtils.class.getDeclaredMethod("getPropertyValue", String.class, Properties.class, Logger.class);
+        getPropertyValue.setAccessible(true);
+
+        assertNull(getPropertyValue.invoke(null, "missing", new Properties(), null));
+    }
+
     @Test
     void testloadpropertiesFile() throws Exception {
         Path propertyFile = Paths.get(getBasedir() + "/src/test/units-files/propertyutils-test.properties");