Skip to content
Permalink
Browse files

Merge branch 'findbugs' into spotbugs

  • Loading branch information...
mebigfatguy committed Aug 17, 2019
2 parents 981212c + cffce41 commit dbe8ebef5a6d017a2c536659857f8fc713b6253e
@@ -1896,7 +1896,7 @@ System.out.println("Problem with the object :" + someObj);

<BugPattern type="OCP_OVERLY_CONCRETE_PARAMETER">
<ShortDescription>Method needlessly defines parameter with concrete classes</ShortDescription>
<LongDescription>{3}</LongDescription>
<LongDescription>{1}: {3}</LongDescription>
<Details>
<![CDATA[
<p>This method uses concrete classes for parameters when only methods defined in an implemented
@@ -82,6 +82,9 @@
private int parmCount;
private boolean methodSignatureIsConstrained;
private boolean methodIsStatic;
private OpcodeStack.Item ternary1Value;
private OpcodeStack.Item ternary2Value;
private int ternaryTarget;

/**
* constructs a OCP detector given the reporter to report bugs on
@@ -210,6 +213,9 @@ public void visitCode(final Code obj) {
parameterDefiners.clear();
usedParameters.clear();
stack.resetForMethodEntry(this);
ternary1Value = null;
ternary2Value = null;
ternaryTarget = -1;

if (buildParameterDefiners()) {
try {
@@ -235,6 +241,14 @@ public void visitCode(final Code obj) {
public void sawOpcode(final int seen) {

try {
if (ternaryTarget != -1 && getPC() > ternaryTarget) {
ternary1Value = null;
ternary2Value = null;
ternaryTarget = -1;
} else if (getPC() == ternaryTarget && stack.getStackDepth() > 0) {
ternary2Value = stack.getStackItem(0);
}

stack.precomputation(this);

if (OpcodeUtils.isInvoke(seen)) {
@@ -269,13 +283,10 @@ public void sawOpcode(final int seen) {
// Don't check parameters that are aliased
if (stack.getStackDepth() > 0) {
OpcodeStack.Item itm = stack.getStackItem(0);
int reg = itm.getRegisterNumber();
int parm = reg;
if (!methodIsStatic) {
parm--;
}
if ((parm >= 0) && (parm < parmCount)) {
parameterDefiners.remove(Integer.valueOf(reg));
removeParmDefiner(itm);
if (ternaryTarget == getPC()) {
removeParmDefiner(ternary1Value);
removeParmDefiner(ternary2Value);
}
} else {
parameterDefiners.clear();
@@ -284,14 +295,8 @@ public void sawOpcode(final int seen) {
if ((seen == Const.GETFIELD) || (seen == Const.PUTFIELD)) {
if (stack.getStackDepth() > 1) {
OpcodeStack.Item itm = stack.getStackItem(1);
int reg = itm.getRegisterNumber();
int parm = reg;
if (!methodIsStatic) {
parm--;
}
if ((parm >= 0) && (parm < parmCount)) {
parameterDefiners.remove(Integer.valueOf(reg));
}
removeParmDefiner(itm);

} else {
parameterDefiners.clear();
}
@@ -311,32 +316,24 @@ public void sawOpcode(final int seen) {
// Don't check parameters that are stored in
if (stack.getStackDepth() >= 3) {
OpcodeStack.Item itm = stack.getStackItem(0);
int reg = itm.getRegisterNumber();
int parm = reg;
if (!methodIsStatic) {
parm--;
}
if ((parm >= 0) && (parm < parmCount)) {
parameterDefiners.remove(Integer.valueOf(reg));
}
removeParmDefiner(itm);

} else {
parameterDefiners.clear();
}
} else if (seen == Const.ARETURN) {
if (stack.getStackDepth() >= 1) {
OpcodeStack.Item item = stack.getStackItem(0);
int reg = item.getRegisterNumber();
int parm = reg;
if (!methodIsStatic) {
parm--;
}
OpcodeStack.Item itm = stack.getStackItem(0);
removeParmDefiner(itm);

if ((parm >= 0) && (parm < parmCount)) {
parameterDefiners.remove(Integer.valueOf(reg));
}
} else {
parameterDefiners.clear();
}
} else if (((seen == GOTO) || (seen == GOTO_W)) && getBranchOffset() > 0) {
if (stack.getStackDepth() > 0) {
ternary1Value = stack.getStackItem(0);
ternaryTarget = getBranchTarget();
}
}

if (parameterDefiners.isEmpty()) {
@@ -347,6 +344,26 @@ public void sawOpcode(final int seen) {
}
}

/**
* removes a parameter from the definer list, if the item is in fact a parameter
* @param itm the possible parameter
*/
private void removeParmDefiner(OpcodeStack.Item itm) {
if (itm == null) {
return;
}

int reg = itm.getRegisterNumber();
int parm = reg;
if (!methodIsStatic) {
parm--;
}

if ((parm >= 0) && (parm < parmCount)) {
parameterDefiners.remove(Integer.valueOf(reg));
}
}

/**
* determines whether the method is a baked in special method of the jdk
*
@@ -14,6 +14,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -253,3 +254,15 @@ public boolean fpProcessSet(TreeSet<String> s) {
return s.contains("boo");
}
}

class FP367 {
private List<Object> resources;

public void nonTernaryOCP(List<Object> resources) {
this.resources = resources;
}

public void ternaryOCP(List<Object> resources) {
this.resources = (resources == null) ? new ArrayList<>() : resources;
}
}

0 comments on commit dbe8ebe

Please sign in to comment.
You can’t perform that action at this time.