You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2017/01/26 02:49:58 UTC
svn commit: r1780316 - in
/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity:
runtime/directive/RuntimeMacro.java util/ExtProperties.java
util/introspection/IntrospectorBase.java
util/introspection/IntrospectorCache.java
Author: cbrisson
Date: Thu Jan 26 02:49:58 2017
New Revision: 1780316
URL: http://svn.apache.org/viewvc?rev=1780316&view=rev
Log:
[engine] use commons.lang3.Validate whenever appropriate
Modified:
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorBase.java
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorCache.java
Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java?rev=1780316&r1=1780315&r2=1780316&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java Thu Jan 26 02:49:58 2017
@@ -36,6 +36,8 @@ import org.apache.velocity.runtime.parse
import org.apache.velocity.runtime.parser.node.ParserTreeConstants;
import org.apache.velocity.util.StringUtils;
+import org.apache.commons.lang3.Validate;
+
import java.io.IOException;
import java.io.Writer;
import java.util.List;
@@ -124,13 +126,8 @@ public class RuntimeMacro extends Direct
{
super.init(rs, context, node);
- macroName = name;
- if (macroName == null)
- {
- throw new IllegalArgumentException("Null arguments");
- }
-
- this.macroName = rsvc.useStringInterning() ? macroName.intern() : macroName;
+ macroName = Validate.notNull(name);
+ macroName = rsvc.useStringInterning() ? macroName.intern() : macroName;
this.node = node;
/**
Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java?rev=1780316&r1=1780315&r2=1780316&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java Thu Jan 26 02:49:58 2017
@@ -1002,7 +1002,7 @@ public class ExtProperties extends Hasht
String pvalue = token.substring(equalSign + 1).trim();
props.put(pkey, pvalue);
} else {
- throw new IllegalArgumentException('\'' + token + "' does not contain " + "an equals sign");
+ throw new IllegalArgumentException('\'' + token + "' does not contain an equals sign");
}
}
return props;
Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorBase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorBase.java?rev=1780316&r1=1780315&r2=1780316&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorBase.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorBase.java Thu Jan 26 02:49:58 2017
@@ -19,6 +19,7 @@ package org.apache.velocity.util.introsp
* under the License.
*/
+import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import java.lang.reflect.Field;
@@ -84,31 +85,21 @@ public abstract class IntrospectorBase
* the parameters
*
* @return The desired Method object.
- * @throws IllegalArgumentException When the parameters passed in can not be used for introspection.
+ * @throws NullPointerException When the parameters passed in can not be used for introspection because null.
* @throws MethodMap.AmbiguousException When the method map contains more than one match for the requested signature.
*/
public Method getMethod(final Class c, final String name, final Object[] params)
- throws IllegalArgumentException,MethodMap.AmbiguousException
+ throws MethodMap.AmbiguousException
{
- if (c == null)
- {
- throw new IllegalArgumentException ("class object is null!");
- }
-
- if (params == null)
- {
- throw new IllegalArgumentException("params object is null!");
- }
-
IntrospectorCache ic = getIntrospectorCache();
- ClassMap classMap = ic.get(c);
+ ClassMap classMap = ic.get(Validate.notNull(c, "class object is null!"));
if (classMap == null)
{
classMap = ic.put(c);
}
- return classMap.findMethod(name, params);
+ return classMap.findMethod(name, Validate.notNull(params, "params object is null!"));
}
/**
@@ -123,14 +114,9 @@ public abstract class IntrospectorBase
public Field getField(final Class c, final String name)
throws IllegalArgumentException
{
- if (c == null)
- {
- throw new IllegalArgumentException("class object is null!");
- }
-
IntrospectorCache ic = getIntrospectorCache();
- ClassFieldMap classFieldMap = ic.getFieldMap(c);
+ ClassFieldMap classFieldMap = ic.getFieldMap(Validate.notNull(c, "class object is null!"));
if (classFieldMap == null)
{
ic.put(c);
Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorCache.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorCache.java?rev=1780316&r1=1780315&r2=1780316&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorCache.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorCache.java Thu Jan 26 02:49:58 2017
@@ -19,6 +19,8 @@ package org.apache.velocity.util.introsp
* under the License.
*/
+import org.apache.commons.lang3.Validate;
+
import org.slf4j.Logger;
import java.util.HashMap;
@@ -101,12 +103,7 @@ public final class IntrospectorCache
*/
public ClassMap get(final Class c)
{
- if (c == null)
- {
- throw new IllegalArgumentException("class is null!");
- }
-
- ClassMap classMap = (ClassMap)classMapCache.get(c);
+ ClassMap classMap = (ClassMap)classMapCache.get(Validate.notNull(c));
if (classMap == null)
{
/*
@@ -136,12 +133,7 @@ public final class IntrospectorCache
*/
public ClassFieldMap getFieldMap(final Class c)
{
- if (c == null)
- {
- throw new IllegalArgumentException("class is null!");
- }
-
- ClassFieldMap classFieldMap = (ClassFieldMap)classFieldMapCache.get(c);
+ ClassFieldMap classFieldMap = (ClassFieldMap)classFieldMapCache.get(Validate.notNull(c));
if (classFieldMap == null)
{
/*