From 3f609f9775af802508e9d11307aec587cd9ff521 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 11 Aug 2008 11:40:31 +0000 Subject: [PATCH] explicitly guard against nul values, mark to and from attributes as required. PR 44790. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@684721 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/CoreTypes/mapper.html | 6 ++++-- .../org/apache/tools/ant/util/GlobPatternMapper.java | 10 ++++++++++ .../org/apache/tools/ant/util/RegexpPatternMapper.java | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/manual/CoreTypes/mapper.html b/docs/manual/CoreTypes/mapper.html index 914c1ea1c..365620930 100644 --- a/docs/manual/CoreTypes/mapper.html +++ b/docs/manual/CoreTypes/mapper.html @@ -221,7 +221,7 @@ leading directory information stripped off. Both to and

glob

-

Both to and from define patterns that may +

Both to and from are required and define patterns that may contain at most one *. For each source file that matches the from pattern, a target file name will be constructed from the to pattern by substituting the * in @@ -350,7 +350,7 @@ that don't match the from pattern will be ignored.

regexp

-

Both to and from define regular +

Both to and from are required and define regular expressions. If the source file name matches the from pattern, the target file name will be constructed from the to pattern, using \0 to \9 as @@ -571,6 +571,7 @@ the package mapper replaces directory separators found in the matched source pattern with dots in the target pattern placeholder. This mapper is particularly useful in combination with <uptodate> and <junit> output.

+

The to and from attributes are both required.

Example:
 <mapper type="package" from="*Test.java" to="TEST-*Test.xml"/>
@@ -602,6 +603,7 @@ with <uptodate> and <junit> output.

test cases. The mapper shares the sample syntax as the glob mapper.

+

The to and from attributes are both required.

Example:
 <mapper type="unpackage" from="TEST-*Test.xml" to="${test.src.dir}/*Test.java">
diff --git a/src/main/org/apache/tools/ant/util/GlobPatternMapper.java b/src/main/org/apache/tools/ant/util/GlobPatternMapper.java
index 24f4fede4..9aabf969b 100644
--- a/src/main/org/apache/tools/ant/util/GlobPatternMapper.java
+++ b/src/main/org/apache/tools/ant/util/GlobPatternMapper.java
@@ -18,6 +18,8 @@
 
 package org.apache.tools.ant.util;
 
+import org.apache.tools.ant.BuildException;
+
 /**
  * Implementation of FileNameMapper that does simple wildcard pattern
  * replacements.
@@ -95,6 +97,7 @@ public class GlobPatternMapper implements FileNameMapper {
      * @param from a string
      */
     public void setFrom(String from) {
+        if (from != null) {
         int index = from.lastIndexOf("*");
         if (index == -1) {
             fromPrefix = from;
@@ -105,6 +108,9 @@ public class GlobPatternMapper implements FileNameMapper {
         }
         prefixLength = fromPrefix.length();
         postfixLength = fromPostfix.length();
+        } else {
+            throw new BuildException("this mapper requires a 'from' attribute");
+        }
     }
 
     /**
@@ -112,6 +118,7 @@ public class GlobPatternMapper implements FileNameMapper {
      * @param to a string
      */
     public void setTo(String to) {
+        if (to != null) {
         int index = to.lastIndexOf("*");
         if (index == -1) {
             toPrefix = to;
@@ -120,6 +127,9 @@ public class GlobPatternMapper implements FileNameMapper {
             toPrefix = to.substring(0, index);
             toPostfix = to.substring(index + 1);
         }
+        } else {
+            throw new BuildException("this mapper requires a 'to' attribute");
+        }
     }
 
     /**
diff --git a/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java b/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
index 51ad6e652..2971daaed 100644
--- a/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
+++ b/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
@@ -80,6 +80,7 @@ public class RegexpPatternMapper implements FileNameMapper {
      * @throws BuildException on error.
      */
     public void setFrom(String from) throws BuildException {
+        if (from != null) {
         try {
             reg.setPattern(from);
         } catch (NoClassDefFoundError e) {
@@ -88,6 +89,9 @@ public class RegexpPatternMapper implements FileNameMapper {
             throw new BuildException("Cannot load regular expression matcher",
                                      e);
         }
+        } else {
+            throw new BuildException("this mapper requires a 'from' attribute");
+        }
     }
 
     /**
@@ -96,7 +100,11 @@ public class RegexpPatternMapper implements FileNameMapper {
      * @throws BuildException on error.
      */
     public void setTo(String to) {
+        if (to != null) {
         this.to = to.toCharArray();
+        } else {
+            throw new BuildException("this mapper requires a 'to' attribute");
+        }
     }
 
     /**