Package edu.umd.cs.findbugs.ba

Examples of edu.umd.cs.findbugs.ba.XMethod


                funky = true;
            }

        }
        //
        XMethod m = getXMethod();
        String sourceSig = m.getSourceSignature();
        if (sourceSig != null) {
            GenericSignatureParser sig = new GenericSignatureParser(sourceSig);
            String genericReturnValue = sig.getReturnTypeSignature();
            Type t = GenericUtilities.getType(genericReturnValue);
            if (t instanceof GenericObjectType) {
                funky = true;
            }

            //            if (false) {
            //                XClass c = getXClass();
            //                String classSourceSig = c.getSourceSignature();
            //                if (!genericReturnValue.equals(classSourceSig))
            //                    return;
            //            }
        }

        //         System.out.println("Investigating " + getFullyQualifiedMethodName());
        returnSelf = returnOther = updates = returnNew = returnUnknown = 0;

        if (testingEnabled && REPORT_INFERRED_METHODS
                && AnalysisContext.currentAnalysisContext().isApplicationClass(getThisClass())) {
            inferredMethod = new BugInstance("TESTING", NORMAL_PRIORITY).addClassAndMethod(this);
        } else {
            inferredMethod = null;
        }
        super.visit(code); // make callbacks to sawOpcode for all opcodes
        //         System.out.printf("  %3d %3d %3d %3d%n", returnSelf, updates, returnOther, returnNew);

        if (returnSelf > 0 && returnOther == 0) {
            okToIgnore.add(m);
        } else if (funky) {
            okToIgnore.add(m);
        } else if (returnOther > 0 && returnOther >= returnSelf && returnNew > 0 && returnNew >= returnOther - 1) {

            int priority = HIGH_PRIORITY;
            if (returnSelf > 0 || updates > 0) {
                priority++;
            }
            if (returnUnknown > 0) {
                priority++;
            }
            if (returnNew > 0 && priority > NORMAL_PRIORITY) {
                priority = NORMAL_PRIORITY;
            }
            if (updates > 0) {
                priority = LOW_PRIORITY;
            }
            if (priority <= HIGH_PRIORITY) {
                doNotIgnoreHigh.add(m);
            }
            if (priority <= NORMAL_PRIORITY) {
                // System.out.printf("  adding %d %s%n", priority,
                // MethodAnnotation.fromVisitedMethod(this).getSourceLines());
                doNotIgnore.add(m);
                if (!m.isStatic()) {
                    XFactory xFactory = AnalysisContext.currentXFactory();
                    xFactory.addFunctionThatMightBeMistakenForProcedures(getMethodDescriptor());
                    if (inferredMethod != null) {
                        inferredMethod.setPriority(priority);
                        inferredMethod.addString(String.format("%3d %3d %5d %3d", returnOther, returnSelf, returnNew, updates));
View Full Code Here


            if (rv.isInitialParameter()) {
                returnSelf++;
                break;
            }

            XMethod xMethod = rv.getReturnValueOf();
            if (xMethod == null) {
                returnSelf++;
                break;
            }
            if (inferredMethod != null) {
                inferredMethod.addCalledMethod(xMethod);
            }
            if (okToIgnore.contains(xMethod) ) {
                returnSelf++;
                break;
            }
            if (xMethod.getName().equals("<init>")) {
                String sig = xMethod.getSignature();
                // returning a newly constructed value
                boolean voidConstructor;
                if (!isInnerClass) {
                    voidConstructor = sig.equals("()V");
                } else {
                    SignatureParser parser = new SignatureParser(sig);
                    voidConstructor = parser.getNumParameters()  <= 1;
                }
                if (voidConstructor) {
                    returnSelf++;
                } else {
                    returnOther++;
                    returnNew++;
                }
                break;

            }


            if (xMethod.isAbstract() && !xMethod.getClassDescriptor().equals(getClassDescriptor())) {
                returnUnknown++;
                break;
            }
            if (xMethod.getName().equals("<init>") || doNotIgnoreHigh.contains(xMethod)) {
                returnOther++;
                // System.out.println("  calls " + xMethod);
                // System.out.println("  at " +
                // MethodAnnotation.fromXMethod(xMethod).getSourceLines());
                if (xMethod.getName().equals("<init>") || doNotIgnore.contains(xMethod)) {
                    returnNew++;
                }
            } else if (doNotIgnore.contains(xMethod)) {
                returnOther++;
                // System.out.println("  calls " + xMethod);
View Full Code Here

    public void visitAfter(Code code) {
        bugAccumulator.reportAccumulatedBugs();
    }

    private boolean badUseOfCompareResult(Item left, Item right) {
        XMethod m = left.getReturnValueOf();

        if (m == null) {
            return false;
        }
        String name = m.getName();

        if (!name.startsWith("compare")) {
            return false;
        }

        Object value = right.getConstant();
        if (!(value instanceof Integer) || ((Integer) value).intValue() == 0) {
            return false;
        }
        if (!m.isPublic() && m.isResolved()) {
            return false;
        }


        if (m.isStatic() || !m.isResolved()) {
            if (name.equals("compare") && m.getClassName().startsWith("com.google.common.primitives.")) {
                return true;
            }
        }
        if (!m.isStatic() || !m.isResolved()) {
            if (name.equals("compareTo") && m.getSignature().equals("(Ljava/lang/Object;)I")) {
                return true;
            }
            if (name.equals("compare") && m.getSignature().equals("(Ljava/lang/Object;Ljava/lang/Object;)I")) {
                return true;
            }
        }

        return false;
View Full Code Here

        case Constants.IF_ICMPNE:
            OpcodeStack.Item left = stack.getStackItem(1);
            OpcodeStack.Item right = stack.getStackItem(0);
            if (badUseOfCompareResult(left, right)) {
                XMethod returnValueOf = left.getReturnValueOf();
                assert returnValueOf != null;
                bugAccumulator.accumulateBug(new BugInstance(this, "RV_CHECK_COMPARETO_FOR_SPECIFIC_RETURN_VALUE", NORMAL_PRIORITY)
                .addClassAndMethod(this).addMethod(returnValueOf).describe(MethodAnnotation.METHOD_CALLED).addValueSource(right, this), this);
            } else if (badUseOfCompareResult(right, left)) {
                XMethod returnValueOf = right.getReturnValueOf();
                assert returnValueOf != null;
                bugAccumulator.accumulateBug(new BugInstance(this, "RV_CHECK_COMPARETO_FOR_SPECIFIC_RETURN_VALUE", NORMAL_PRIORITY)
                .addClassAndMethod(this).addMethod(returnValueOf).describe(MethodAnnotation.METHOD_CALLED).addValueSource(left, this), this);
            }
            break;
View Full Code Here

                    if (sourceSignature != null) {
                        System.out.println("  source signature: " + sourceSignature);
                    }
                }
                boolean foundSomething = false;
                XMethod m2 = m.bridgeTo();
                if (m2 != null) {
                    m = m2;
                }
                if (sourceSignature != null && !sourceSignature.equals(m.getSignature())) {
                    GenericSignatureParser p = new GenericSignatureParser(sourceSignature);
View Full Code Here

    public void visitClassContext(ClassContext classContext) {

        JavaClass jclass = classContext.getJavaClass();

        for (Method method : jclass.getMethods()) {
            XMethod xmethod = XFactory.createXMethod(classContext.getJavaClass(), method);
            ParameterProperty nonnullParameters = AnalysisContext.currentAnalysisContext().getUnconditionalDerefParamDatabase()
                    .getProperty(xmethod.getMethodDescriptor());
            if (nonnullParameters != null) {
                for (int p : nonnullParameters.iterable()) {
                    TypeQualifierAnnotation directTypeQualifierAnnotation = TypeQualifierApplications
                            .getDirectTypeQualifierAnnotation(xmethod, p, nonnullTypeQualifierValue);
                    if (directTypeQualifierAnnotation != null && directTypeQualifierAnnotation.when == When.UNKNOWN) {
                        //
                        // The LocalVariableAnnotation is constructed using the
                        // local variable
                        // number of the parameter, not the parameter number.
                        //
                        int paramLocal = xmethod.isStatic() ? p : p + 1;

                        reporter.reportBug(new BugInstance(this, "NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE",
                                NORMAL_PRIORITY).addClassAndMethod(jclass, method).add(
                                        LocalVariableAnnotation.getParameterLocalVariableAnnotation(method, paramLocal)));
View Full Code Here

            return;
        }
        if (!getClassName().equals(getClassConstantOperand())) {
            return;
        }
        XMethod invokedMethod = XFactory.createXMethod(getDottedClassConstantOperand(), getNameConstantOperand(),
                getSigConstantOperand(), false);
        if (invokedMethod.isResolved() && invokedMethod.getClassName().equals(getDottedClassConstantOperand())
                || invokedMethod.isSynthetic()) {
            return;
        }
        // method is inherited
        String possibleTargetClass = getDottedClassName();
        String superClassName = getDottedSuperclassName();
        while (true) {
            int i = possibleTargetClass.lastIndexOf('$');
            if (i <= 0) {
                break;
            }
            possibleTargetClass = possibleTargetClass.substring(0, i);
            if (possibleTargetClass.equals(superClassName)) {
                break;
            }
            XMethod alternativeMethod = XFactory.createXMethod(possibleTargetClass, getNameConstantOperand(),
                    getSigConstantOperand(), false);
            if (alternativeMethod.isResolved() && alternativeMethod.getClassName().equals(possibleTargetClass)) {
                String targetPackage = invokedMethod.getPackageName();
                String alternativePackage = alternativeMethod.getPackageName();
                int priority = HIGH_PRIORITY;
                if (targetPackage.equals(alternativePackage)) {
                    priority++;
                }
                if (targetPackage.startsWith("javax.swing") || targetPackage.startsWith("java.awt")) {
View Full Code Here

        if (!checkedDatabases) {
            checkDatabases();
            checkedDatabases = true;
        }

        XMethod xMethod = XFactory.createXMethod(classContext.getJavaClass(), method);

        ClassDescriptor junitTestAnnotation = DescriptorFactory.createClassDescriptor("org/junit/Test");
        AnnotationValue av = xMethod.getAnnotation(junitTestAnnotation);
        if (av != null) {
            Object value = av.getValue("expected");

            if (value instanceof Type) {
                String className = ((Type) value).getClassName();
View Full Code Here

            if (DEBUG_NULLRETURN) {
                System.out.println("Checking return annotation for "
                        + SignatureConverter.convertMethodSignature(classContext.getJavaClass(), method));
            }

            XMethod m = XFactory.createXMethod(classContext.getJavaClass(), method);
            return AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase().getResolvedAnnotation(m, false);
        }
        return NullnessAnnotation.UNKNOWN_NULLNESS;
    }
View Full Code Here

        }
        if (DEBUG_NULLARG) {
            System.out.println("Null arguments passed: " + nullArgSet);
            System.out.println("Frame is: " + frame);
            System.out.println("# arguments: " + frame.getNumArguments(invokeInstruction, cpg));
            XMethod xm = XFactory.createXMethod(invokeInstruction, cpg);
            System.out.print("Signature: " + xm.getSignature());
        }

        if (unconditionalDerefParamDatabase != null) {
            checkUnconditionallyDereferencedParam(location, cpg, typeDataflow, invokeInstruction, nullArgSet,
                    definitelyNullArgSet);
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ba.XMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.