From 7f3406304a21c4bd2424f7eaee3be60edbd2bcf1 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 29 Oct 2008 17:39:27 +0000 Subject: [PATCH] deal with resources without name in . PR 39960. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@708948 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 ++ .../org/apache/tools/ant/taskdefs/Copy.java | 7 +++ .../apache/tools/ant/util/ResourceUtils.java | 5 ++ src/tests/antunit/taskdefs/copy-test.xml | 58 +++++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/WHATSNEW b/WHATSNEW index 3cd29d516..339e016ad 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -282,6 +282,10 @@ Fixed bugs: original error is now logged to System.err. Bugzilla Report 25086. + * failed with a NullPointerException when copying a resource + without a name. It will now fail with a meaningful error message. + Bugzilla Report 39960. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Copy.java b/src/main/org/apache/tools/ant/taskdefs/Copy.java index 624816202..9943cd619 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copy.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copy.java @@ -757,6 +757,13 @@ public class Copy extends Task { } for (int i = 0; i < toCopy.length; i++) { String[] mappedFiles = mapper.mapFileName(toCopy[i].getName()); + for (int j = 0; j < mappedFiles.length; j++) { + if (mappedFiles[j] == null) { + throw new BuildException("Can't copy a resource without a" + + " name if the mapper doesn't" + + " provide one."); + } + } if (!enableMultipleMappings) { map.put(toCopy[i], diff --git a/src/main/org/apache/tools/ant/util/ResourceUtils.java b/src/main/org/apache/tools/ant/util/ResourceUtils.java index 3e2a6ff7b..9e9b2da61 100644 --- a/src/main/org/apache/tools/ant/util/ResourceUtils.java +++ b/src/main/org/apache/tools/ant/util/ResourceUtils.java @@ -155,6 +155,11 @@ public class ResourceUtils { Project.MSG_VERBOSE); continue; } + for (int i = 0; i < targetnames.length; i++) { + if (targetnames[i] == null) { + targetnames[i] = "(no name)"; + } + } Union targetColl = new Union(); for (int i = 0; i < targetnames.length; i++) { targetColl.add(targets.getResource( diff --git a/src/tests/antunit/taskdefs/copy-test.xml b/src/tests/antunit/taskdefs/copy-test.xml index 91db6fb5d..719ca6dee 100644 --- a/src/tests/antunit/taskdefs/copy-test.xml +++ b/src/tests/antunit/taskdefs/copy-test.xml @@ -42,4 +42,62 @@ + + + length ? -1 : 0; + } + }; + } +} +]]> + + + + + + + + + + + + + + + + + + + + + + + + +