forked from phoedos/pmd
pmd: fix #958 Intermittent NullPointerException while loading XPath node attributes
* synchronizing the method cache * adding additional null check
This commit is contained in:
parent
34b868ad14
commit
62fc70e816
@ -1,5 +1,6 @@
|
||||
????? ??, 2013 - 5.0.3:
|
||||
|
||||
Fixed bug 958: Intermittent NullPointerException while loading XPath node attributes
|
||||
Fixed bug 968: Issues with JUnit4 @Test annotation with expected exception (Thanks to Yiannis Paschalidis)
|
||||
Fixed bug 975: false positive in ClassCastExceptionWithToArray
|
||||
Fixed bug 976: UselessStringValueOf wrong when appending character arrays
|
||||
|
@ -5,6 +5,7 @@ package net.sourceforge.pmd.lang.ast.xpath;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@ -48,7 +49,8 @@ public class AttributeAxisIterator implements Iterator<Attribute> {
|
||||
private int position;
|
||||
private Node node;
|
||||
|
||||
private static Map<Class<?>, MethodWrapper[]> methodCache = new HashMap<Class<?>, MethodWrapper[]>();
|
||||
private static Map<Class<?>, MethodWrapper[]> methodCache =
|
||||
Collections.synchronizedMap(new HashMap<Class<?>, MethodWrapper[]>());
|
||||
|
||||
public AttributeAxisIterator(Node contextNode) {
|
||||
this.node = contextNode;
|
||||
@ -86,7 +88,7 @@ public class AttributeAxisIterator implements Iterator<Attribute> {
|
||||
}
|
||||
|
||||
private Attribute getNextAttribute() {
|
||||
if (position == methodWrappers.length) {
|
||||
if (methodWrappers == null || position == methodWrappers.length) {
|
||||
return null;
|
||||
}
|
||||
MethodWrapper m = methodWrappers[position++];
|
||||
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.ast.xpath;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.DummyJavaNode;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test for {@link AttributeAxisIterator}
|
||||
*/
|
||||
public class AttributeAxisIteratorTest {
|
||||
|
||||
/**
|
||||
* Test hasNext and next.
|
||||
*/
|
||||
@Test
|
||||
public void testAttributeAxisIterator() {
|
||||
DummyJavaNode dummyNode = new DummyJavaNode(1);
|
||||
dummyNode.testingOnly__setBeginLine(1);
|
||||
dummyNode.testingOnly__setBeginColumn(1);
|
||||
|
||||
AttributeAxisIterator it = new AttributeAxisIterator(dummyNode);
|
||||
Map<String, Attribute> atts = new HashMap<String, Attribute>();
|
||||
while (it.hasNext()) {
|
||||
Attribute attribute = it.next();
|
||||
atts.put(attribute.getName(), attribute);
|
||||
}
|
||||
Assert.assertEquals(7, atts.size());
|
||||
Assert.assertTrue(atts.containsKey("BeginColumn"));
|
||||
Assert.assertTrue(atts.containsKey("BeginLine"));
|
||||
Assert.assertTrue(atts.containsKey("FindBoundary"));
|
||||
Assert.assertTrue(atts.containsKey("Image"));
|
||||
Assert.assertTrue(atts.containsKey("SingleLine"));
|
||||
Assert.assertTrue(atts.containsKey("EndColumn"));
|
||||
Assert.assertTrue(atts.containsKey("EndLine"));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user