Package edu.umd.cs.findbugs.ba.vna

Examples of edu.umd.cs.findbugs.ba.vna.ValueNumber


                if (!vnFrame.isValid()) {
                    AnalysisContext.logError("Invalid value number frame in " + xmethod);
                    continue;
                }

                ValueNumber objectVN = vnFrame.getStackValue(lhsPos);
                ValueNumber argVN = vnFrame.getStackValue(stackPos);

                if (objectVN.equals(argVN)) {
                    String bugPattern = "DMI_COLLECTIONS_SHOULD_NOT_CONTAIN_THEMSELVES";
                    int priority = HIGH_PRIORITY;
                    if (invokedMethodName.equals("removeAll")) {
                        bugPattern = "DMI_USING_REMOVEALL_TO_CLEAR_COLLECTION";
                        priority = NORMAL_PRIORITY;
                    } else if (invokedMethodName.endsWith("All")) {
                        bugPattern = "DMI_VACUOUS_SELF_COLLECTION_CALL";
                        priority = NORMAL_PRIORITY;
                    }
                    if (invokedMethodName.startsWith("contains")) {
                        InstructionHandle next = handle.getNext();
                        if (next != null) {
                            Instruction nextIns = next.getInstruction();

                            if (nextIns instanceof InvokeInstruction) {
                                XMethod nextMethod = XFactory.createXMethod((InvokeInstruction) nextIns, cpg);
                                if (nextMethod.getName().equals("assertFalse")) {
                                    continue;
                                }
                            }
                        }
                    }
                    accumulator.accumulateBug(
                            new BugInstance(this, bugPattern, priority)
                            .addClassAndMethod(methodGen, sourceFile)
                            .addCalledMethod(methodGen, (InvokeInstruction) ins)
                            .addOptionalAnnotation(
                                    ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location, objectVN,
                                            vnFrame, "INVOKED_ON")), SourceLineAnnotation.fromVisitedInstruction(
                                                    classContext, methodGen, sourceFile, handle));
                }

                // Only consider generic...
                Type objectType = frame.getStackValue(lhsPos);
                if (!(objectType instanceof GenericObjectType)) {
                    continue;
                }

                GenericObjectType operand = (GenericObjectType) objectType;

                int expectedTypeParameters = 1;
                String simpleName = info.interfaceForCall.getSimpleName();
                if ( simpleName.toLowerCase().endsWith("map") || simpleName.equals("Hashtable")) {
                    expectedTypeParameters = 2;
                } else if (simpleName.equals("Table")) {
                    expectedTypeParameters = 3;
                }

                // ... containers
                if (!operand.hasParameters()) {
                    continue;
                }
                if (operand.getNumParameters() != expectedTypeParameters) {
                    continue;
                }
                ClassDescriptor operandClass = DescriptorFactory.getClassDescriptor(operand);
                if (!isGenericCollection(operandClass)) {
                    continue;
                }

                if (expectedTypeParameters == 2 &&
                        Subtypes2.instanceOf(operandClass, Map.class)
                        && !TypeFrameModelingVisitor.isStraightGenericMap(operandClass)) {
                    continue;
                }
                Type expectedType;
                if (allMethod) {
                    expectedType = operand;
                } else {
                    expectedType = operand.getParameterAt(typeArgument);
                }
                Type actualType = frame.getStackValue(stackPos);
                Type equalsType = actualType;
                if (allMethod) {
                    if (!(actualType instanceof GenericObjectType)) {
                        continue;
                    }
                    equalsType = ((GenericObjectType)actualType).getParameterAt(typeArgument);
                }


                IncompatibleTypes matchResult = compareTypes(expectedType, actualType, allMethod);

                boolean parmIsObject = expectedType.getSignature().equals("Ljava/lang/Object;");
                boolean selfOperation = !allMethod && operand.equals(actualType) && !parmIsObject;
                if (!allMethod && !parmIsObject && actualType instanceof GenericObjectType) {

                    GenericObjectType p2 = (GenericObjectType) actualType;
                    List<? extends ReferenceType> parameters = p2.getParameters();
                    if (parameters != null && parameters.equals(operand.getParameters())) {
                        selfOperation = true;
                    }
                }

                if (!selfOperation && ( matchResult == IncompatibleTypes.SEEMS_OK || matchResult.getPriority() == Priorities.IGNORE_PRIORITY)) {
                    continue;
                }

                if (invokedMethodName.startsWith("contains") || invokedMethodName.equals("remove")) {
                    InstructionHandle next = handle.getNext();
                    if (next != null) {
                        Instruction nextIns = next.getInstruction();

                        if (nextIns instanceof InvokeInstruction) {
                            XMethod nextMethod = XFactory.createXMethod((InvokeInstruction) nextIns, cpg);
                            if (nextMethod.getName().equals("assertFalse")) {
                                continue;
                            }
                        }
                    }
                } else if (invokedMethodName.equals("get") || invokedMethodName.equals("remove")) {
                    InstructionHandle next = handle.getNext();
                    if (next != null) {
                        Instruction nextIns = next.getInstruction();

                        if (nextIns instanceof InvokeInstruction) {
                            XMethod nextMethod = XFactory.createXMethod((InvokeInstruction) nextIns, cpg);
                            if (nextMethod.getName().equals("assertNull")) {
                                continue;
                            }
                        }
                    }
                }
                boolean noisy = false;
                if (invokedMethodName.equals("get")) {
                    UnconditionalValueDerefDataflow unconditionalValueDerefDataflow = classContext
                            .getUnconditionalValueDerefDataflow(method);

                    UnconditionalValueDerefSet unconditionalDeref = unconditionalValueDerefDataflow.getFactAtLocation(location);
                    ValueNumberFrame vnAfter = vnDataflow.getFactAfterLocation(location);
                    ValueNumber top = vnAfter.getTopValue();
                    noisy = unconditionalDeref.getValueNumbersThatAreUnconditionallyDereferenced().contains(top);
                }
                // Prepare bug report
                SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen,
                        sourceFile, handle);
View Full Code Here


                if (methodName.equals("lock") && methodSig.equals("()V")
                        && Hierarchy.isSubtype(className, "java.util.concurrent.locks.Lock")) {

                    Location location = new Location(handle, basicBlock);
                    ValueNumberFrame frame = vnaDataflow.getFactAtLocation(location);
                    ValueNumber lockValue = frame.getTopValue();
                    if (DEBUG) {
                        System.out.println("Lock value is " + lockValue.getNumber() + ", frame=" + frame.toString());
                    }
                    if (DEBUG) {
                        ++numAcquires;
                    }
                    return new Lock(location, className, lockValue);
View Full Code Here

                if (!frame.isValid()) {
                    continue;
                }

                // Get lock set and instance value
                ValueNumber thisValue = !method.isStatic() ? vnaDataflow.getAnalysis().getThisValue() : null;
                LockSet lockSet = lockChecker.getFactAtLocation(location);
                InstructionHandle handle = location.getHandle();
                ValueNumber instance = frame.getInstance(handle.getInstruction(), cpg);
                if (DEBUG) {
                    System.out.println("Lock set: " + lockSet);
                    System.out.println("value number: " + instance.getNumber());
                    System.out.println("Lock count: " + lockSet.getLockCount(instance.getNumber()));
                }

                // Is the instance locked?
                // We consider the access to be locked if either
                // - the object is explicitly locked, or
                // - the field is accessed through the "this" reference,
                // and the method is in the locked method set, or
                // - any value returned by a called method is locked;
                // the (conservative) assumption is that the return lock object
                // is correct for synchronizing the access
                boolean isExplicitlyLocked = lockSet.getLockCount(instance.getNumber()) > 0;
                boolean isAccessedThroughThis = thisValue != null && thisValue.equals(instance);
                boolean isLocked = isExplicitlyLocked
                        || ((isConstructor(method.getName()) || lockedMethodSet.contains(method)) && isAccessedThroughThis)
                        || lockSet.containsReturnValue(vnaDataflow.getAnalysis().getFactory());
View Full Code Here

            if (numConsumed == Constants.UNPREDICTABLE) {
                throw new DataflowAnalysisException("Unpredictable stack consumption", methodGen, handle);
            }
            // if (DEBUG) System.out.println("Getting receiver for frame: " +
            // frame);
            ValueNumber instance = frame.getStackValue(numConsumed - 1);

            // Is the instance locked?
            int lockCount = lockSet.getLockCount(instance.getNumber());
            if (lockCount > 0) {
                // This is a locked call site
                obviouslyLockedSites.add(callSite);
            }
        }
View Full Code Here

                        //                        boolean isImmediateNullTest = next != null
                        //                                && (next.getInstruction() instanceof IFNULL || next.getInstruction() instanceof IFNONNULL);
                        if (countOtherCalls || isIgnored) {
                            BitSet live = llsaDataflow.getAnalysis().getFactAtLocation(location);
                            ValueNumberFrame vna = vnaDataflow.getAnalysis().getFactAtLocation(location);
                            ValueNumber vn = vna.getTopValue();

                            int locals = vna.getNumLocals();
                            //                            boolean isRetained = false;
                            for (int pos = 0; pos < locals; pos++) {
                                if (vna.getValue(pos).equals(vn) && live.get(pos)) {
View Full Code Here

        int opcode = ins.getOpcode();
        int offset = 1;
        if (opcode == LCMP || opcode == LXOR || opcode == LAND || opcode == LOR || opcode == LSUB) {
            offset = 2;
        }
        ValueNumber v0 = frame.getStackValue(0);
        ValueNumber v1 = frame.getStackValue(offset);
        if (!v1.equals(v0)) {
            return;
        }
        if (v0.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT) || v0.hasFlag(ValueNumber.CONSTANT_VALUE)) {
            return;
        }
View Full Code Here

                ValueNumberDataflow valueNumberDataflow = getClassContext().getValueNumberDataflow(getMethod());
                UnconditionalValueDerefDataflow unconditionalValueDerefDataflow = getClassContext()
                        .getUnconditionalValueDerefDataflow(getMethod());
                ValueNumberFrame valueNumberFact = valueNumberDataflow.getFactAtLocation(produced);
                IsNullValueFrame isNullFact = isNullValueDataflow.getFactAtLocation(produced);
                ValueNumber value = valueNumberFact.getTopValue();
                if (isNullFact.getTopValue().isDefinitelyNotNull()) {
                    return;
                }
                if (DEBUG) {
                    System.out.println("Produced: " + produced);
View Full Code Here

        else if (ins instanceof InvokeInstruction && ins.consumeStack(cpg) == 2) {
            InvokeInstruction invoke = (InvokeInstruction) ins;
            isTest = invoke.getMethodName(cpg).equals("equals") &&invoke.getSignature(cpg).equals("(Ljava/lang/Object;)Z") ;
        }
        if (isTest) {
            ValueNumber top = factAtLocation.getStackValue(0);
            if (top.hasFlag(ValueNumber.CONSTANT_VALUE)) {
                return;
            }
            ValueNumber next = factAtLocation.getStackValue(1);
            if (next.hasFlag(ValueNumber.CONSTANT_VALUE)) {
                return;
            }
            FlowValue topTQ = forwardsFact.getValue(top);
            FlowValue nextTQ = forwardsFact.getValue(next);
            if (DEBUG) {
View Full Code Here

            Location location = i.next();

            Set<SourceSinkInfo> sourceSet = forwardDataflow.getAnalysis().getSourceSinkInfoSet(location);

            for (SourceSinkInfo source : sourceSet) {
                ValueNumber vn = source.getValueNumber();
                TypeQualifierValueSet backwardsFact = backwardDataflow.getFactAtLocation(location);
                FlowValue backwardsFlowValue = backwardsFact.getValue(vn);

                if (!(backwardsFlowValue == FlowValue.ALWAYS || backwardsFlowValue == FlowValue.NEVER)) {
                    continue;
View Full Code Here

            Iterator<String> paramIterator = parser.parameterSignatureIterator();
            int i = 0;
            while (paramIterator.hasNext()) {
                String paramSig = paramIterator.next();

                ValueNumber paramVN = vnaDataflow.getAnalysis().getEntryValue(paramLocalOffset);

                handleParameter: if (entryFact.isUnconditionallyDereferenced(paramVN)) {
                    TypeQualifierAnnotation directTypeQualifierAnnotation = TypeQualifierApplications
                            .getDirectTypeQualifierAnnotation(xmethod, i, nonnullTypeQualifierValue);
                    TypeQualifierAnnotation typeQualifierAnnotation = TypeQualifierApplications
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ba.vna.ValueNumber

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.