Skip to content

Commit

Permalink
Merge branch 'findbugs' into spotbugs
Browse files Browse the repository at this point in the history
 Conflicts:
	src/main/java/com/mebigfatguy/fbcontrib/detect/OverlyPermissiveMethod.java
  • Loading branch information
mebigfatguy committed Mar 10, 2020
2 parents 12b0fcc + bf1e3d5 commit 28c23d6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public void sawOpcode(int seen) {
break;

case Const.INVOKEDYNAMIC:
// older than dirt
ConstantInvokeDynamic id = (ConstantInvokeDynamic) getConstantRefOperand();

BootstrapMethod bm = getBootstrapMethod(id.getBootstrapMethodAttrIndex());
Expand Down Expand Up @@ -212,24 +213,38 @@ private boolean hasRuntimeAnnotations(Method obj) {
}

private boolean isAssumedPublic(String methodName) {
return (cls.isEnum() && "valueOf".equals(methodName));
return cls.isEnum() && "valueOf".equals(methodName);
}

private boolean isGetterSetter(String methodName, String methodSignature) {
if (methodName.startsWith("get") || methodName.startsWith("set")) {
int numParameters = SignatureUtils.getNumParameters(methodSignature);
boolean voidReturn = Values.SIG_VOID.equals(SignatureUtils.getReturnSignature(methodSignature));

if ((numParameters == 0) && !voidReturn && (methodName.charAt(0) == 'g')) {
if (methodName.length() <= 3 || Character.isLowerCase(methodName.charAt(3))) {
return false;
}

if (numParameters == 0 && !voidReturn && methodName.charAt(0) == 'g') {
return true;
}

if ((numParameters == 1) && voidReturn && (methodName.charAt(0) == 's')) {
if (numParameters == 1 && voidReturn && methodName.charAt(0) == 's') {
return true;
}
}
} else if (methodName.startsWith("is")) {
if (methodName.length() <= 2 || Character.isLowerCase(methodName.charAt(2))) {
return false;
}
int numParameters = SignatureUtils.getNumParameters(methodSignature);

if (numParameters == 0) {
String returnSig = SignatureUtils.getReturnSignature(methodSignature);
return Values.SIG_PRIMITIVE_BOOLEAN.equals(returnSig) || Values.SIG_JAVA_UTIL_BOOLEAN.equals(returnSig);
}
}
return false;

}

/**
Expand Down Expand Up @@ -337,7 +352,7 @@ private boolean isConstrainedByInterface(FQMethod fqMethod) {
String infParmType = infTypes.get(i);
String fqParmType = fqTypes.get(i);
if (infParmType.equals(fqParmType)) {
if ((infParmType.charAt(0) != 'L') || (fqParmType.charAt(0) != 'L')) {
if (infParmType.charAt(0) != 'L' || fqParmType.charAt(0) != 'L') {
matches = false;
break;
}
Expand Down Expand Up @@ -394,7 +409,7 @@ private boolean isDerived(JavaClass fqCls, FQMethod key) {
}

JavaClass superClass = fqCls.getSuperClass();
if ((superClass == null) || Values.DOTTED_JAVA_LANG_OBJECT.equals(superClass.getClassName())) {
if (superClass == null || Values.DOTTED_JAVA_LANG_OBJECT.equals(superClass.getClassName())) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/mebigfatguy/fbcontrib/utils/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public final class Values {
@SlashedClassName
public static final String SLASHED_JAVA_UTIL_UUID = "java/util/UUID";

public static final String SIG_JAVA_UTIL_BOOLEAN = "Ljava/lang/Boolean;";
public static final String SIG_JAVA_UTIL_STRINGBUFFER = "Ljava/lang/StringBuffer;";
public static final String SIG_JAVA_UTIL_STRINGBUILDER = "Ljava/lang/StringBuilder;";

Expand Down
4 changes: 4 additions & 0 deletions src/samples/java/ex/OPM_Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public void someNormalMethod() {
List<String> l = getFoo(new ArrayList<String>());
}

public Boolean isFoo390() {
return true;
}

@Override
public List<String> getFoo(List<String> l) {
return l;
Expand Down

0 comments on commit 28c23d6

Please sign in to comment.