Search in sources :

Example 21 with JavaClass

use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.

the class Section508Compliance method processSetSizeOps.

/**
 * looks for calls to setSize on components, rather than letting the layout manager set them
 *
 * @param methodName
 *            the method that was called on a component
 *
 * @throws ClassNotFoundException
 *             if the gui class wasn't found
 */
private void processSetSizeOps(String methodName) throws ClassNotFoundException {
    if ("setSize".equals(methodName)) {
        int argCount = SignatureUtils.getNumParameters(getSigConstantOperand());
        if ((windowClass != null) && (stack.getStackDepth() > argCount)) {
            OpcodeStack.Item item = stack.getStackItem(argCount);
            JavaClass cls = item.getJavaClass();
            if ((cls != null) && cls.instanceOf(windowClass)) {
                bugReporter.reportBug(new BugInstance(this, BugType.S508C_NO_SETSIZE.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
            }
        }
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) JavaClass(org.apache.bcel.classfile.JavaClass) BugInstance(edu.umd.cs.findbugs.BugInstance)

Example 22 with JavaClass

use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.

the class SluggishGui method visitCode.

/**
 * overrides the visitor to segregate method into two, those that implement listeners, and those that don't. The ones that don't are processed first.
 *
 * @param obj
 *            the context object of the currently parsed code block
 */
@Override
public void visitCode(Code obj) {
    try {
        for (JavaClass inf : guiInterfaces) {
            Method[] methods = inf.getMethods();
            for (Method m : methods) {
                if (m.getName().equals(methodName) && m.getSignature().equals(methodSig)) {
                    listenerCode.put(obj, this.getMethod());
                    return;
                }
            }
        }
        isListenerMethod = false;
        super.visitCode(obj);
    } catch (StopOpcodeParsingException e) {
    // method already reported
    }
}
Also used : JavaClass(org.apache.bcel.classfile.JavaClass) StopOpcodeParsingException(com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException) Method(org.apache.bcel.classfile.Method)

Example 23 with JavaClass

use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.

the class SpoiledChildInterfaceImplementor method filterSuperInterfaceMethods.

/**
 * removes methods found in an interface when a super interface having the same methods is implemented in a parent. While this is somewhat hinky, we'll
 * allow it.
 *
 * @param inf
 *            the interface to look for super interfaces for
 * @param infMethods
 *            the remaining methods that are needed to be found
 * @param cls
 *            the super class to look for these methods in
 */
private void filterSuperInterfaceMethods(JavaClass inf, Set<QMethod> infMethods, JavaClass cls) {
    try {
        if (infMethods.isEmpty()) {
            return;
        }
        JavaClass[] superInfs = inf.getInterfaces();
        for (JavaClass superInf : superInfs) {
            if (cls.implementationOf(superInf)) {
                Set<QMethod> superInfMethods = buildMethodSet(superInf);
                infMethods.removeAll(superInfMethods);
                if (infMethods.isEmpty()) {
                    return;
                }
            }
            filterSuperInterfaceMethods(superInf, infMethods, cls);
        }
    } catch (ClassNotFoundException cnfe) {
        bugReporter.reportMissingClass(cnfe);
        infMethods.clear();
    }
}
Also used : QMethod(com.mebigfatguy.fbcontrib.utils.QMethod) JavaClass(org.apache.bcel.classfile.JavaClass)

Example 24 with JavaClass

use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.

the class SpoiledChildInterfaceImplementor method visitClassContext.

/**
 * looks for classes that implement interfaces but don't provide those methods
 *
 * @param classContext
 *            the context object of the currently parsed class
 */
@Override
public void visitClassContext(ClassContext classContext) {
    try {
        JavaClass cls = classContext.getJavaClass();
        if (cls.isAbstract() || cls.isInterface()) {
            return;
        }
        if (Values.DOTTED_JAVA_LANG_OBJECT.equals(cls.getSuperclassName())) {
            return;
        }
        JavaClass[] infs = cls.getInterfaces();
        if (infs.length > 0) {
            Set<QMethod> clsMethods = buildMethodSet(cls);
            for (JavaClass inf : infs) {
                Set<QMethod> infMethods = buildMethodSet(inf);
                if (!infMethods.isEmpty()) {
                    infMethods.removeAll(clsMethods);
                    if (!infMethods.isEmpty()) {
                        JavaClass superCls = cls.getSuperClass();
                        filterSuperInterfaceMethods(inf, infMethods, superCls);
                        if (!infMethods.isEmpty() && !superCls.implementationOf(inf)) {
                            int priority = AnalysisContext.currentAnalysisContext().isApplicationClass(superCls) ? NORMAL_PRIORITY : LOW_PRIORITY;
                            BugInstance bi = new BugInstance(this, BugType.SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTOR.name(), priority).addClass(cls).addString("Implementing interface: " + inf.getClassName()).addString("Methods:");
                            for (QMethod methodInfo : infMethods) {
                                bi.addString('\t' + methodInfo.toString());
                            }
                            bugReporter.reportBug(bi);
                            return;
                        }
                    }
                }
            }
        }
    } catch (ClassNotFoundException cnfe) {
        bugReporter.reportMissingClass(cnfe);
    }
}
Also used : QMethod(com.mebigfatguy.fbcontrib.utils.QMethod) JavaClass(org.apache.bcel.classfile.JavaClass) BugInstance(edu.umd.cs.findbugs.BugInstance)

Example 25 with JavaClass

use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.

the class SpuriousThreadStates method sawOpcode.

@Override
public void sawOpcode(int seen) {
    OpcodeStack.Item itm = null;
    try {
        stack.precomputation(this);
        if (seen == INVOKEVIRTUAL) {
            String className = getClassConstantOperand();
            if (Values.SLASHED_JAVA_LANG_OBJECT.equals(className)) {
                if (stack.getStackDepth() > 0) {
                    String methodName = getNameConstantOperand();
                    String signature = getSigConstantOperand();
                    if (("wait".equals(methodName) || "notify".equals(methodName) || "notifyAll".equals(methodName)) && SignatureBuilder.SIG_VOID_TO_VOID.equals(signature)) {
                        itm = stack.getStackItem(0);
                    } else if ("wait".equals(methodName)) {
                        if (SignatureBuilder.SIG_LONG_TO_VOID.equals(signature) && (stack.getStackDepth() > 1)) {
                            itm = stack.getStackItem(1);
                        } else if (SignatureBuilder.SIG_LONG_AND_INT_TO_VOID.equals(signature) && (stack.getStackDepth() > 2)) {
                            itm = stack.getStackItem(2);
                        }
                    }
                }
                if (itm != null) {
                    JavaClass cls = itm.getJavaClass();
                    boolean found = false;
                    if (cls != null) {
                        if ("java.lang.Thread".equals(cls.getClassName())) {
                            found = true;
                        } else {
                            JavaClass[] supers = cls.getSuperClasses();
                            for (JavaClass jc : supers) {
                                if ("java.lang.Thread".equals(jc.getClassName())) {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (found) {
                        bugReporter.reportBug(new BugInstance(this, "STS_SPURIOUS_THREAD_STATES", NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
                    }
                }
            }
        }
    } catch (ClassNotFoundException cnfe) {
        bugReporter.reportMissingClass(cnfe);
    } finally {
        stack.sawOpcode(this, seen);
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) JavaClass(org.apache.bcel.classfile.JavaClass) BugInstance(edu.umd.cs.findbugs.BugInstance)

Aggregations

JavaClass (org.apache.bcel.classfile.JavaClass)144 OpcodeStack (edu.umd.cs.findbugs.OpcodeStack)45 BugInstance (edu.umd.cs.findbugs.BugInstance)43 Method (org.apache.bcel.classfile.Method)28 ToString (com.mebigfatguy.fbcontrib.utils.ToString)27 Field (org.apache.bcel.classfile.Field)17 HashSet (java.util.HashSet)14 HashMap (java.util.HashMap)11 ClassParser (org.apache.bcel.classfile.ClassParser)10 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)8 ExceptionTable (org.apache.bcel.classfile.ExceptionTable)8 XField (edu.umd.cs.findbugs.ba.XField)7 Nullable (javax.annotation.Nullable)7 AnnotationEntry (org.apache.bcel.classfile.AnnotationEntry)7 Type (org.apache.bcel.generic.Type)7 Iterator (java.util.Iterator)6 List (java.util.List)6 Map (java.util.Map)6 Set (java.util.Set)6