Browse Source

ensure FileNameMapper implementations deal with null source names

https://bz.apache.org/bugzilla/show_bug.cgi?id=62076
master
Stefan Bodewig 7 years ago
parent
commit
a3246562ff
5 changed files with 14 additions and 1 deletions
  1. +3
    -0
      src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java
  2. +3
    -0
      src/main/org/apache/tools/ant/types/mappers/FilterMapper.java
  3. +2
    -1
      src/main/org/apache/tools/ant/util/FlatFileNameMapper.java
  4. +3
    -0
      src/main/org/apache/tools/ant/util/GlobPatternMapper.java
  5. +3
    -0
      src/main/org/apache/tools/ant/util/RegexpPatternMapper.java

+ 3
- 0
src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java View File

@@ -63,6 +63,9 @@ public class CutDirsMapper implements FileNameMapper {
throw new BuildException("dirs must be set to a positive number"); throw new BuildException("dirs must be set to a positive number");
} }
final char fileSep = File.separatorChar; final char fileSep = File.separatorChar;
if (sourceFileName == null) {
return null;
}
final String fileSepCorrected = final String fileSepCorrected =
sourceFileName.replace('/', fileSep).replace('\\', fileSep); sourceFileName.replace('/', fileSep).replace('\\', fileSep);
int nthMatch = fileSepCorrected.indexOf(fileSep); int nthMatch = fileSepCorrected.indexOf(fileSep);


+ 3
- 0
src/main/org/apache/tools/ant/types/mappers/FilterMapper.java View File

@@ -63,6 +63,9 @@ public class FilterMapper extends FilterChain implements FileNameMapper {
* the filterchain returns an empty string. * the filterchain returns an empty string.
*/ */
public String[] mapFileName(String sourceFileName) { public String[] mapFileName(String sourceFileName) {
if (sourceFileName == null) {
return null;
}
try { try {
Reader stringReader = new StringReader(sourceFileName); Reader stringReader = new StringReader(sourceFileName);
ChainReaderHelper helper = new ChainReaderHelper(); ChainReaderHelper helper = new ChainReaderHelper();


+ 2
- 1
src/main/org/apache/tools/ant/util/FlatFileNameMapper.java View File

@@ -49,6 +49,7 @@ public class FlatFileNameMapper implements FileNameMapper {
* @return the file name in a one-element array. * @return the file name in a one-element array.
*/ */
public String[] mapFileName(String sourceFileName) { public String[] mapFileName(String sourceFileName) {
return new String[] {new java.io.File(sourceFileName).getName()};
return sourceFileName == null ? null
: new String[] {new java.io.File(sourceFileName).getName()};
} }
} }

+ 3
- 0
src/main/org/apache/tools/ant/util/GlobPatternMapper.java View File

@@ -154,6 +154,9 @@ public class GlobPatternMapper implements FileNameMapper {
* @return a list of converted filenames * @return a list of converted filenames
*/ */
public String[] mapFileName(String sourceFileName) { public String[] mapFileName(String sourceFileName) {
if (sourceFileName == null) {
return null;
}
String modName = modifyName(sourceFileName); String modName = modifyName(sourceFileName);
if (fromPrefix == null if (fromPrefix == null
|| (sourceFileName.length() < (prefixLength + postfixLength)) || (sourceFileName.length() < (prefixLength + postfixLength))


+ 3
- 0
src/main/org/apache/tools/ant/util/RegexpPatternMapper.java View File

@@ -114,6 +114,9 @@ public class RegexpPatternMapper implements FileNameMapper {
* null if the to pattern did not match * null if the to pattern did not match
*/ */
public String[] mapFileName(String sourceFileName) { public String[] mapFileName(String sourceFileName) {
if (sourceFileName == null) {
return null;
}
if (handleDirSep) { if (handleDirSep) {
if (sourceFileName.indexOf("\\") != -1) { if (sourceFileName.indexOf("\\") != -1) {
sourceFileName = sourceFileName.replace('\\', '/'); sourceFileName = sourceFileName.replace('\\', '/');


Loading…
Cancel
Save