Package edu.umd.cs.findbugs.ba

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


    private State() {
    }

    public State(/* int maxObligationTypes, */ObligationFactory factory) {
        this.obligationSet = new ObligationSet(/* maxObligationTypes, */factory);
        this.path = new Path();
    }
View Full Code Here


        final StateSet inputFact = fact;

        if (DEBUG && inputFact.isValid()) {
            for (Iterator<State> i = inputFact.stateIterator(); i.hasNext();) {
                State state = i.next();
                Path path = state.getPath();
                if (path.getLength() > 0) {
                    if (path.getBlockIdAt(path.getLength() - 1) != edge.getSource().getLabel()) {
                        throw new IllegalStateException("on edge " + edge + ": state " + state + " missing source label in path");
                    }
                }
            }
        }

        // Handle easy top and bottom cases
        if (inputFact.isTop() || result.isBottom() ) {
            // Nothing to do
        } else if (inputFact.isBottom() || result.isTop() || result.isEmpty()) {
            copy(inputFact, result);
        } else if (inputFact.isOnExceptionPath()
                && !result.isOnExceptionPath()) {
            if (DEBUG) {
                System.out.println("Ignoring " + inputFact + " in favor of " + result);
                BasicBlock from = edge.getSource();
                BasicBlock to = edge.getTarget();
                System.out.printf("  edge %s -> %s%n", from, to);
            }
            // Nothing to do
        } else if(!inputFact.isOnExceptionPath() && !inputFact.isEmpty()
                && result.isOnExceptionPath()) {
            if (DEBUG) {
                System.out.println("overwriting " + result + " with " + inputFact);
            }
            copy(inputFact, result);
        } else {
            // We will destructively replace the state map of the result fact
            // we're building.
            final Map<ObligationSet, State> updatedStateMap = result.createEmptyMap();
            // Build a Set of all ObligationSets.
            Set<ObligationSet> allObligationSets = new HashSet<ObligationSet>();
            allObligationSets.addAll(inputFact.getAllObligationSets());
            allObligationSets.addAll(result.getAllObligationSets());

            // Go through set of all ObligationsSets.
            // When both inputFact and result fact have a State
            // with a common ObligationSet, we combine them into
            // a single State.
            for (Iterator<ObligationSet> i = allObligationSets.iterator(); i.hasNext();) {
                ObligationSet obligationSet = i.next();

                State stateInInputFact = inputFact.getStateWithObligationSet(obligationSet);
                State stateInResultFact = result.getStateWithObligationSet(obligationSet);

                State stateToAdd;

                if (stateInInputFact != null && stateInResultFact != null) {
                    // Combine the two states,
                    // using the shorter path as the basis
                    // of the new state's path.
                    // If both paths are the same length, we arbitrarily choose
                    // the path from the result fact.
                    Path path = stateInResultFact.getPath();
                    if (stateInInputFact.getPath().getLength() < path.getLength()) {
                        path = stateInInputFact.getPath();
                    }

                    stateToAdd = new State(factory);
                    stateToAdd.getObligationSet().copyFrom(obligationSet);
View Full Code Here

        }

        private void checkStateForLeakedObligations(State state, Map<Obligation, State> leakedObligationMap)
                throws IllegalStateException {
            if (DEBUG) {
                Path path = state.getPath();
                if (path.getLength() > 0 && path.getBlockIdAt(path.getLength() - 1) != cfg.getExit().getLabel()) {
                    throw new IllegalStateException("path " + path + " at cfg exit has no label for exit block");
                }
            }

            for (int id = 0; id < database.getFactory().getMaxObligationTypes(); ++id) {
View Full Code Here

         *         negative if attempt to release an un-acquired obligation)
         */
        private int getAdjustedLeakCount(State state, int obligationId) {

            final Obligation obligation = database.getFactory().getObligationById(obligationId);
            Path path = state.getPath();
            PostProcessingPathVisitor visitor = new PostProcessingPathVisitor(obligation, state);
            path.acceptVisitor(cfg, visitor);

            if (visitor.couldNotAnalyze()) {
                return 0;
            } else {
                return visitor.getAdjustedLeakCount();
View Full Code Here

            return subtypes2.isSubtype(type, obligationType);
        }

        private void reportPath(final BugInstance bugInstance, final Obligation obligation, final State state) {

            Path path = state.getPath();

            // This PathVisitor will traverse the Path and add appropriate
            // SourceLineAnnotations to the BugInstance.
            PathVisitor visitor = new PathVisitor() {
                boolean sawFirstCreation;

                SourceLineAnnotation lastSourceLine;// = creationSourceLine;

                BasicBlock curBlock;

                @Override
                public void visitBasicBlock(BasicBlock basicBlock) {
                    curBlock = basicBlock;

                    // See if the initial instance of the leaked resource
                    // is in the entry fact due to a @WillClose annotation.
                    if (curBlock == cfg.getEntry()) {
                        // Get the entry fact - it should have precisely one
                        // state
                        StateSet entryFact = dataflow.getResultFact(curBlock);
                        Iterator<State> i = entryFact.stateIterator();
                        if (i.hasNext()) {
                            State entryState = i.next();
                            if (entryState.getObligationSet().getCount(obligation.getId()) > 0) {
                                lastSourceLine = SourceLineAnnotation.forFirstLineOfMethod(methodDescriptor);
                                lastSourceLine
                                .setDescription(SourceLineAnnotation.ROLE_OBLIGATION_CREATED_BY_WILLCLOSE_PARAMETER);
                                bugInstance.add(lastSourceLine);
                                sawFirstCreation = true;

                                if (REPORT_PATH_DEBUG) {
                                    System.out.println("  " + obligation + " created by @WillClose parameter at "
                                            + lastSourceLine);
                                }
                            }
                        }
                    }
                }

                @Override
                public void visitInstructionHandle(InstructionHandle handle) {
                    boolean isCreation = (dataflow.getAnalysis().getActionCache().addsObligation(curBlock, handle, obligation));

                    if (!sawFirstCreation && !isCreation) {
                        return;
                    }

                    SourceLineAnnotation sourceLine = SourceLineAnnotation.fromVisitedInstruction(methodDescriptor, new Location(
                            handle, curBlock));
                    sourceLine.setDescription(isCreation ? SourceLineAnnotation.ROLE_OBLIGATION_CREATED
                            : SourceLineAnnotation.ROLE_PATH_CONTINUES);

                    boolean isInteresting = (sourceLine.getStartLine() > 0)
                            && (lastSourceLine == null || isCreation || sourceLine.getStartLine() != lastSourceLine.getStartLine());

                    if (REPORT_PATH_DEBUG) {
                        System.out.println("  " + handle.getPosition() + " --> " + sourceLine + (isInteresting ? " **" : ""));
                    }
                    if (isInteresting) {
                        bugInstance.add(sourceLine);
                        lastSourceLine = sourceLine;
                        if (isCreation) {
                            sawFirstCreation = true;
                        }
                    }
                }

                @Override
                public void visitEdge(Edge edge) {
                    if (REPORT_PATH_DEBUG) {
                        System.out.println("Edge of type " + Edge.edgeTypeToString(edge.getType()) + " to "
                                + edge.getTarget().getLabel());
                        if (edge.getTarget().getFirstInstruction() != null) {
                            System.out.println("  First instruction in target: " + edge.getTarget().getFirstInstruction());
                        }
                        if (edge.getTarget().isExceptionThrower()) {
                            System.out.println("  exception thrower for " + edge.getTarget().getExceptionThrower());
                        }
                        if (edge.isExceptionEdge()) {
                            System.out.println("  exceptions thrown: " + typeDataflow.getEdgeExceptionSet(edge));
                        }
                    }
                }
            };

            // Visit the Path
            path.acceptVisitor(cfg, visitor);
        }
View Full Code Here

TOP

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

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.