Browse Source

Fix character setters which are given empty string values

PR:	12186


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274149 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
17f0831297
2 changed files with 21 additions and 3 deletions
  1. +10
    -2
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  2. +11
    -1
      src/main/org/apache/tools/ant/filters/ReplaceTokens.java

+ 10
- 2
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -257,7 +257,7 @@ public class IntrospectionHelper implements BuildListener {
particular order.
*/
}
AttributeSetter as = createAttributeSetter(m, args[0]);
AttributeSetter as = createAttributeSetter(m, args[0], propName);
if (as != null) {
attributeTypes.put(propName, args[0]);
attributeSetters.put(propName, as);
@@ -723,12 +723,15 @@ public class IntrospectionHelper implements BuildListener {
* Must not be <code>null</code>.
* @param arg The type of the single argument of the bean's method.
* Must not be <code>null</code>.
* @param attrName the name of the attribute for which the setter is being
* created.
*
* @return an appropriate AttributeSetter instance, or <code>null</code>
* if no appropriate conversion is available.
*/
private AttributeSetter createAttributeSetter(final Method m,
Class arg) {
Class arg,
final String attrName) {
// use wrappers for primitive classes, e.g. int and
// Integer are treated identically
final Class reflectedArg = PRIMITIVE_TYPE_MAP.containsKey (arg)
@@ -748,6 +751,11 @@ public class IntrospectionHelper implements BuildListener {
return new AttributeSetter() {
public void set(Project p, Object parent, String value)
throws InvocationTargetException, IllegalAccessException {
if (value.length() == 0) {
throw new BuildException("The value \"\" is not a "
+ "legal value for attribute \""
+ attrName + "\"");
}
m.invoke(parent, new Character[] {new Character(value.charAt(0))});
}



+ 11
- 1
src/main/org/apache/tools/ant/filters/ReplaceTokens.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,6 +57,7 @@ import java.io.IOException;
import java.io.Reader;
import java.util.Hashtable;
import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.BuildException;

/**
* Replaces tokens in the original input with user-supplied values.
@@ -303,9 +304,18 @@ public final class ReplaceTokens
final String type = params[i].getType();
if ("tokenchar".equals(type)) {
final String name = params[i].getName();
String value = params[i].getValue();
if ("begintoken".equals(name)) {
if (value.length() == 0) {
throw new BuildException("Begin token cannot "
+ "be empty");
}
beginToken = params[i].getValue().charAt(0);
} else if ("endtoken".equals(name)) {
if (value.length() == 0) {
throw new BuildException("End token cannot "
+ "be empty");
}
endToken = params[i].getValue().charAt(0);
}
} else if ("token".equals(type)) {


Loading…
Cancel
Save