diff --git a/WHATSNEW b/WHATSNEW
index 457af5267..75e48ff15 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -7,6 +7,9 @@ Fixed bugs:
* Fixed NullPointerException in ChainedMapper
Bugzilla Report 62086
+ * Fixed NullPointerException when a mappedresource is used in pathconvert
+ Bugzilla Report 62076
+
Changes from Ant 1.10.1 TO Ant 1.10.2
=====================================
diff --git a/src/etc/testcases/taskdefs/pathconvert.xml b/src/etc/testcases/taskdefs/pathconvert.xml
index 1cdcc8cda..5a1cdf74b 100644
--- a/src/etc/testcases/taskdefs/pathconvert.xml
+++ b/src/etc/testcases/taskdefs/pathconvert.xml
@@ -17,6 +17,8 @@
-->
+
+
@@ -39,4 +41,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/org/apache/tools/ant/util/IdentityMapper.java b/src/main/org/apache/tools/ant/util/IdentityMapper.java
index 548803d67..dcfa0238f 100644
--- a/src/main/org/apache/tools/ant/util/IdentityMapper.java
+++ b/src/main/org/apache/tools/ant/util/IdentityMapper.java
@@ -50,6 +50,14 @@ public class IdentityMapper implements FileNameMapper {
*/
@Override
public String[] mapFileName(String sourceFileName) {
- return new String[] { sourceFileName };
+ if (sourceFileName == null) {
+ // The FileNameMapper#mapFileName contract states that:
+ // "if the given rule doesn't apply to the source file,
+ // implementation must return null"
+ // we consider a null source file name as non-matching and
+ // hence return null
+ return null;
+ }
+ return new String[] {sourceFileName};
}
}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java
index 41096b61c..f29dc12b9 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java
@@ -57,6 +57,17 @@ public class PathConvertTest {
buildRule.executeTarget("testnotargetos");
}
+ /**
+ * Tests that if a {@code mappedresource}, that excludes certain resources, is used in a {@code pathconvert},
+ * then it doesn't lead to a {@link NullPointerException}.
+ *
+ * @see bz-62076 for more details
+ */
+ @Test
+ public void testNonMatchingMapper() {
+ buildRule.executeTarget("test-nonmatching-mapper");
+ }
+
private void test(String target) {
buildRule.executeTarget(target);
assertEquals("test#" + BUILD_FILENAME, buildRule.getProject().getProperty("result"));