Package edu.umd.cs.findbugs.ba.obl

Examples of edu.umd.cs.findbugs.ba.obl.Obligation


            SplitCamelCaseIdentifier splitter = new SplitCamelCaseIdentifier(methodName);
            methodHasCloseInName = splitter.split().contains("close");
            Obligation[] paramObligationTypes = database.getFactory().getParameterObligationTypes(xmethod);

            for (int i = 0; i < xmethod.getNumParams(); i++) {
                Obligation obligationType = paramObligationTypes[i];
                if (obligationType == null) {
                    continue;
                }
                if (methodHasCloseInName) {
                    // Method has "close" in its name.
View Full Code Here


            //
            // Report a separate BugInstance for each Obligation,State pair.
            // (Two different obligations may be leaked in the same state.)
            //
            for (Map.Entry<Obligation, State> entry : leakedObligationMap.entrySet()) {
                Obligation obligation = entry.getKey();
                State state = entry.getValue();
                reportWarning(obligation, state, factAtExit);
            }
            // TODO: closing of nonexistent resources
View Full Code Here

                    throw new IllegalStateException("path " + path + " at cfg exit has no label for exit block");
                }
            }

            for (int id = 0; id < database.getFactory().getMaxObligationTypes(); ++id) {
                Obligation obligation = database.getFactory().getObligationById(id);
                // If the raw count produced by the analysis
                // for this obligation type is 0,
                // assume everything is ok on this state's path.
                int rawLeakCount = state.getObligationSet().getCount(id);
                if (rawLeakCount == 0) {
View Full Code Here

         * @return the adjusted leak count (positive if leaked obligation,
         *         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()) {
View Full Code Here

                if (DEBUG_FP && !(producedType instanceof ObjectType)) {
                    System.out.println("Produced type " + producedType + " not an ObjectType");
                }

                if (producedType instanceof ObjectType) {
                    Obligation produced = database.getFactory().getObligationByType((ObjectType) producedType);

                    if (DEBUG_FP && produced == null) {
                        System.out.println("Produced type  " + producedType + " not an obligation type");
                    }

                    if (produced != null) {
                        XMethod calledMethod = XFactory.createXMethod(inv, cpg);
                        Obligation[] params = database.getFactory().getParameterObligationTypes(calledMethod);

                        for (int i = 0; i < params.length; i++) {
                            Obligation consumed = params[i];

                            if (DEBUG_FP && consumed == null) {
                                System.out.println("Param " + i + " not an obligation type");
                            }

                            if (DEBUG_FP && consumed != null && consumed.equals(produced)) {
                                System.out.println("Consumed type is the same as produced type");
                            }

                            if (consumed != null && !consumed.equals(produced)) {
                                // See if an instance of the consumed obligation
                                // type
                                // exists here.
                                if (transferState.getObligationSet().getCount(consumed.getId()) > 0) {
                                    transferList.add(new PossibleObligationTransfer(consumed, produced));
                                    if (DEBUG_FP) {
                                        System.out.println("===> Possible transfer of " + consumed + " to " + produced + " at "
                                                + handle);
                                    }
View Full Code Here

            if (u != null) {
                AuxilaryObligationPropertyDatabase db = new AuxilaryObligationPropertyDatabase();
                db.read(u.openStream());
                for (Map.Entry<MethodDescriptor, String> e : db.entrySet()) {
                    String[] v = e.getValue().split(",");
                    Obligation obligation = database.getFactory().getObligationByName(v[2]);
                    if (obligation == null) {
                        obligation = database.getFactory().addObligation(v[2]);
                    }
                    database.addEntry(new MatchMethodEntry(e.getKey(), ObligationPolicyDatabaseActionType.valueOf(v[0]),
                            ObligationPolicyDatabaseEntryType.valueOf(v[1]), obligation));
View Full Code Here

    public void visitClass(ClassDescriptor classDescriptor) throws CheckedAnalysisException {

        XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, classDescriptor);

        // Is this class an obligation type?
        Obligation thisClassObligation = database.getFactory().getObligationByType(xclass.getClassDescriptor());

        // Scan methods for uses of obligation-related annotations
        for (XMethod xmethod : xclass.getXMethods()) {
            // Is this method marked with @CreatesObligation?
            if (thisClassObligation != null) {
View Full Code Here

            SplitCamelCaseIdentifier splitter = new SplitCamelCaseIdentifier(xmethod.getName());
            methodHasCloseInName = splitter.split().contains("close");
        }

        for (int i = 0; i < xmethod.getNumParams(); i++) {
            Obligation obligationType = paramObligationTypes[i];
            if (obligationType != null) {
                if (xmethod.getParameterAnnotation(i, willCloseWhenClosed) != null) {
                    //
                    // Calling this method deletes a parameter obligation
                    // and
View Full Code Here

        addFileStreamEntries("InputStream");
        addFileStreamEntries("OutputStream");
        addFileStreamEntries("Reader");
        addFileStreamEntries("Writer");

        Obligation javaIoInputStreamObligation = database.getFactory().getObligationByName("java.io.InputStream");
        database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.lang.Class")),
                new ExactStringMatcher("getResourceAsStream"),
                new ExactStringMatcher("(Ljava/lang/String;)Ljava/io/InputStream;"), false,
                ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, javaIoInputStreamObligation));
        Obligation javaIoOutputStreamObligation = database.getFactory().getObligationByName("java.io.OutputStream");
        database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil
                .getObjectTypeInstance("java.util.logging.StreamHandler")), new ExactStringMatcher("setOutputStream"),
                new ExactStringMatcher("(Ljava/io/OutputStream;)V"), false, ObligationPolicyDatabaseActionType.DEL,
                ObligationPolicyDatabaseEntryType.STRONG, javaIoOutputStreamObligation));

        database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil
                .getObjectTypeInstance("java.io.FileOutputStream")), new ExactStringMatcher("getChannel"),
                new ExactStringMatcher("()Ljava/nio/channels/FileChannel;"), false, ObligationPolicyDatabaseActionType.DEL,
                ObligationPolicyDatabaseEntryType.STRONG, javaIoOutputStreamObligation));
        database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil
                .getObjectTypeInstance("java.io.FileInputStream")), new ExactStringMatcher("getChannel"),
                new ExactStringMatcher("()Ljava/nio/channels/FileChannel;"), false, ObligationPolicyDatabaseActionType.DEL,
                ObligationPolicyDatabaseEntryType.STRONG, javaIoInputStreamObligation));


        // Database obligation types
        Obligation connection = database.getFactory().addObligation("java.sql.Connection");
        Obligation statement = database.getFactory().addObligation("java.sql.Statement");
        Obligation resultSet = database.getFactory().addObligation("java.sql.ResultSet");

        // Add factory method entries for database obligation types
        database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.DriverManager")),
                new ExactStringMatcher("getConnection"), new RegexStringMatcher("^.*\\)Ljava/sql/Connection;$"), false,
                ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, connection));
View Full Code Here

    /**
     * General method for adding entries for File
     * InputStream/OutputStream/Reader/Writer classes.
     */
    private void addFileStreamEntries(String kind) {
        Obligation obligation = database.getFactory().addObligation("java.io." + kind);
        database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.io.File" + kind)),
                new ExactStringMatcher("<init>"), new RegexStringMatcher(".*"), false, ObligationPolicyDatabaseActionType.ADD,
                ObligationPolicyDatabaseEntryType.STRONG, obligation));
        database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.io." + kind)),
                new ExactStringMatcher("close"), new ExactStringMatcher("()V"), false, ObligationPolicyDatabaseActionType.DEL,
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ba.obl.Obligation

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.