Search in sources :

Example 71 with Method

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

the class AbstractOverriddenMethod method visitMethod.

/**
 * overrides the visitor to find abstract methods that override concrete ones
 *
 * @param obj
 *            the context object of the currently parsed method
 */
@Override
public void visitMethod(Method obj) {
    if (!obj.isAbstract())
        return;
    String methodName = obj.getName();
    String methodSig = obj.getSignature();
    outer: for (JavaClass cls : superClasses) {
        Method[] methods = cls.getMethods();
        for (Method m : methods) {
            if (m.isPrivate() || m.isAbstract())
                continue;
            if (methodName.equals(m.getName()) && methodSig.equals(m.getSignature())) {
                BugInstance bug = new BugInstance(this, BugType.AOM_ABSTRACT_OVERRIDDEN_METHOD.name(), NORMAL_PRIORITY).addClass(this).addMethod(this);
                Code code = obj.getCode();
                if (code != null)
                    bug.addSourceLineRange(clsContext, this, 0, code.getLength() - 1);
                bugReporter.reportBug(bug);
                break outer;
            }
        }
    }
}
Also used : JavaClass(org.apache.bcel.classfile.JavaClass) BugInstance(edu.umd.cs.findbugs.BugInstance) Method(org.apache.bcel.classfile.Method) Code(org.apache.bcel.classfile.Code)

Example 72 with Method

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

the class AnnotationIssues method visitCode.

@Override
public void visitCode(Code obj) {
    Method method = getMethod();
    String sig = method.getSignature();
    String returnType = sig.substring(sig.indexOf(')') + 1);
    char returnTypeChar = returnType.charAt(0);
    if ((returnTypeChar != 'L') && (returnTypeChar != '[')) {
        return;
    }
    if (method.isSynthetic() && !isCollecting()) {
        return;
    }
    if (Values.SIG_JAVA_LANG_VOID.equals(returnType)) {
        return;
    }
    if (methodHasNullableAnnotation(method)) {
        if (isCollecting()) {
            MethodInfo methodInfo = Statistics.getStatistics().getMethodStatistics(getClassName(), method.getName(), method.getSignature());
            methodInfo.setCanReturnNull(true);
        }
        return;
    }
    MethodInfo methodInfo = Statistics.getStatistics().getMethodStatistics(getClassName(), method.getName(), method.getSignature());
    if (!isCollecting() && methodInfo.getCanReturnNull()) {
        bugReporter.reportBug(new BugInstance(this, BugType.AI_ANNOTATION_ISSUES_NEEDS_NULLABLE.name(), LOW_PRIORITY).addClass(this).addMethod(this));
    } else {
        methodIsNullable = false;
        stack.resetForMethodEntry(this);
        assumedNullTill.clear();
        assumedNonNullTill.clear();
        noAssumptionsPossible.clear();
        super.visitCode(obj);
        if (methodIsNullable) {
            if (isCollecting()) {
                methodInfo.setCanReturnNull(true);
            } else {
                bugReporter.reportBug(new BugInstance(this, BugType.AI_ANNOTATION_ISSUES_NEEDS_NULLABLE.name(), LOW_PRIORITY).addClass(this).addMethod(this));
            }
        }
    }
}
Also used : BugInstance(edu.umd.cs.findbugs.BugInstance) MethodInfo(com.mebigfatguy.fbcontrib.collect.MethodInfo) Method(org.apache.bcel.classfile.Method) XMethod(edu.umd.cs.findbugs.ba.XMethod)

Example 73 with Method

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

the class ArrayIndexOutOfBounds method visitCode.

/**
 * overrides the visitor to collect parameter registers
 *
 * @param obj
 *            the code block of the currently parsed method
 */
@Override
public void visitCode(Code obj) {
    Method m = getMethod();
    stack.resetForMethodEntry(this);
    initializedRegs.clear();
    modifyRegs.clear();
    Type[] argTypes = m.getArgumentTypes();
    int arg = m.isStatic() ? 0 : 1;
    for (Type argType : argTypes) {
        String argSig = argType.getSignature();
        initializedRegs.set(arg);
        arg += SignatureUtils.getSignatureSize(argSig);
    }
    nullStoreToLocation.clear();
    super.visitCode(obj);
    for (Integer pc : nullStoreToLocation.values()) {
        bugReporter.reportBug(new BugInstance(this, BugType.AIOB_ARRAY_STORE_TO_NULL_REFERENCE.name(), HIGH_PRIORITY).addClass(this).addMethod(this).addSourceLine(this, pc.intValue()));
    }
}
Also used : ConstantInteger(org.apache.bcel.classfile.ConstantInteger) BugType(com.mebigfatguy.fbcontrib.utils.BugType) Type(org.apache.bcel.generic.Type) BugInstance(edu.umd.cs.findbugs.BugInstance) Method(org.apache.bcel.classfile.Method)

Example 74 with Method

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

the class BloatedAssignmentScope method visitCode.

/**
 * implements the visitor to reset the register to location map
 *
 * @param obj
 *            the context object of the currently parsed code block
 */
@Override
public void visitCode(Code obj) {
    try {
        ignoreRegs.clear();
        Method method = getMethod();
        if (!method.isStatic()) {
            ignoreRegs.set(0);
        }
        int[] parmRegs = RegisterUtils.getParameterRegisters(method);
        for (int parm : parmRegs) {
            ignoreRegs.set(parm);
        }
        rootScopeBlock = new ScopeBlock(0, obj.getLength());
        tryBlocks.clear();
        catchHandlers.clear();
        CodeException[] exceptions = obj.getExceptionTable();
        if (exceptions != null) {
            for (CodeException ex : exceptions) {
                tryBlocks.set(ex.getStartPC());
                catchHandlers.set(ex.getHandlerPC());
            }
        }
        switchTargets.clear();
        stack.resetForMethodEntry(this);
        dontReport = false;
        sawDup = false;
        sawNull = false;
        super.visitCode(obj);
        if (!dontReport) {
            rootScopeBlock.findBugs(new HashSet<Integer>());
        }
    } finally {
        rootScopeBlock = null;
    }
}
Also used : CodeException(org.apache.bcel.classfile.CodeException) Method(org.apache.bcel.classfile.Method) FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod)

Example 75 with Method

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

the class BloatedSynchronizedBlock method visitCode.

/**
 * implement the visitor to reset the sync count, the stack, and gather some information
 *
 * @param obj
 *            the context object for the currently parsed method
 */
@Override
public void visitCode(Code obj) {
    Method m = getMethod();
    if (prescreen(m)) {
        if (m.isSynchronized()) {
            syncPC = 0;
        } else {
            syncPC = -1;
        }
        isStatic = m.isStatic();
        unsafeAliases.clear();
        unsafeAliases.set(0);
        branchInfo.clear();
        unsafeCallOccurred = false;
        stack.resetForMethodEntry(this);
    }
}
Also used : Method(org.apache.bcel.classfile.Method)

Aggregations

Method (org.apache.bcel.classfile.Method)79 JavaClass (org.apache.bcel.classfile.JavaClass)28 BugInstance (edu.umd.cs.findbugs.BugInstance)20 ToString (com.mebigfatguy.fbcontrib.utils.ToString)12 StopOpcodeParsingException (com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException)11 FQMethod (com.mebigfatguy.fbcontrib.utils.FQMethod)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Field (org.apache.bcel.classfile.Field)6 Type (org.apache.bcel.generic.Type)6 AnnotationEntry (org.apache.bcel.classfile.AnnotationEntry)5 ExceptionTable (org.apache.bcel.classfile.ExceptionTable)5 OpcodeStack (edu.umd.cs.findbugs.OpcodeStack)4 SourceLineAnnotation (edu.umd.cs.findbugs.SourceLineAnnotation)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)4 BugType (com.mebigfatguy.fbcontrib.utils.BugType)3 QMethod (com.mebigfatguy.fbcontrib.utils.QMethod)3 XMethod (edu.umd.cs.findbugs.ba.XMethod)3