Package edu.umd.cs.findbugs.ba.npe

Examples of edu.umd.cs.findbugs.ba.npe.IsNullValueFrame


            // Method takes no arguments, or takes no reference arguments
            return;
        }

        // See if any null arguments are passed
        IsNullValueFrame frame = classContext.getIsNullValueDataflow(method).getFactAtLocation(location);
        if (!frame.isValid()) {
            return;
        }
        /*
        if (false && methodName.equals("checkNotNull")
                && invokeInstruction.getClassName(cpg).equals("com.google.common.base.Preconditions")) {
            SignatureParser sigParser = new SignatureParser(signature);
            int numParameters = sigParser.getNumParameters();
            IsNullValue value = frame.getArgument(invokeInstruction, cpg, 0, sigParser);
            if (value.isDefinitelyNotNull()) {
                TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
                int priority = NORMAL_PRIORITY;
                String pattern = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE";
                ValueNumberFrame vnFrame = vnaDataflow.getFactAtLocation(location);
                ValueNumber valueNumber = vnFrame.getArgument(invokeInstruction, cpg, 0, sigParser);
                org.apache.bcel.generic.Type typeOfFirstArgument = typeFrame.getArgument(invokeInstruction, cpg, 0, sigParser);
                String signature2 = typeOfFirstArgument.getSignature();
                boolean constantStringForFirstArgument = signature2.equals("Ljava/lang/String;")
                        && valueNumber.hasFlag(ValueNumber.CONSTANT_VALUE);
                @CheckForNull
                BugAnnotation annotation = BugInstance.getSourceForStackValue(classContext, method, location, numParameters - 1);
                if (value.wouldHaveBeenAKaboom()) {
                    pattern = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE";
                    priority = HIGH_PRIORITY;
                } else if (constantStringForFirstArgument) {
                    annotation = null;
                    priority = HIGH_PRIORITY;
                    if (numParameters == 2) {
                        IsNullValue secondValue = frame.getArgument(invokeInstruction, cpg, 1, sigParser);
                        if (!secondValue.isDefinitelyNotNull()) {
                            pattern = "DMI_ARGUMENTS_WRONG_ORDER";
                            priority = NORMAL_PRIORITY;
                        }
                    }
                }

                BugInstance warning = new BugInstance(this, pattern, priority)
                .addClassAndMethod(classContext.getJavaClass(), method).addOptionalAnnotation(annotation)
                .addCalledMethod(cpg, invokeInstruction).addSourceLine(classContext, method, location);

                bugReporter.reportBug(warning);
            }
        }
         */
        BitSet nullArgSet = frame.getArgumentSet(invokeInstruction, cpg, new DataflowValueChooser<IsNullValue>() {
            @Override
            public boolean choose(IsNullValue value) {
                // Only choose non-exception values.
                // Values null on an exception path might be due to
                // infeasible control flow.
                return value.mightBeNull() && !value.isException() && !value.isReturnValue();
            }
        });
        BitSet definitelyNullArgSet = frame.getArgumentSet(invokeInstruction, cpg, new DataflowValueChooser<IsNullValue>() {
            @Override
            public boolean choose(IsNullValue value) {
                return value.isDefinitelyNull();
            }
        });
        nullArgSet.and(definitelyNullArgSet);
        if (nullArgSet.isEmpty()) {
            return;
        }
        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) {
View Full Code Here


    }

    private void examinePutfieldInstruction(Location location, PUTFIELD ins, ConstantPoolGen cpg)
            throws DataflowAnalysisException {

        IsNullValueFrame frame = invDataflow.getFactAtLocation(location);
        if (!frame.isValid()) {
            return;
        }
        IsNullValue tos = frame.getTopValue();
        if (tos.isDefinitelyNull()) {
            XField field = XFactory.createXField(ins, cpg);
            NullnessAnnotation annotation = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase()
                    .getResolvedAnnotation(field, false);
            if (annotation == NullnessAnnotation.NONNULL) {
View Full Code Here

        if (DEBUG_NULLRETURN) {
            System.out.println("Checking null return at " + location);
        }

        IsNullValueDataflow invDataflow = classContext.getIsNullValueDataflow(method);
        IsNullValueFrame frame = invDataflow.getFactAtLocation(location);
        ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location);
        if (!vnaFrame.isValid()) {
            return;
        }
        ValueNumber valueNumber = vnaFrame.getTopValue();
        if (!frame.isValid()) {
            return;
        }
        IsNullValue tos = frame.getTopValue();
        if (tos.isDefinitelyNull()) {
            BugAnnotation variable = ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location, valueNumber, vnaFrame,
                    "VALUE_OF");

            String bugPattern = "NP_NONNULL_RETURN_VIOLATION";
View Full Code Here

                    System.out.println("target was alive previously");
                }
                // Block was not dead before the null pointer analysis.
                // See if it is dead now by inspecting the null value frame.
                // If it's TOP, then the block became dead.
                IsNullValueFrame invFrame = invDataflow.getStartFact(target);
                createdDeadCode = invFrame.isTop();
                if (DEBUG) {
                    System.out.println("target is now " + (createdDeadCode ? "dead" : "alive"));
                }

            }
View Full Code Here

                Instruction ins = handle.getInstruction();
                if (!(ins instanceof ALOAD)) {
                    continue;
                }

                IsNullValueFrame frame = nullValueDataflow.getFactAtLocation(location);
                if (!frame.isValid()) {
                    // This basic block is probably dead
                    continue;
                }
                // System.out.println(handle.getPosition() + "\t" +
                // ins.getName() + "\t" + frame);

                ALOAD load = (ALOAD) ins;

                int index = load.getIndex();
                IsNullValue v = frame.getValue(index);
                if (!v.isDefinitelyNull()) {
                    int sourceLine = lineNumbers.getSourceLine(handle.getPosition());
                    if (sourceLine > 0) {
                        linesWithLoadsOfNotDefinitelyNullValues.set(sourceLine);
                    }
                }
            }
        }

        IdentityHashMap<InstructionHandle, Object> sometimesGood = new IdentityHashMap<InstructionHandle, Object>();

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();
            InstructionHandle handle = location.getHandle();
            Instruction ins = handle.getInstruction();
            if (!(ins instanceof ALOAD)) {
                continue;
            }
            IsNullValueFrame frame = nullValueDataflow.getFactAtLocation(location);
            if (!frame.isValid()) {
                // This basic block is probably dead
                continue;
            }
            // System.out.println(handle.getPosition() + "\t" + ins.getName() +
            // "\t" + frame);

            ALOAD load = (ALOAD) ins;

            int index = load.getIndex();
            IsNullValue v = frame.getValue(index);
            if (!v.isDefinitelyNull()) {
                sometimesGood.put(handle, null);
            }
        }

        // System.out.println(nullValueDataflow);
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();

            InstructionHandle handle = location.getHandle();
            Instruction ins = handle.getInstruction();
            if (!(ins instanceof ALOAD)) {
                continue;
            }

            if (sometimesGood.containsKey(handle)) {
                continue;
            }
            IsNullValueFrame frame = nullValueDataflow.getFactAtLocation(location);
            if (!frame.isValid()) {
                // This basic block is probably dead
                continue;
            }
            // System.out.println(handle.getPosition() + "\t" + ins.getName() +
            // "\t" + frame);

            ALOAD load = (ALOAD) ins;

            int index = load.getIndex();
            IsNullValue v = frame.getValue(index);
            if (v.isDefinitelyNull()) {
                InstructionHandle nextHandle = handle.getNext();
                Instruction next = nextHandle.getInstruction();
                int position = location
                        .getHandle().getPosition();
View Full Code Here

                || (opcode == Constants.IF_ACMPNE && edge.getType() == EdgeTypes.FALL_THROUGH_EDGE)) {
            //
            // Check nullness and type of the top two stack values.
            //
            Location location = new Location(last, sourceBlock);
            IsNullValueFrame invFrame = invDataflow.getFactAtLocation(location);
            TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
            if (invFrame.isValid() && typeFrame.isValid()) {
                //
                // See if exactly one of the top two stack values is definitely
                // null
                //
                boolean leftIsNull = invFrame.getStackValue(1).isDefinitelyNull();
                boolean rightIsNull = invFrame.getStackValue(0).isDefinitelyNull();

                if ((leftIsNull || rightIsNull) && !(leftIsNull && rightIsNull)) {
                    //
                    // Now we can determine what type was compared to null.
                    //
View Full Code Here

                if (line > 0 && linesMentionedMultipleTimes.get(line)) {
                    split = true;
                }
            }

            IsNullValueFrame nullFrame = isNullDataflow.getFactAtLocation(location);
            if (!nullFrame.isValid()) {
                continue;
            }
            IsNullValue operandNullness = nullFrame.getTopValue();
            if (DEBUG) {
                String kind = isCast ? "checkedCast" : "instanceof";
                System.out.println(kind + " at pc: " + pc + " in " + methodName);
                System.out.println(" occurrences: " + occurrences);
                System.out.println("XXX: " + operandNullness);
View Full Code Here

        if (firstChar != 'L' && firstChar != '[') {
            return;
        }
        NullnessAnnotation resolvedAnnotation = database.getResolvedAnnotation(field, true);
        if (resolvedAnnotation == NullnessAnnotation.NONNULL) {
            IsNullValueFrame invFrame = invDataflow.getFactAtLocation(location);
            if (!invFrame.isValid()) {
                return;
            }
            IsNullValue value = invFrame.getTopValue();
            if (reportDereference(value)) {
                ValueNumber vn = vnaFrame.getTopValue();
                fact.addDeref(vn, location);
            }
        }
View Full Code Here

    }

    public static Set<ValueNumber> checkAllNonNullParams(Location location, ValueNumberFrame vnaFrame,
            ConstantPoolGen constantPool, @CheckForNull Method method, @CheckForNull IsNullValueDataflow invDataflow,
            TypeDataflow typeDataflow) throws DataflowAnalysisException {
        IsNullValueFrame invFrame = null;
        if (invDataflow != null) {
            invFrame = invDataflow.getFactAtLocation(location);
        }
        Set<ValueNumber> result1 = checkNonNullParams(location, vnaFrame, constantPool, method, invFrame);
        Set<ValueNumber> result2 = checkUnconditionalDerefDatabase(location, vnaFrame, constantPool, invFrame, typeDataflow);
View Full Code Here

        }
        if (vn.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT)) {
            return;
        }

        IsNullValueFrame startFact = null;

        startFact = invDataflow.getStartFact(fallThroughPredecessor);

        if (!startFact.isValid()) {
            return;
        }

        int slot = startFact.getInstanceSlot(location.getHandle().getInstruction(), methodGen.getConstantPool());
        if (!reportDereference(startFact, slot)) {
            return;
        }
        if (DEBUG) {
            System.out.println("FOUND GUARANTEED DEREFERENCE");
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ba.npe.IsNullValueFrame

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.