diff --git a/src/main/java/com/mebigfatguy/fbcontrib/detect/OverlyPermissiveMethod.java b/src/main/java/com/mebigfatguy/fbcontrib/detect/OverlyPermissiveMethod.java index 73a293f06..a4534d254 100644 --- a/src/main/java/com/mebigfatguy/fbcontrib/detect/OverlyPermissiveMethod.java +++ b/src/main/java/com/mebigfatguy/fbcontrib/detect/OverlyPermissiveMethod.java @@ -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()); @@ -212,7 +213,7 @@ 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) { @@ -220,16 +221,30 @@ private boolean isGetterSetter(String methodName, String methodSignature) { 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; + } /** @@ -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; } @@ -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; } diff --git a/src/main/java/com/mebigfatguy/fbcontrib/utils/Values.java b/src/main/java/com/mebigfatguy/fbcontrib/utils/Values.java index c67d92f2f..2949f88d2 100644 --- a/src/main/java/com/mebigfatguy/fbcontrib/utils/Values.java +++ b/src/main/java/com/mebigfatguy/fbcontrib/utils/Values.java @@ -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;"; diff --git a/src/samples/java/ex/OPM_Sample.java b/src/samples/java/ex/OPM_Sample.java index 9705f3db9..6668767cf 100644 --- a/src/samples/java/ex/OPM_Sample.java +++ b/src/samples/java/ex/OPM_Sample.java @@ -35,6 +35,10 @@ public void someNormalMethod() { List l = getFoo(new ArrayList()); } + public Boolean isFoo390() { + return true; + } + @Override public List getFoo(List l) { return l;