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

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


        }
        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";
            int priority = NORMAL_PRIORITY;
            if (tos.isDefinitelyNull() && !tos.isException()) {
                priority = HIGH_PRIORITY;
            }
            String methodName = method.getName();
            if (methodName.equals("clone")) {
                bugPattern = "NP_CLONE_COULD_RETURN_NULL";
View Full Code Here


        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) {

                BugAnnotation variableAnnotation = null;
                try {
                    ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location);
                    ValueNumber valueNumber = vnaFrame.getTopValue();
                    variableAnnotation = ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location, valueNumber,
                            vnaFrame, "VALUE_OF");

                } catch (DataflowAnalysisException e) {
                    AnalysisContext.logError("error", e);
                } catch (CFGBuilderException e) {
                    AnalysisContext.logError("error", e);
                }

                BugInstance warning = new BugInstance(this, "NP_STORE_INTO_NONNULL_FIELD", tos.isDefinitelyNull() ? HIGH_PRIORITY
                        : NORMAL_PRIORITY).addClassAndMethod(classContext.getJavaClass(), method).addField(field)
                        .addOptionalAnnotation(variableAnnotation).addSourceLine(classContext, method, location);

                bugReporter.reportBug(warning);
            }
View Full Code Here

                // 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();
                int catchSizeANY = Util.getSizeOfSurroundingTryBlock(method, "", position);
                if (catchSizeANY < Integer.MAX_VALUE && isNullTestedClose( classContext, load, nextHandle, next)) {
                    continue;
                }
                InstructionHandle prevHandle = handle.getPrev();
                SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen,
                        sourceFile, handle);
                SourceLineAnnotation prevSourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext,
                        methodGen, sourceFile, prevHandle);

                if (next instanceof ARETURN) {
                    // probably stored for duration of finally block
                    continue;
                }
                if (next instanceof GOTO) {
                    InstructionHandle targ = ((BranchInstruction) next).getTarget();
                    if (targ.getInstruction() instanceof ARETURN) {
                        // Skip for the same reason we would skip if
                        // (next instanceof ARETURN) were true. This
                        // is necessary because the bytecode compiler
                        // compiles the ternary ? operator with a GOTO
                        // to an ARETURN instead of just an ARETURN.
                        continue;
                    }
                }
                int startLine = sourceLineAnnotation.getStartLine();
                if (startLine > 0 && lineMentionedMultipleTimes.get(startLine)
                        && linesWithLoadsOfNotDefinitelyNullValues.get(startLine)) {
                    continue;
                }

                int previousLine = prevSourceLineAnnotation.getEndLine();
                if (startLine < previousLine) {
                    // probably stored for duration of finally block
                    // System.out.println("Inverted line");
                    continue;
                }
                int priority = NORMAL_PRIORITY;
                if (!v.isChecked()) {
                    priority++;
                }

                BugAnnotation variableAnnotation = null;
                try {
View Full Code Here

            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);
            }

            if (split && !isCast) {
                // don't report this case; it might be infeasible due to
                // inlining
                continue;
            }

            TypeFrame frame = typeDataflow.getFactAtLocation(location);
            if (!frame.isValid()) {
                // This basic block is probably dead
                continue;
            }

            Type operandType = frame.getTopValue();
            if (operandType.equals(TopType.instance())) {
                // unreachable
                continue;
            }
            boolean operandTypeIsExact = frame.isExact(frame.getStackLocation(0));
            final Type castType = ((TypedInstruction) ins).getType(cpg);

            if (!(castType instanceof ReferenceType)) {
                // This shouldn't happen either
                continue;
            }
            String castSig = castType.getSignature();

            if (operandType.equals(NullType.instance()) || operandNullness.isDefinitelyNull()) {
                SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen,
                        sourceFile, handle);
                assert castSig.length() > 1;
                if (!isCast) {
                    accumulator.accumulateBug(new BugInstance(this, "NP_NULL_INSTANCEOF", split ? LOW_PRIORITY : NORMAL_PRIORITY)
View Full Code Here

    public static boolean reportPotentialDereference(Location location, IsNullValueFrame invFrame)
            throws DataflowAnalysisException {
        if (!invFrame.isValid()) {
            return false;
        }
        IsNullValue value = invFrame.getTopValue();
        if (value.isDefinitelyNotNull()) {
            return false;
        }
        if (value.isDefinitelyNull()) {
            return false;
        }
        return true;
    }
View Full Code Here

        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

        IsNullConditionDecision decision = invFrame.getDecision();
        if (decision == null) {
            return null;
        }

        IsNullValue inv = decision.getDecision(edge.getType());
        if (inv == null || !inv.isDefinitelyNotNull()) {
            return null;
        }
        ValueNumber value = decision.getValue();
        if (DEBUG) {
            System.out.println("Value number " + value + " is known nonnull on " + edge);
View Full Code Here

                    }
                    IsNullValueFrame frame = isNullDataflow.getFactAtLocation(location);
                    if (!frame.isValid()) {
                        return false;
                    }
                    IsNullValue receiver = frame.getInstance(ins, cpg);
                    boolean notNull = receiver.isDefinitelyNotNull();
                    if (DEBUG && notNull) {
                        System.out.println("Ignoring exception from non-null GETFIELD");
                    }
                    return notNull;
                } else if (ins instanceof InvokeInstruction) {
View Full Code Here

                        IsNullValueFrame iFrame = invDataflow.getAnalysis().getFactAtPC(invDataflow.getCFG(), getPC());
                        AvailableLoad l = new AvailableLoad(f);
                        ValueNumber[] availableLoads = vFrame.getAvailableLoad(l);
                        if (availableLoads != null && iFrame.isTrackValueNumbers()) {
                            for (ValueNumber v : availableLoads) {
                                IsNullValue knownValue = iFrame.getKnownValue(v);
                                if (knownValue == null) {
                                    continue;
                                }
                                if (knownValue.isDefinitelyNotNull()) {
                                    if (valuePut.isNull()) {
                                        priority++;
                                    } else {
                                        priority--;
                                    }
                                    break;
                                } else if (knownValue.isDefinitelyNull()) {
                                    break checkWriteToStaticFromInstanceMethod;
                                }
                            }
                        }
View Full Code Here

                }
                IsNullValueFrame frame = inv.getFactAtLocation(location);
                if (!frame.isValid()) {
                    continue;
                }
                IsNullValue value = frame.getTopValue();
                if (!value.isDefinitelyNotNull()) {
                    guaranteedNonNull = false;
                    break;
                }

            }
View Full Code Here

TOP

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

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.