Search in sources :

Example 16 with FQMethod

use of com.mebigfatguy.fbcontrib.utils.FQMethod in project fb-contrib by mebigfatguy.

the class MoreDumbMethods method getFQMethod.

private FQMethod getFQMethod() {
    final String className = getClassConstantOperand();
    final String methodName = getNameConstantOperand();
    final String methodSig = getSigConstantOperand();
    return new FQMethod(className, methodName, methodSig);
}
Also used : FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod) ToString(com.mebigfatguy.fbcontrib.utils.ToString)

Example 17 with FQMethod

use of com.mebigfatguy.fbcontrib.utils.FQMethod in project fb-contrib by mebigfatguy.

the class MoreDumbMethods method visitClassContext.

@Override
public void visitClassContext(ClassContext classContext) {
    if (classContext.getJavaClass().getMajor() <= MAJOR_1_5) {
        dumbMethods.put(new FQMethod("java/security/SecureRandom", Values.CONSTRUCTOR, SignatureBuilder.SIG_VOID_TO_VOID), new ReportInfo("MDM_SECURERANDOM", LOW_PRIORITY));
        dumbMethods.put(new FQMethod("java/security/SecureRandom", Values.CONSTRUCTOR, byteArrayToVoid), new ReportInfo("MDM_SECURERANDOM", LOW_PRIORITY));
        dumbMethods.put(new FQMethod("java/security/SecureRandom", "getSeed", intToByteArray), new ReportInfo("MDM_SECURERANDOM", LOW_PRIORITY));
    } else {
        dumbMethods.remove(new FQMethod("java/security/SecureRandom", Values.CONSTRUCTOR, SignatureBuilder.SIG_VOID_TO_VOID));
        dumbMethods.remove(new FQMethod("java/security/SecureRandom", Values.CONSTRUCTOR, byteArrayToVoid));
        dumbMethods.remove(new FQMethod("java/security/SecureRandom", "getSeed", intToByteArray));
    }
    super.visitClassContext(classContext);
}
Also used : FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod)

Example 18 with FQMethod

use of com.mebigfatguy.fbcontrib.utils.FQMethod in project fb-contrib by mebigfatguy.

the class NonCollectionMethodUse method sawOpcode.

/**
 * implements the visitor to look for method calls that are one of the old pre-collections1.2 set of methods
 *
 * @param seen
 *            the currently parsed opcode
 */
@Override
public void sawOpcode(int seen) {
    if (seen == INVOKEVIRTUAL) {
        String className = getClassConstantOperand();
        String methodName = getNameConstantOperand();
        String methodSig = getSigConstantOperand();
        FQMethod methodInfo = new FQMethod(className, methodName, methodSig);
        if (oldMethods.contains(methodInfo)) {
            bugReporter.reportBug(new BugInstance(this, BugType.NCMU_NON_COLLECTION_METHOD_USE.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
        }
    }
}
Also used : FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod) BugInstance(edu.umd.cs.findbugs.BugInstance)

Example 19 with FQMethod

use of com.mebigfatguy.fbcontrib.utils.FQMethod in project fb-contrib by mebigfatguy.

the class Section508Compliance method processFaultyGuiStrings.

/**
 * looks for calls to set a readable string that is generated from a static constant, as these strings are not translatable. also looks for setting readable
 * strings that are appended together. This is likely not to be internationalizable.
 */
private void processFaultyGuiStrings() {
    FQMethod methodInfo = new FQMethod(getClassConstantOperand(), getNameConstantOperand(), getSigConstantOperand());
    Integer parmIndex = displayTextMethods.get(methodInfo);
    if ((parmIndex != null) && (stack.getStackDepth() > parmIndex.intValue())) {
        OpcodeStack.Item item = stack.getStackItem(parmIndex.intValue());
        if (item.getConstant() != null) {
            bugReporter.reportBug(new BugInstance(this, BugType.S508C_NON_TRANSLATABLE_STRING.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
        } else if (S508UserValue.APPENDED_STRING == item.getUserValue()) {
            bugReporter.reportBug(new BugInstance(this, BugType.S508C_APPENDED_STRING.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
        }
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod) BugInstance(edu.umd.cs.findbugs.BugInstance)

Example 20 with FQMethod

use of com.mebigfatguy.fbcontrib.utils.FQMethod in project fb-contrib by mebigfatguy.

the class OverlyPermissiveMethod method isConstrainedByInterface.

/**
 * looks to see if this method is an implementation of a method in an interface, including generic specified interface methods.
 *
 * @param fqMethod
 *            the method to check
 * @return if this method is constrained by an interface method
 */
private boolean isConstrainedByInterface(FQMethod fqMethod) {
    try {
        JavaClass fqCls = Repository.lookupClass(fqMethod.getClassName());
        if (fqCls.isInterface()) {
            return true;
        }
        for (JavaClass inf : fqCls.getAllInterfaces()) {
            for (Method infMethod : inf.getMethods()) {
                if (infMethod.getName().equals(fqMethod.getMethodName())) {
                    String infMethodSig = infMethod.getSignature();
                    String fqMethodSig = fqMethod.getSignature();
                    if (infMethodSig.equals(fqMethodSig)) {
                        return true;
                    }
                    List<String> infTypes = SignatureUtils.getParameterSignatures(infMethodSig);
                    List<String> fqTypes = SignatureUtils.getParameterSignatures(fqMethodSig);
                    if (infTypes.size() == fqTypes.size()) {
                        boolean matches = true;
                        for (int i = 0; i < infTypes.size(); i++) {
                            String infParmType = infTypes.get(i);
                            String fqParmType = fqTypes.get(i);
                            if (infParmType.equals(fqParmType)) {
                                if ((infParmType.charAt(0) != 'L') || (fqParmType.charAt(0) != 'L')) {
                                    matches = false;
                                    break;
                                }
                                JavaClass infParmClass = Repository.lookupClass(SignatureUtils.stripSignature(infParmType));
                                JavaClass fqParmClass = Repository.lookupClass(SignatureUtils.stripSignature(fqParmType));
                                if (!fqParmClass.instanceOf(infParmClass)) {
                                    matches = false;
                                    break;
                                }
                            }
                        }
                        if (matches) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    } catch (ClassNotFoundException cnfe) {
        bugReporter.reportMissingClass(cnfe);
        return true;
    }
}
Also used : JavaClass(org.apache.bcel.classfile.JavaClass) Method(org.apache.bcel.classfile.Method) BootstrapMethod(org.apache.bcel.classfile.BootstrapMethod) FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod)

Aggregations

FQMethod (com.mebigfatguy.fbcontrib.utils.FQMethod)25 OpcodeStack (edu.umd.cs.findbugs.OpcodeStack)15 BugInstance (edu.umd.cs.findbugs.BugInstance)13 XMethod (edu.umd.cs.findbugs.ba.XMethod)7 ToString (com.mebigfatguy.fbcontrib.utils.ToString)6 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Method (org.apache.bcel.classfile.Method)3 MethodInfo (com.mebigfatguy.fbcontrib.collect.MethodInfo)2 QMethod (com.mebigfatguy.fbcontrib.utils.QMethod)2 JavaClass (org.apache.bcel.classfile.JavaClass)2 Statistics (com.mebigfatguy.fbcontrib.collect.Statistics)1 XField (edu.umd.cs.findbugs.ba.XField)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Nullable (javax.annotation.Nullable)1 AnnotationEntry (org.apache.bcel.classfile.AnnotationEntry)1 BootstrapMethod (org.apache.bcel.classfile.BootstrapMethod)1