conor 2003/02/19 06:40:37
Modified: src/main/org/apache/tools/ant IntrospectionHelper.java
src/main/org/apache/tools/ant/filters ReplaceTokens.java
Log:
Fix character setters which are given empty string values
PR: 12186
Revision Changes Path
1.48 +10 -2
ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
Index: IntrospectionHelper.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -w -u -r1.47 -r1.48
--- IntrospectionHelper.java 11 Feb 2003 13:41:33 -0000 1.47
+++ IntrospectionHelper.java 19 Feb 2003 14:40:36 -0000 1.48
@@ -257,7 +257,7 @@
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 @@
* 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 @@
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))});
}
1.10 +11 -1
ant/src/main/org/apache/tools/ant/filters/ReplaceTokens.java
Index: ReplaceTokens.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/filters/ReplaceTokens.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -w -u -r1.9 -r1.10
--- ReplaceTokens.java 19 Feb 2003 14:11:42 -0000 1.9
+++ ReplaceTokens.java 19 Feb 2003 14:40:37 -0000 1.10
@@ -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.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 @@
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)) {