Package edu.umd.cs.findbugs.ba

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


        }

    }

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

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

        if (m.getName().equals("compareTo") && m.getSignature().equals("(Ljava/lang/Object;)I")) {
            return true;
        }
        if (m.getName().equals("compare") && m.getSignature().equals("(Ljava/lang/Object;Ljava/lang/Object;)I")) {
            return true;
        }

        return false;
View Full Code Here


                && stack.getStackDepth() == stackDepth) {

            String cl = getClassConstantOperand();
            String nm = getNameConstantOperand();
            String sig = getSigConstantOperand();
            XMethod m = getXMethodOperand();
            if ((m == null || m.isVarArgs())
                    && sig.indexOf("Ljava/lang/String;[Ljava/lang/Object;)") >= 0
                    && ("java/util/Formatter".equals(cl) && "format".equals(nm) || "java/lang/String".equals(cl)
                            && "format".equals(nm) || "java/io/PrintStream".equals(cl) && "format".equals(nm)
                            || "java/io/PrintStream".equals(cl) && "printf".equals(nm) || cl.endsWith("Writer")
                            && "format".equals(nm) || cl.endsWith("Writer") && "printf".equals(nm)) || cl.endsWith("Logger")
View Full Code Here

        if (seen == INVOKEVIRTUAL && getClassConstantOperand().equals("java/lang/Class")
                && getNameConstantOperand().equals("getName") && getSigConstantOperand().equals("()Ljava/lang/String;")
                && stack.getStackDepth() >= 2) {
            Item left = stack.getStackItem(1);
            XMethod leftM = left.getReturnValueOf();
            Item right = stack.getStackItem(0);
            XMethod rightM = right.getReturnValueOf();
            if (leftM != null && rightM != null && leftM.getName().equals("getName") && rightM.getName().equals("getClass")) {
                dangerDanger = true;
            }

        }
        if (seen == INVOKESPECIAL && getNameConstantOperand().equals(EQUALS_NAME)
View Full Code Here

     *
     */
    private void checkForComparingClasses() {
        if (stack.getStackDepth() >= 2) {
            Item left = stack.getStackItem(1);
            XMethod leftM = left.getReturnValueOf();
            Item right = stack.getStackItem(0);
            XMethod rightM = right.getReturnValueOf();
            if (left.getSignature().equals("Ljava/lang/Class;") && right.getSignature().equals("Ljava/lang/Class;")) {
                boolean leftMatch = leftM != null && leftM.getName().equals("getClass");
                boolean rightMatch = rightM != null && rightM.getName().equals("getClass");
                if (leftMatch && rightMatch) {
                    sawGoodEqualsClass = true;
                } else {
                    if (getClassName().equals(left.getConstant()) && rightMatch || leftMatch
                            && getClassName().equals(right.getConstant())) {
                        if (getThisClass().isFinal()) {
                            sawGoodEqualsClass = true;
                        } else {
                            sawBadEqualsClass = true;
                            if (AnalysisContext.currentAnalysisContext().isApplicationClass(getThisClass())) {

                                int priority = Priorities.NORMAL_PRIORITY;

                                BugInstance bug = new BugInstance(this, "EQ_GETCLASS_AND_CLASS_CONSTANT", priority)
                                .addClassAndMethod(this);

                                try {

                                    Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2();
                                    Set<ClassDescriptor> subtypes = subtypes2.getDirectSubtypes(getClassDescriptor());
                                    for (ClassDescriptor c : subtypes) {
                                        try {
                                            Global.getAnalysisCache().getClassAnalysis(XClass.class, c);
                                        } catch (CheckedAnalysisException e) {
                                            continue;
                                        }
                                        XMethod m = Hierarchy2.findMethod(c, "equals", "(Ljava/lang/Object;)Z", false);
                                        if (m == null) {
                                            bug.addClass(c).describe(ClassAnnotation.SUBCLASS_ROLE);
                                            priority--;
                                            bug.setPriority(priority);
                                        }
View Full Code Here

                        && Repository.instanceOf(m.getClassName(), m2.getClassName())) {
                    WarningPropertySet<NamingProperty> propertySet = new WarningPropertySet<NamingProperty>();

                    int priority = HIGH_PRIORITY;
                    boolean intentional = false;
                    XMethod m3 = null;
                    try {
                        JavaClass clazz = Repository.lookupClass(m.getClassName());
                        if ((m3 = definedIn(clazz, m2)) != null) {
                            // the method we don't override is also defined in
                            // our class
View Full Code Here

        if (m.getName().startsWith("<init>") || m.getName().startsWith("<clinit>")) {
            return false;
        }
        for (XMethod m2 : others) {
            if (confusingMethodNamesWrongCapitalization(m, m2)) {
                XMethod mm1;
                XMethod mm2;
                if (m.compareTo(m2) < 0) {
                    mm1 = m;
                    mm2 = m2;
                } else {
                    mm1 = m2;
                    mm2 = m;
                }
                bugReporter.reportBug(new BugInstance(this, "NM_CONFUSING", LOW_PRIORITY).addClass(mm1.getClassName())
                        .addMethod(mm1).addClass(mm2.getClassName()).addMethod(mm2));
                return true;
            }
        }
        return false;
    }
View Full Code Here

        }

        String sig2 = removePackageNamesFromSignature(sig);
        String allSmall = mName.toLowerCase() + sig2;

        XMethod xm = getXMethod();
        {
            TreeSet<XMethod> s = canonicalToXMethod.get(allSmall);
            if (s == null) {
                s = new TreeSet<XMethod>();
                canonicalToXMethod.put(allSmall, s);
View Full Code Here

            return;
        }

        if (seen == INVOKESPECIAL && getNameConstantOperand().equals("<init>") &&  getClassConstantOperand().equals(getClassName())) {

            XMethod m = getXMethodOperand();
            Set<XField> read = staticFieldsRead.get(m);
            if (constructorsInvokedInStaticInitializer.add(m) && read != null && !read.isEmpty()) {
                lastInvocation = new InvocationInfo(m, getPC());
                invocationInfo.add(lastInvocation);
View Full Code Here

     * @return this object
     */
    @Nonnull
    public BugInstance addClassAndMethod(PreorderVisitor visitor) {
        addClass(visitor);
        XMethod m = visitor.getXMethod();
        addMethod(visitor);
        if (m.isSynthetic()) {
            foundInSyntheticMethod();
        }
        return this;
    }
View Full Code Here

            FieldAnnotation a = FieldAnnotation.fromXField(xField);
            a.setDescription(FieldAnnotation.LOADED_FROM_ROLE);
            return a;
        }

        XMethod xMethod = item.getReturnValueOf();
        if (xMethod != null) {
            MethodAnnotation a = MethodAnnotation.fromXMethod(xMethod);
            a.setDescription(MethodAnnotation.METHOD_RETURN_VALUE_OF);
            return a;
        }
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.