You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2005/09/26 14:20:42 UTC
svn commit: r291608 -
/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/util/parser/BaseValueParser.java
Author: henning
Date: Mon Sep 26 05:20:40 2005
New Revision: 291608
URL: http://svn.apache.org/viewcvs?rev=291608&view=rev
Log:
Letting NPE's happening and then catching them wasn't exactly the
smartest idea because this is the path that is needed when supplying
parameters with default values. So one would end up with lots of
[WARN] messages in the log file for default parameters that were
confusing (and plain wrong). Thanks to Scott Eade for pointing out.
Fixed the code to check whether a string is empty and only calling the
conversion methods when it is not. Else just return null everywhere.
Modified:
jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/util/parser/BaseValueParser.java
Modified: jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/util/parser/BaseValueParser.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/util/parser/BaseValueParser.java?rev=291608&r1=291607&r2=291608&view=diff
==============================================================================
--- jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/util/parser/BaseValueParser.java (original)
+++ jakarta/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/util/parser/BaseValueParser.java Mon Sep 26 05:20:40 2005
@@ -412,6 +412,7 @@
{
Boolean result = null;
String value = getString(name);
+
if (StringUtils.isNotEmpty(value))
{
if (value.equals("1") ||
@@ -496,19 +497,17 @@
double result = defaultValue;
String value = getString(name);
- try
- {
- result = Double.parseDouble(StringUtils.trim(value));
- }
- catch (NumberFormatException e)
- {
- logConvertionFailure(name, value, "Double");
- }
- catch (NullPointerException e)
+ if (StringUtils.isNotEmpty(value))
{
- logConvertionFailure(name, value, "Double");
+ try
+ {
+ result = Double.parseDouble(StringUtils.trim(value));
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value, "Double");
+ }
}
-
return result;
}
@@ -540,17 +539,16 @@
result = new double[value.length];
for (int i = 0; i < value.length; i++)
{
- try
+ if (StringUtils.isNotEmpty(value[i]))
{
- result[i] = Double.parseDouble(value[i]);
- }
- catch (NumberFormatException e)
- {
- logConvertionFailure(name, value[i], "Double");
- }
- catch (NullPointerException e)
- {
- logConvertionFailure(name, value[i], "Double");
+ try
+ {
+ result[i] = Double.parseDouble(value[i]);
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value[i], "Double");
+ }
}
}
}
@@ -583,17 +581,16 @@
Double result = null;
String value = getString(name);
- try
- {
- result = new Double(StringUtils.trim(value));
- }
- catch(NumberFormatException e)
- {
- logConvertionFailure(name, value, "Double");
- }
- catch(NullPointerException e)
+ if (StringUtils.isNotEmpty(value))
{
- logConvertionFailure(name, value, "Double");
+ try
+ {
+ result = new Double(StringUtils.trim(value));
+ }
+ catch(NumberFormatException e)
+ {
+ logConvertionFailure(name, value, "Double");
+ }
}
return result;
}
@@ -614,17 +611,16 @@
result = new Double[value.length];
for (int i = 0; i < value.length; i++)
{
- try
- {
- result[i] = Double.valueOf(value[i]);
- }
- catch (NumberFormatException e)
+ if (StringUtils.isNotEmpty(value[i]))
{
- logConvertionFailure(name, value[i], "Double");
- }
- catch (NullPointerException e)
- {
- logConvertionFailure(name, value[i], "Double");
+ try
+ {
+ result[i] = Double.valueOf(value[i]);
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value[i], "Double");
+ }
}
}
}
@@ -644,19 +640,17 @@
float result = defaultValue;
String value = getString(name);
- try
- {
- result = Float.parseFloat(StringUtils.trim(value));
- }
- catch (NumberFormatException e)
- {
- logConvertionFailure(name, value, "Float");
- }
- catch (NullPointerException e)
+ if (StringUtils.isNotEmpty(value))
{
- logConvertionFailure(name, value, "Float");
+ try
+ {
+ result = Float.parseFloat(StringUtils.trim(value));
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value, "Float");
+ }
}
-
return result;
}
@@ -688,17 +682,16 @@
result = new float[value.length];
for (int i = 0; i < value.length; i++)
{
- try
- {
- result[i] = Float.parseFloat(value[i]);
- }
- catch (NumberFormatException e)
+ if (StringUtils.isNotEmpty(value[i]))
{
- logConvertionFailure(name, value[i], "Float");
- }
- catch (NullPointerException e)
- {
- logConvertionFailure(name, value[i], "Float");
+ try
+ {
+ result[i] = Float.parseFloat(value[i]);
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value[i], "Float");
+ }
}
}
}
@@ -731,17 +724,16 @@
Float result = null;
String value = getString(name);
- try
- {
- result = new Float(StringUtils.trim(value));
- }
- catch(NumberFormatException e)
- {
- logConvertionFailure(name, value, "Float");
- }
- catch(NullPointerException e)
+ if (StringUtils.isNotEmpty(value))
{
- logConvertionFailure(name, value, "Float");
+ try
+ {
+ result = new Float(StringUtils.trim(value));
+ }
+ catch(NumberFormatException e)
+ {
+ logConvertionFailure(name, value, "Float");
+ }
}
return result;
@@ -763,17 +755,16 @@
result = new Float[value.length];
for (int i = 0; i < value.length; i++)
{
- try
- {
- result[i] = Float.valueOf(value[i]);
- }
- catch (NumberFormatException e)
- {
- logConvertionFailure(name, value[i], "Float");
- }
- catch (NullPointerException e)
+ if (StringUtils.isNotEmpty(value[i]))
{
- logConvertionFailure(name, value[i], "Float");
+ try
+ {
+ result[i] = Float.valueOf(value[i]);
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value[i], "Float");
+ }
}
}
}
@@ -793,17 +784,16 @@
BigDecimal result = defaultValue;
String value = getString(name);
- try
- {
- result = new BigDecimal(StringUtils.trim(value));
- }
- catch (NumberFormatException e)
- {
- logConvertionFailure(name, value, "BigDecimal");
- }
- catch (NullPointerException e)
+ if (StringUtils.isNotEmpty(value))
{
- logConvertionFailure(name, value, "BigDecimal");
+ try
+ {
+ result = new BigDecimal(StringUtils.trim(value));
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value, "BigDecimal");
+ }
}
return result;
@@ -837,17 +827,16 @@
result = new BigDecimal[value.length];
for (int i = 0; i < value.length; i++)
{
- try
- {
- result[i] = new BigDecimal(value[i]);
- }
- catch (NumberFormatException e)
- {
- logConvertionFailure(name, value[i], "BigDecimal");
- }
- catch (NullPointerException e)
+ if (StringUtils.isNotEmpty(value[i]))
{
- logConvertionFailure(name, value[i], "BigDecimal");
+ try
+ {
+ result[i] = new BigDecimal(value[i]);
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value[i], "BigDecimal");
+ }
}
}
}
@@ -867,17 +856,16 @@
int result = defaultValue;
String value = getString(name);
- try
- {
- result = Integer.parseInt(StringUtils.trim(value));
- }
- catch (NumberFormatException e)
- {
- logConvertionFailure(name, value, "Integer");
- }
- catch (NullPointerException e)
+ if (StringUtils.isNotEmpty(value))
{
- logConvertionFailure(name, value, "Integer");
+ try
+ {
+ result = Integer.parseInt(StringUtils.trim(value));
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value, "Integer");
+ }
}
return result;
@@ -953,17 +941,16 @@
result = new int[value.length];
for (int i = 0; i < value.length; i++)
{
- try
- {
- result[i] = Integer.parseInt(value[i]);
- }
- catch (NumberFormatException e)
- {
- logConvertionFailure(name, value[i], "Integer");
- }
- catch (NullPointerException e)
+ if (StringUtils.isNotEmpty(value[i]))
{
- logConvertionFailure(name, value[i], "Integer");
+ try
+ {
+ result[i] = Integer.parseInt(value[i]);
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value[i], "Integer");
+ }
}
}
}
@@ -996,17 +983,16 @@
Integer result = null;
String value = getString(name);
- try
- {
- result = new Integer(StringUtils.trim(value));
- }
- catch(NumberFormatException e)
- {
- logConvertionFailure(name, value, "Integer");
- }
- catch(NullPointerException e)
+ if (StringUtils.isNotEmpty(value))
{
- logConvertionFailure(name, value, "Integer");
+ try
+ {
+ result = new Integer(StringUtils.trim(value));
+ }
+ catch(NumberFormatException e)
+ {
+ logConvertionFailure(name, value, "Integer");
+ }
}
return result;
@@ -1028,17 +1014,16 @@
result = new Integer[value.length];
for (int i = 0; i < value.length; i++)
{
- try
- {
- result[i] = Integer.valueOf(value[i]);
- }
- catch (NumberFormatException e)
+ if (StringUtils.isNotEmpty(value[i]))
{
- logConvertionFailure(name, value[i], "Integer");
- }
- catch (NullPointerException e)
- {
- logConvertionFailure(name, value[i], "Integer");
+ try
+ {
+ result[i] = Integer.valueOf(value[i]);
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value[i], "Integer");
+ }
}
}
}
@@ -1071,17 +1056,16 @@
long result = defaultValue;
String value = getString(name);
- try
- {
- result = Long.parseLong(StringUtils.trim(value));
- }
- catch (NumberFormatException e)
- {
- logConvertionFailure(name, value, "Long");
- }
- catch (NullPointerException e)
+ if (StringUtils.isNotEmpty(value))
{
- logConvertionFailure(name, value, "Long");
+ try
+ {
+ result = Long.parseLong(StringUtils.trim(value));
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value, "Long");
+ }
}
return result;
@@ -1115,17 +1099,16 @@
result = new long[value.length];
for (int i = 0; i < value.length; i++)
{
- try
+ if (StringUtils.isNotEmpty(value[i]))
{
- result[i] = Long.parseLong(value[i]);
- }
- catch (NumberFormatException e)
- {
- logConvertionFailure(name, value[i], "Long");
- }
- catch (NullPointerException e)
- {
- logConvertionFailure(name, value[i], "Long");
+ try
+ {
+ result[i] = Long.parseLong(value[i]);
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value[i], "Long");
+ }
}
}
}
@@ -1148,17 +1131,16 @@
result = new Long[value.length];
for (int i = 0; i < value.length; i++)
{
- try
- {
- result[i] = Long.valueOf(value[i]);
- }
- catch (NumberFormatException e)
+ if (StringUtils.isNotEmpty(value[i]))
{
- logConvertionFailure(name, value[i], "Long");
- }
- catch (NullPointerException e)
- {
- logConvertionFailure(name, value[i], "Long");
+ try
+ {
+ result[i] = Long.valueOf(value[i]);
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value[i], "Long");
+ }
}
}
}
@@ -1177,17 +1159,16 @@
Long result = null;
String value = getString(name);
- try
- {
- result = new Long(StringUtils.trim(value));
- }
- catch(NumberFormatException e)
- {
- logConvertionFailure(name, value, "Long");
- }
- catch(NullPointerException e)
+ if (StringUtils.isNotEmpty(value))
{
- logConvertionFailure(name, value, "Long");
+ try
+ {
+ result = new Long(StringUtils.trim(value));
+ }
+ catch(NumberFormatException e)
+ {
+ logConvertionFailure(name, value, "Long");
+ }
}
return result;
@@ -1220,17 +1201,16 @@
byte result = defaultValue;
String value = getString(name);
- try
- {
- result = Byte.parseByte(StringUtils.trim(value));
- }
- catch (NumberFormatException e)
- {
- logConvertionFailure(name, value, "Byte");
- }
- catch (NullPointerException e)
+ if (StringUtils.isNotEmpty(value))
{
- logConvertionFailure(name, value, "Byte");
+ try
+ {
+ result = Byte.parseByte(StringUtils.trim(value));
+ }
+ catch (NumberFormatException e)
+ {
+ logConvertionFailure(name, value, "Byte");
+ }
}
return result;
@@ -1295,17 +1275,16 @@
Byte result = null;
String value = getString(name);
- try
- {
- result = new Byte(StringUtils.trim(value));
- }
- catch(NumberFormatException e)
- {
- logConvertionFailure(name, value, "Byte");
- }
- catch(NullPointerException e)
+ if (StringUtils.isNotEmpty(value))
{
- logConvertionFailure(name, value, "Byte");
+ try
+ {
+ result = new Byte(StringUtils.trim(value));
+ }
+ catch(NumberFormatException e)
+ {
+ logConvertionFailure(name, value, "Byte");
+ }
}
return result;
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org