WW-4360 Fixes potential NullPointerExceptions

This commit is contained in:
Lukasz Lenart
2014-07-28 21:35:17 +02:00
parent 2dd9cb555a
commit 413d67bd28
6 changed files with 36 additions and 16 deletions
@@ -37,11 +37,13 @@ import com.opensymphony.xwork2.util.location.Location;
import com.opensymphony.xwork2.util.location.LocationUtils;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
@@ -426,7 +428,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
} else {
if (!verifyAction(className, name, location)) {
if (LOG.isErrorEnabled())
LOG.error("Unable to verify action [#0] with class [#1], from [#2]", name, className, location.toString());
LOG.error("Unable to verify action [#0] with class [#1], from [#2]", name, className, location);
return;
}
}
@@ -95,6 +95,8 @@ public class NumberConverter extends DefaultTypeConverter {
bigValue = new BigInteger(stringValue);
lowerBound = BigInteger.valueOf(Long.MIN_VALUE);
upperBound = BigInteger.valueOf(Long.MAX_VALUE);
} else {
throw new IllegalArgumentException("Unexpected numeric type: " + toType.getName());
}
} catch (NumberFormatException e) {
//shoult it fail here? BigInteger doesnt seem to be so nice parsing numbers as NumberFormat
@@ -80,7 +80,10 @@ public class NamedVariablePatternMatcher implements PatternMatcher<NamedVariable
char c = data.charAt(x);
switch (c) {
case '{' : varName = new StringBuilder(); break;
case '}' : varNames.add(varName.toString());
case '}' : if (varName == null) {
throw new IllegalArgumentException("Mismatched braces in pattern");
}
varNames.add(varName.toString());
regex.append("([^/]+)");
varName = null;
break;
@@ -1000,9 +1000,8 @@ public class ResourceFinder {
private Properties loadProperties(URL resource) throws IOException {
InputStream in = resource.openStream();
BufferedInputStream reader = null;
BufferedInputStream reader = new BufferedInputStream(in);
try {
reader = new BufferedInputStream(in);
Properties properties = new Properties();
properties.load(reader);
@@ -1018,12 +1017,10 @@ public class ResourceFinder {
private String readContents(URL resource) throws IOException {
InputStream in = resource.openStream();
BufferedInputStream reader = null;
StringBuilder sb = new StringBuilder();
BufferedInputStream reader = new BufferedInputStream(in);
try {
reader = new BufferedInputStream(in);
int b = reader.read();
while (b != -1) {
sb.append((char) b);
@@ -263,14 +263,14 @@ public class LocationUtils {
newFinders.remove(ref);
finders = newFinders;
}
}
Location result = finder.getLocation(obj, description);
if (result != null) {
return result;
} else {
Location result = finder.getLocation(obj, description);
if (result != null) {
return result;
}
}
}
if (obj instanceof Throwable) {
Throwable t = (Throwable) obj;
StackTraceElement[] stack = t.getStackTrace();
@@ -15,16 +15,23 @@
*/
package com.opensymphony.xwork2.util;
import com.opensymphony.xwork2.util.NamedVariablePatternMatcher.CompiledPattern;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
public class NamedVariablePatternMatcherTest extends TestCase {
import org.junit.Test;
import com.opensymphony.xwork2.util.NamedVariablePatternMatcher.CompiledPattern;
public class NamedVariablePatternMatcherTest {
@Test
public void testCompile() {
NamedVariablePatternMatcher matcher = new NamedVariablePatternMatcher();
@@ -46,6 +53,14 @@ public class NamedVariablePatternMatcherTest extends TestCase {
assertFalse(pattern.getPattern().matcher("foo/star/jie").matches());
}
@Test(expected = IllegalArgumentException.class)
public void testCompileWithMismatchedBracketsParses() {
NamedVariablePatternMatcher matcher = new NamedVariablePatternMatcher();
matcher.compilePattern("}");
}
@Test
public void testMatch() {
NamedVariablePatternMatcher matcher = new NamedVariablePatternMatcher();
@@ -56,6 +71,7 @@ public class NamedVariablePatternMatcherTest extends TestCase {
assertEquals("baz", vars.get("bar"));
}
@Test
public void testIsLiteral() {
NamedVariablePatternMatcher matcher = new NamedVariablePatternMatcher();