Package edu.umd.cs.findbugs.ba

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


    public static final Pattern mapSignaturePattern = Pattern.compile("<(\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*):L[^;]*;(\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*):L[^;]*;>.*Ljava/util/(\\p{javaJavaIdentifierStart}(\\p{javaJavaIdentifierPart}|/)*)?Map<T\\1;T\\2;>;.*");
    public static boolean isStraightGenericMap(ClassDescriptor c) {
        if (c.matches(Map.class)) {
            return true;
        }
        XClass xc;
        try {
            xc = c.getXClass();
        } catch (CheckedAnalysisException e) {
            return false;
        }
        String sourceSignature = xc.getSourceSignature();
        if (sourceSignature == null) {
            return false;
        }
        if (sourceSignature.startsWith("<")) {
            Matcher matcher = mapSignaturePattern.matcher(sourceSignature);
View Full Code Here


        if (seen == PUTFIELD) {
            OpcodeStack.Item obj = stack.getStackItem(1);
            OpcodeStack.Item value = stack.getStackItem(0);
            XField f = getXFieldOperand();
            XClass x = getXClassOperand();

            checkPUTFIELD: if (putFieldPC + 10 > getPC() && f != null && obj != null && f.equals(putFieldXField)
                    && !f.isSynthetic() && obj.equals(putFieldObj) && x != null) {

                LineNumberTable table = getCode().getLineNumberTable();
                if (table != null) {
                    int first = table.getSourceLine(putFieldPC);
                    int second = table.getSourceLine(getPC());
                    if (first + 1 != second && first != second) {
                        break checkPUTFIELD;
                    }
                } else if (putFieldPC + 3 != getPC()) {
                    break checkPUTFIELD;
                }

                int priority = NORMAL_PRIORITY;
                if (value.equals(putFieldValue) && putFieldPC + 3 != getPC()) {
                    priority++;
                }
                boolean storeOfDefaultValue = putFieldValue.isNull() || putFieldValue.hasConstantValue(0);
                if (storeOfDefaultValue) {
                    priority++;
                }
                if (f.isVolatile()) {
                    priority++;
                }
                XField intendedTarget = null;

                double minimumDistance = 2;
                int matches = 0;
                for (XField f2 : x.getXFields()) {
                    if (!f.equals(f2) && !f2.isStatic() && !f2.isFinal() && !f2.isSynthetic()
                            && f2.getSignature().equals(f.getSignature())) {

                        double distance = EditDistance.editDistanceRatio(f.getName(), f2.getName());
                        matches++;
View Full Code Here

        }
        case INVOKEVIRTUAL:
        case INVOKEINTERFACE: {
            if (getDottedClassConstantOperand().equals("java.util.concurrent.ConcurrentHashMap")) {
                String methodName = getNameConstantOperand();
                XClass xClass = getXClassOperand();
                if (xClass != null && methodName.equals("put")) {
                    if ((getPC() < lastQuestionableCheckTarget) && (lastQuestionableCheckTarget != -1)) {
                        bugReporter.reportBug(new BugInstance(this, "AT_OPERATION_SEQUENCE_ON_CONCURRENT_ABSTRACTION", priority)
                        .addClassAndMethod(this).addType(xClass.getClassDescriptor()).addCalledMethod(this)
                        .addSourceLine(this));
                    }
                }
            }
            break;
View Full Code Here

    public static SourceLineAnnotation forFirstLineOfMethod(MethodDescriptor methodDescriptor) {
        SourceLineAnnotation result = null;

        try {
            Method m = Global.getAnalysisCache().getMethodAnalysis(Method.class, methodDescriptor);
            XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, methodDescriptor.getClassDescriptor());
            LineNumberTable lnt = m.getLineNumberTable();
            String sourceFile = xclass.getSource();
            if (sourceFile != null && lnt != null) {
                int firstLine = Integer.MAX_VALUE;
                int bytecode = 0;
                LineNumber[] entries = lnt.getLineNumberTable();
                for (LineNumber entry : entries) {
View Full Code Here

        this.bugReporter = bugReporter;
    }

    @Override
    public boolean shouldVisit(JavaClass obj) {
        XClass xClass = getXClass();
        return xClass.getCalledClassDescriptors().contains(ObjectOutputStream)
                || xClass.getCalledClassDescriptors().contains(ObjectInputStream);
    }
View Full Code Here

            if (c == null || !Subtypes2.instanceOf(c, Serializable.class)) {
                return;
            }

            try {
                XClass xClass = Global.getAnalysisCache().getClassAnalysis(XClass.class, c);
                if (xClass.isInterface()) {
                    return;
                }
                if (xClass.isSynthetic()) {
                    return;
                }
                if (xClass.isAbstract()) {
                    return;
                }
                unreadFields.strongEvidenceForIntendedSerialization(c);
            } catch (CheckedAnalysisException e) {
                bugReporter.logError("Error looking up xClass of " + c, e);
            }

        }
        if (seen == CHECKCAST) {
            OpcodeStack.Item top = stack.getStackItem(0);
            if (readObject.equals(top.getReturnValueOf())) {
                ClassDescriptor c = getClassDescriptorOperand();
                if (!Subtypes2.instanceOf(c, Serializable.class)) {
                    return;
                }

                try {
                    XClass xClass = Global.getAnalysisCache().getClassAnalysis(XClass.class, c);
                    if (xClass.isInterface()) {
                        return;
                    }
                    if (xClass.isSynthetic()) {
                        return;
                    }
                    if (xClass.isAbstract()) {
                        return;
                    }
                    unreadFields.strongEvidenceForIntendedSerialization(c);
                } catch (CheckedAnalysisException e) {
                    bugReporter.logError("Error looking up xClass of " + c, e);
View Full Code Here

            try {
                // True if variable is itself declared as a Map
                if ("java.util.Map".equals(d.getDottedClassName())) {
                    return true;
                }
                XClass classNameAndInfo = Global.getAnalysisCache().getClassAnalysis(XClass.class, d);
                ClassDescriptor is[] = classNameAndInfo.getInterfaceDescriptorList();
                d = classNameAndInfo.getSuperclassDescriptor();
                for (ClassDescriptor i : is) {
                    if ("java.util.Map".equals(i.getDottedClassName())) {
                        return true;
                    }
                }
View Full Code Here

        boolean inheritedEqualsIsFinal = false;
        boolean inheritedEqualsIsAbstract = false;
        boolean inheritedEqualsFromAbstractClass = false;
        XMethod inheritedEquals = null;
        if (!hasEqualsObject) {
            XClass we = Lookup.findImplementor(getXClass(), "equals", "(Ljava/lang/Object;)Z", false, bugReporter);
            if (we == null || we.equals(getXClass())) {
                whereEqual = "java.lang.Object";
            } else {
                inheritedEqualsFromAbstractClass = we.isAbstract();
                whereEqual = we.getClassDescriptor().getDottedClassName();
                inheritedEquals = we.findMethod("equals", "(Ljava/lang/Object;)Z", false);
                if (inheritedEquals != null) {
                    inheritedEqualsIsFinal = inheritedEquals.isFinal();
                    inheritedEqualsIsAbstract = inheritedEquals.isAbstract();
                }
            }
        }
        boolean usesDefaultEquals = whereEqual.equals("java.lang.Object");
        String whereHashCode = getDottedClassName();
        if (!hasHashCode) {
            XClass wh = Lookup.findSuperImplementor(getXClass(), "hashCode", "()I", false, bugReporter);
            if (wh == null) {
                whereHashCode = "java.lang.Object";
            } else {
                whereHashCode = wh.getClassDescriptor().getDottedClassName();
                XMethod m = wh.findMethod("hashCode", "()I", false);
                if (m != null && m.isFinal()) {
                    inheritedHashCodeIsFinal = true;
                }
            }
        }
View Full Code Here

        case INVOKESPECIAL:
        case INVOKESTATIC:
            String className = getClassConstantOperand();
            if (!className.startsWith("[")) {
                try {
                    XClass c = Global.getAnalysisCache().getClassAnalysis(XClass.class,
                            DescriptorFactory.createClassDescriptor(className));
                    XMethod m = Hierarchy2.findInvocationLeastUpperBound(c, getNameConstantOperand(), getSigConstantOperand(),
                            seen == INVOKESTATIC, seen == INVOKEINTERFACE);
                    if (m == null) {
                        break;
View Full Code Here

            potentiallyDeadStores.set(register);
        }


        if (seen == INVOKEVIRTUAL && getNameConstantOperand().equals("ordinal") && getSigConstantOperand().equals("()I")) {
            XClass c = getXClassOperand();
            if (c != null) {
                ClassDescriptor superclassDescriptor = c.getSuperclassDescriptor();
                if (superclassDescriptor != null && superclassDescriptor.getClassName().equals("java/lang/Enum")) {
                    enumType = c;
                }
                if (DEBUG) {
                    System.out.println("Saw " + enumType + ".ordinal()");
View Full Code Here

TOP

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

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.