forked from phoedos/pmd
Merge branch 'bug-1476' into pmd/5.3.x
This commit is contained in:
@ -117,8 +117,17 @@ public abstract class AbstractSunSecureRule extends AbstractJavaRule {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the image of the first ASTName node found by
|
||||
* Gets the image of the ASTName node found by
|
||||
* {@link Node#getFirstDescendantOfType(Class)}
|
||||
* if it is the greatgrandchild of the given node.
|
||||
*
|
||||
* E.g.
|
||||
* <pre>
|
||||
* n = Expression || StatementExpression
|
||||
* PrimaryExpression
|
||||
* PrimaryPrefix
|
||||
* Name
|
||||
* </pre>
|
||||
*
|
||||
* @param n
|
||||
* the node to search
|
||||
@ -126,7 +135,7 @@ public abstract class AbstractSunSecureRule extends AbstractJavaRule {
|
||||
*/
|
||||
protected String getFirstNameImage(Node n) {
|
||||
ASTName name = n.getFirstDescendantOfType(ASTName.class);
|
||||
if (name != null) {
|
||||
if (name != null && name.getNthParent(3) == n) {
|
||||
return name.getImage();
|
||||
}
|
||||
return null;
|
||||
|
@ -98,12 +98,12 @@ public class ArrayIsStoredDirectlyRule extends AbstractSunSecureRule {
|
||||
if (se == null || !(se.jjtGetChild(0) instanceof ASTPrimaryExpression)) {
|
||||
continue;
|
||||
}
|
||||
ASTPrimaryExpression pe = (ASTPrimaryExpression) se.jjtGetChild(0);
|
||||
String assignedVar = getExpressionVarName(pe);
|
||||
String assignedVar = getExpressionVarName(se);
|
||||
if (assignedVar == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ASTPrimaryExpression pe = (ASTPrimaryExpression) se.jjtGetChild(0);
|
||||
Node n = pe.getFirstParentOfType(ASTMethodDeclaration.class);
|
||||
if (n == null) {
|
||||
n = pe.getFirstParentOfType(ASTConstructorDeclaration.class);
|
||||
|
@ -150,6 +150,31 @@ public class TestClass {
|
||||
this.obj = Arrays.copyOf(obj, obj.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1476 False positive of ArrayIsStoredDirectly</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class NotificationPacket {
|
||||
public NotificationPacket(byte id, byte[] rawTypeData)
|
||||
{
|
||||
super(id);
|
||||
if (rawTypeData == null)
|
||||
{
|
||||
throw new IllegalArgumentException("No type data is specified");
|
||||
}
|
||||
if (rawTypeData.length == 0)
|
||||
{
|
||||
this.message = EMPTY_MESSAGE;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.message = new String(rawTypeData, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -46,6 +46,8 @@
|
||||
* [#1453](https://sourceforge.net/p/pmd/bugs/1453/): Test Class Without Test Cases gives false positive
|
||||
* java-optimizations/UseStringBufferForStringAppends:
|
||||
* [#1340](https://sourceforge.net/p/pmd/bugs/1340/): UseStringBufferForStringAppends False Positive with ternary operator
|
||||
* java-sunsecure/ArrayIsStoredDirectly:
|
||||
* [#1476](https://sourceforge.net/p/pmd/bugs/1476/): False positive of ArrayIsStoredDirectly
|
||||
* java-unnecessary/UnnecessaryFinalModifier:
|
||||
* [#1464](https://sourceforge.net/p/pmd/bugs/1464/): UnnecessaryFinalModifier false positive on a @SafeVarargs method
|
||||
* java-unusedcode/UnusedFormalParameter:
|
||||
|
Reference in New Issue
Block a user