Package edu.umd.cs.findbugs.ba

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


            }
        }
        if (prevIns instanceof AALOAD) {
            CFG cfg = classContext.getCFG(method);

            Location prev = getPreviousLocation(cfg, location, true);
            if (prev != null) {
                Location prev2 = getPreviousLocation(cfg, prev, true);
                if (prev2 != null && prev2.getHandle().getInstruction() instanceof GETSTATIC) {
                    GETSTATIC getStatic = (GETSTATIC) prev2.getHandle().getInstruction();
                    if (getStatic.getSignature(cpg).equals("[Ljava/lang/String;")) {
                        return true;
                    }
                }
            }
View Full Code Here


        return null;
    }

    private @CheckForNull
    Location getPreviousLocation(CFG cfg, Location startLocation, boolean skipNops) {
        Location loc = startLocation;
        InstructionHandle prev = getPreviousInstruction(loc.getHandle(), skipNops);
        if (prev != null) {
            return new Location(prev, loc.getBasicBlock());
        }
        BasicBlock block = loc.getBasicBlock();
        while (true) {
            block = cfg.getPredecessorWithEdgeType(block, EdgeTypes.FALL_THROUGH_EDGE);
            if (block == null) {
                return null;
            }
            InstructionHandle lastInstruction = block.getLastInstruction();
            if (lastInstruction != null) {
                return new Location(lastInstruction, block);
            }
        }
    }
View Full Code Here

        StringAppendState stringAppendState = getStringAppendState(cfg, cpg);

        ConstantDataflow dataflow = classContext.getConstantDataflow(method);
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();
            Instruction ins = location.getHandle().getInstruction();
            if (!(ins instanceof InvokeInstruction)) {
                continue;
            }
            InvokeInstruction invoke = (InvokeInstruction) ins;
            if (isDatabaseSink(invoke, cpg)) {
                ConstantFrame frame = dataflow.getFactAtLocation(location);
                int numArguments = frame.getNumArguments(invoke, cpg);
                Constant value = frame.getStackValue(numArguments - 1);

                if (!value.isConstantString()) {
                    // TODO: verify it's the same string represented by
                    // stringAppendState
                    // FIXME: will false positive on const/static strings
                    // returns by methods
                    Location prev = getPreviousLocation(cfg, location, true);
                    if (prev == null || !isSafeValue(prev, cpg)) {
                        BugInstance bug = generateBugInstance(javaClass, methodGen, location.getHandle(), stringAppendState);
                        if(!testingEnabled && "TESTING".equals(bug.getType())){
                            continue;
                        }
View Full Code Here

            String methodName = methodGen.getClassName() + "." + methodGen.getName();
            System.out.println("Checking " + methodName);
        }

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();
            InstructionHandle handle = location.getHandle();
            Instruction ins = handle.getInstruction();

            Use use = getUse(cpg, ins);
            if (use == null) {
                continue;
View Full Code Here

    private void checkDataflow(XMethod xmethod, CFG cfg, TypeQualifierValue<?> typeQualifierValue,
            ValueNumberDataflow vnaDataflow, ForwardTypeQualifierDataflow forwardDataflow,
            BackwardTypeQualifierDataflow backwardDataflow) throws DataflowAnalysisException, CheckedAnalysisException {
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location loc = i.next();

            TypeQualifierValueSet forwardsFact = forwardDataflow.getFactAtLocation(loc);
            TypeQualifierValueSet backwardsFact = backwardDataflow.getFactAfterLocation(loc);

            if (!forwardsFact.isValid() || !backwardsFact.isValid()) {
                continue;
            }

            if (DEBUG) {
                checkLocation = "location " + loc.toCompactString();
            }
            checkForConflictingValues(xmethod, cfg, typeQualifierValue, forwardsFact, backwardsFact, loc,
                    loc, vnaDataflow.getFactAtLocation(loc));
            checkForEqualityTest(xmethod, cfg, typeQualifierValue, forwardsFact, loc, vnaDataflow.getFactAtLocation(loc));
        }

        for (Iterator<Edge> i = cfg.edgeIterator(); i.hasNext();) {
            Edge edge = i.next();


            // NOTE: when checking forwards and backwards values on an edge,
            // we don't want to apply BOTH edge transfer functions,
            // since the purpose of the edge transfer function is to
            // propagate information across phi nodes (effectively
            // copying information about one value to another).
            // Due to pruning of backwards values when a conflict is detected,
            // we need to check backwards values as "early" as possible,
            // meaning that we want to check at the edge target
            // (before the backwards edge transfer function has pruned
            // the backwards value.)
            TypeQualifierValueSet forwardFact = forwardDataflow.getFactOnEdge(edge);
            TypeQualifierValueSet backwardFact = backwardDataflow.getResultFact(edge.getTarget());

            // The edge target location is where we can check
            // for conflicting flow values.
            Location edgeTargetLocation = getEdgeTargetLocation(cfg, edge);
            ValueNumberFrame vnaFrame = (edgeTargetLocation != null) ? vnaDataflow.getFactAtLocation(edgeTargetLocation) : null;

            // What location do we want to report to the user
            // as where the conflict occurs?
            // The edge source location is generally better,
            // but edge target location is ok as a fallback.
            Location locationToReport;
            if (edge.getSource().getLastInstruction() != null) {
                locationToReport = getEdgeSourceLocation(cfg, edge);
            } else {
                locationToReport = edgeTargetLocation;
            }
View Full Code Here

        // Check to see if any backwards ALWAYS or NEVER values
        // reach incompatible sources.

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            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;
                }
                if (DEBUG) {
                    System.out.println("Checking value source at " + location.toCompactString() + " for " + typeQualifierValue);
                    System.out.println("  back=" + backwardsFact);
                    System.out.println("  source=" + source);
                }

                // Check to see if this warning has already been reported
View Full Code Here

    private Location getEdgeTargetLocation(CFG cfg, Edge edge) {
        BasicBlock targetBlock = edge.getTarget();

        // Target block is nonempty?
        if (targetBlock.getFirstInstruction() != null) {
            return new Location(targetBlock.getFirstInstruction(), targetBlock);
        }

        // Target block is an ETB?
        if (targetBlock.isExceptionThrower()) {
            BasicBlock fallThroughSuccessor = cfg.getSuccessorWithEdgeType(targetBlock, EdgeTypes.FALL_THROUGH_EDGE);
            if (fallThroughSuccessor == null) {
                // Fall through edge might have been pruned
                for (Iterator<Edge> i = cfg.removedEdgeIterator(); i.hasNext();) {
                    Edge removedEdge = i.next();
                    if (removedEdge.getSource() == targetBlock && removedEdge.getType() == EdgeTypes.FALL_THROUGH_EDGE) {
                        fallThroughSuccessor = removedEdge.getTarget();
                        break;
                    }
                }
            }

            if (fallThroughSuccessor != null && fallThroughSuccessor.getFirstInstruction() != null) {
                return new Location(fallThroughSuccessor.getFirstInstruction(), fallThroughSuccessor);
            }
        }

        return null;
    }
View Full Code Here

        return null;
    }

    private Location getEdgeSourceLocation(CFG cfg, Edge edge) {
        BasicBlock sourceBlock = edge.getSource();
        return (sourceBlock.getLastInstruction() != null) ? new Location(sourceBlock.getLastInstruction(), sourceBlock) : null;
    }
View Full Code Here

            annotateWarningWithSourceSinkInfo(warning, xMethod, vn, source);
        }
        Set<? extends SourceSinkInfo> sinkSet = (backward == FlowValue.ALWAYS) ? backwardsFact.getWhereAlways(vn) : backwardsFact
                .getWhereNever(vn);

        Location sinkLocation = getSinkLocation(sinkSet);
        if (sinkLocation == null) {
            AnalysisContext.logError("Unable to compute sink location for " + xMethod);
            return;
        }

        // Hopefully we can find the conflicted value in a local variable
        if (locationWhereDoomedValueIsObserved != null) {
            Method method = Global.getAnalysisCache().getMethodAnalysis(Method.class, xMethod.getMethodDescriptor());

            LocalVariableAnnotation localVariable = ValueNumberSourceInfo.findLocalAnnotationFromValueNumber(method,
                    locationWhereDoomedValueIsObserved, vn, vnaFrame);
            if (localVariable != null && !localVariable.equals(warning.getPrimaryLocalVariableAnnotation())) {
                localVariable.setDescription(localVariable.isSignificant() ? "LOCAL_VARIABLE_VALUE_DOOMED_NAMED"
                        : "LOCAL_VARIABLE_VALUE_DOOMED");
                warning.add(localVariable);

            }
            if (!sinkLocation.equals(locationToReport)) {
                // Report where we observed the value.
                // Note that for conflicts detected on control edges,
                // we REPORT the edge source location
                // rather than the target location, even though it is the
                // target location where the conflict is detected.
View Full Code Here

    }

    private @CheckForNull
    Location getSinkLocation(Iterable<? extends SourceSinkInfo> info) {
        for (SourceSinkInfo s : info) {
            Location l = getSinkLocation(s);
            if (l != null) {
                return l;
            }

        }
View Full Code Here

TOP

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

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.