当前位置: 首页>>代码示例>>Java>>正文


Java WarningPropertySet类代码示例

本文整理汇总了Java中edu.umd.cs.findbugs.props.WarningPropertySet的典型用法代码示例。如果您正苦于以下问题:Java WarningPropertySet类的具体用法?Java WarningPropertySet怎么用?Java WarningPropertySet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WarningPropertySet类属于edu.umd.cs.findbugs.props包,在下文中一共展示了WarningPropertySet类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reportNullDeref

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
private void reportNullDeref(WarningPropertySet<WarningProperty> propertySet, Location location, String type, int priority,
        BugAnnotation cause, @CheckForNull BugAnnotation variable) {

    BugInstance bugInstance = new BugInstance(this, type, priority).addClassAndMethod(classContext.getJavaClass(), method);
    bugInstance.add(cause);
    if (variable != null)
        bugInstance.add(variable);
    else
        bugInstance.add(new LocalVariableAnnotation("?", -1, -1));
    bugInstance.addSourceLine(classContext, method, location).describe("SOURCE_LINE_DEREF");

    if (FindBugsAnalysisFeatures.isRelaxedMode()) {
        WarningPropertyUtil.addPropertiesForDataMining(propertySet, classContext, method, location);
    }
    addPropertiesForDereferenceLocations(propertySet, Collections.singleton(location));

    propertySet.decorateBugInstance(bugInstance);

    bugReporter.reportBug(bugInstance);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:21,代码来源:NoiseNullDeref.java

示例2: isDuplicated

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
/**
 * @param propertySet
 * @param pc
 * @param isConsistent
 * @return
 */
public boolean isDuplicated(WarningPropertySet<WarningProperty> propertySet, int pc, boolean isConsistent) {
    boolean duplicated = false;
    if (!isConsistent) {
        if (propertySet.containsProperty(NullDerefProperty.DEREFS_ARE_CLONED))
            duplicated = true;

        else
            try {
                CFG cfg = classContext.getCFG(method);
                if (cfg.getLocationsContainingInstructionWithOffset(pc).size() > 1) {
                    propertySet.addProperty(NullDerefProperty.DEREFS_ARE_INLINED_FINALLY_BLOCKS);
                    duplicated = true;
                }
            } catch (CFGBuilderException e) {
                AnalysisContext.logError("Error while analyzing " + classContext.getFullyQualifiedMethodName(method), e);
            }
    }
    return duplicated;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:26,代码来源:FindNullDeref.java

示例3: reportNullDeref

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
private void reportNullDeref(WarningPropertySet<WarningProperty> propertySet, Location location, String type, int priority,
        @CheckForNull
        BugAnnotation variable) {

    BugInstance bugInstance = new BugInstance(this, type, priority).addClassAndMethod(classContext.getJavaClass(), method);
    if (variable != null)
        bugInstance.add(variable);
    else
        bugInstance.add(new LocalVariableAnnotation("?", -1, -1));
    bugInstance.addSourceLine(classContext, method, location).describe("SOURCE_LINE_DEREF");

    if (FindBugsAnalysisFeatures.isRelaxedMode()) {
        WarningPropertyUtil.addPropertiesForDataMining(propertySet, classContext, method, location);
    }
    addPropertiesForDereferenceLocations(propertySet, Collections.singleton(location), false);

    propertySet.decorateBugInstance(bugInstance);

    bugReporter.reportBug(bugInstance);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:21,代码来源:FindNullDeref.java

示例4: WarningWithProperties

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
WarningWithProperties(BugInstance warning, WarningPropertySet<WarningProperty> propertySet,
        SourceLineAnnotation sourceLine, Location location) {
    this.instance = warning;
    this.propertySet = propertySet;
    this.sourceLine = sourceLine;
    this.location = location;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:8,代码来源:FindRefComparison.java

示例5: addPropertiesForDereferenceLocations

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
/**
 * @param propertySet
 * @param derefLocationSet
 */
private void addPropertiesForDereferenceLocations(WarningPropertySet<WarningProperty> propertySet,
        Collection<Location> derefLocationSet) {
    boolean derefOutsideCatchBlock = false;
    boolean allDerefsAtDoomedLocations = true;
    for (Location loc : derefLocationSet) {
        if (!inCatchNullBlock(loc))
            derefOutsideCatchBlock = true;

        if (!isDoomed(loc))
            allDerefsAtDoomedLocations = false;
    }

    if (allDerefsAtDoomedLocations) {
        // Add a WarningProperty
        propertySet.addProperty(DoomedCodeWarningProperty.DOOMED_CODE);
    }
    boolean uniqueDereferenceLocations = uniqueLocations(derefLocationSet);

    if (!derefOutsideCatchBlock) {
        if (!uniqueDereferenceLocations || skipIfInsideCatchNull())
            propertySet.addProperty(GeneralWarningProperty.FALSE_POSITIVE);
        else
            propertySet.addProperty(NullDerefProperty.DEREFS_IN_CATCH_BLOCKS);
    }
    if (!uniqueDereferenceLocations)
        // Add a WarningProperty
        propertySet.addProperty(NullDerefProperty.DEREFS_ARE_CLONED);

    addPropertiesForMethodContainingWarning(propertySet);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:35,代码来源:NoiseNullDeref.java

示例6: addPropertiesForMethodContainingWarning

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
/**
 * @param propertySet
 * @param xMethod
 */
private void addPropertiesForMethodContainingWarning(WarningPropertySet<WarningProperty> propertySet) {
    XMethod xMethod = XFactory.createXMethod(classContext.getJavaClass(), method);

    boolean uncallable = !AnalysisContext.currentXFactory().isCalledDirectlyOrIndirectly(xMethod) && xMethod.isPrivate();

    if (uncallable)
        propertySet.addProperty(GeneralWarningProperty.IN_UNCALLABLE_METHOD);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:13,代码来源:NoiseNullDeref.java

示例7: checkLocalVariableName

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
/**
 * Get the name of given local variable (if possible) and store it in the
 * HeuristicPropertySet.
 * 
 * @param lvt
 *            the LocalVariableTable
 * @param local
 *            index of the local
 * @param pc
 *            program counter value of the instruction
 */
private void checkLocalVariableName(LocalVariableTable lvt, int local, int pc,
        WarningPropertySet<DeadLocalStoreProperty> propertySet) {
    if (lvt != null) {
        LocalVariable lv = lvt.getLocalVariable(local, pc);
        if (lv != null) {
            String localName = lv.getName();
            propertySet.setProperty(DeadLocalStoreProperty.LOCAL_NAME, localName);
        }
    }

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:23,代码来源:FindDeadLocalStores.java

示例8: handleSuspiciousRefComparison

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
private void handleSuspiciousRefComparison(JavaClass jclass, Method method, MethodGen methodGen,
        List<WarningWithProperties> refComparisonList, Location location, String lhs, ReferenceType lhsType,
        ReferenceType rhsType) {
    XField xf = null;
    if (lhsType instanceof FinalConstant)
        xf = ((FinalConstant) lhsType).getXField();
    else if (rhsType instanceof FinalConstant)
        xf = ((FinalConstant) rhsType).getXField();
    String sourceFile = jclass.getSourceFileName();
    String bugPattern = "RC_REF_COMPARISON";
    int priority = Priorities.HIGH_PRIORITY;
    if (lhs.equals("java.lang.Boolean")) {
        bugPattern = "RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN";
        priority = Priorities.NORMAL_PRIORITY;
    } else if (xf != null && xf.isStatic() && xf.isFinal()) {
        bugPattern = "RC_REF_COMPARISON_BAD_PRACTICE";
        if (xf.isPublic() || !methodGen.isPublic())
            priority = Priorities.NORMAL_PRIORITY;
    }
    BugInstance instance = new BugInstance(this, bugPattern, priority).addClassAndMethod(methodGen, sourceFile)
            .addType("L" + lhs.replace('.', '/') + ";").describe(TypeAnnotation.FOUND_ROLE);
    if (xf != null)
        instance.addField(xf).describe(FieldAnnotation.LOADED_FROM_ROLE);
    else
        instance.addSomeSourceForTopTwoStackValues(classContext, method, location);
    SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen,
            sourceFile, location.getHandle());
    if (sourceLineAnnotation != null)
        refComparisonList.add(new WarningWithProperties(instance, new WarningPropertySet<WarningProperty>(),
                sourceLineAnnotation, location));
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:32,代码来源:FindRefComparison.java

示例9: checkLocalVariableName

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
/**
 * Get the name of given local variable (if possible) and store it in the
 * HeuristicPropertySet.
 *
 * @param lvt
 *            the LocalVariableTable
 * @param local
 *            index of the local
 * @param pc
 *            program counter value of the instruction
 */
private void checkLocalVariableName(LocalVariableTable lvt, int local, int pc,
        WarningPropertySet<DeadLocalStoreProperty> propertySet) {
    if (lvt != null) {
        LocalVariable lv = lvt.getLocalVariable(local, pc);
        if (lv != null) {
            String localName = lv.getName();
            propertySet.setProperty(DeadLocalStoreProperty.LOCAL_NAME, localName);
        }
    }

}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:23,代码来源:FindDeadLocalStores.java

示例10: handleStringComparison

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
private void handleStringComparison(JavaClass jclass, Method method, MethodGen methodGen,
        RefComparisonTypeFrameModelingVisitor visitor, List<WarningWithProperties> stringComparisonList, Location location,
        Type lhsType, Type rhsType) {
    if (DEBUG) {
        System.out.println("String/String comparison at " + location.getHandle());
    }

    // Compute the priority:
    // - two static strings => do not report
    // - dynamic string and anything => high
    // - static string and unknown => medium
    // - all other cases => low
    // System.out.println("Compare " + lhsType + " == " + rhsType);
    byte type1 = lhsType.getType();
    byte type2 = rhsType.getType();

    String bugPattern = "ES_COMPARING_STRINGS_WITH_EQ";
    // T1 T2 result
    // S S no-op
    // D ? high
    // ? D high
    // S ? normal
    // ? S normal
    WarningPropertySet<WarningProperty> propertySet = new WarningPropertySet<WarningProperty>();
    if (type1 == T_STATIC_STRING && type2 == T_STATIC_STRING) {
        propertySet.addProperty(RefComparisonWarningProperty.COMPARE_STATIC_STRINGS);
    } else if (type1 == T_DYNAMIC_STRING || type2 == T_DYNAMIC_STRING) {
        propertySet.addProperty(RefComparisonWarningProperty.DYNAMIC_AND_UNKNOWN);
    } else if (type2 == T_PARAMETER_STRING || type1 == T_PARAMETER_STRING) {
        bugPattern = "ES_COMPARING_PARAMETER_STRING_WITH_EQ";
        if (methodGen.isPublic() || methodGen.isProtected()) {
            propertySet.addProperty(RefComparisonWarningProperty.STRING_PARAMETER_IN_PUBLIC_METHOD);
        } else {
            propertySet.addProperty(RefComparisonWarningProperty.STRING_PARAMETER);
        }
    } else if (type1 == T_STATIC_STRING || type2 == T_STATIC_STRING) {
        if (lhsType instanceof EmptyStringType || rhsType instanceof EmptyStringType)
            propertySet.addProperty(RefComparisonWarningProperty.EMPTY_AND_UNKNOWN);
        else
            propertySet.addProperty(RefComparisonWarningProperty.STATIC_AND_UNKNOWN);
    } else if (visitor.sawStringIntern()) {
        propertySet.addProperty(RefComparisonWarningProperty.SAW_INTERN);
    }

    String sourceFile = jclass.getSourceFileName();
    BugInstance instance = new BugInstance(this, bugPattern, BASE_ES_PRIORITY).addClassAndMethod(methodGen, sourceFile)
            .addType("Ljava/lang/String;").describe(TypeAnnotation.FOUND_ROLE).addSomeSourceForTopTwoStackValues(classContext, method, location);
    SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen,
            sourceFile, location.getHandle());
    if (sourceLineAnnotation != null) {
        WarningWithProperties warn = new WarningWithProperties(instance, propertySet, sourceLineAnnotation, location);
        stringComparisonList.add(warn);
    }

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:56,代码来源:FindRefComparison.java

示例11: decorateWarning

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
private void decorateWarning(Location location, WarningPropertySet<WarningProperty> propertySet, BugInstance warning) {
    if (FindBugsAnalysisFeatures.isRelaxedMode()) {
        WarningPropertyUtil.addPropertiesForDataMining(propertySet, classContext, method, location);
    }
    propertySet.decorateBugInstance(warning);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:7,代码来源:FindNullDeref.java

示例12: addPropertiesForDereferenceLocations

import edu.umd.cs.findbugs.props.WarningPropertySet; //导入依赖的package包/类
/**
 * @param propertySet
 * @param derefLocationSet
 * @param isConsistent
 *            TODO
 */
private void addPropertiesForDereferenceLocations(WarningPropertySet<WarningProperty> propertySet,
        Collection<Location> derefLocationSet, boolean isConsistent) {
    boolean derefOutsideCatchBlock = false;

    boolean derefOutsideCatchNullBlock = false;
    boolean allDerefsAtDoomedLocations = true;

    for (Location loc : derefLocationSet) {
        if (!inExplictCatchNullBlock(loc)) {
            derefOutsideCatchNullBlock = true;
            if (!inIndirectCatchNullBlock(loc))
                derefOutsideCatchBlock = true;
        }

        if (!isDoomed(loc))
            allDerefsAtDoomedLocations = false;
    }

    if (!derefOutsideCatchNullBlock) {
        propertySet.addProperty(GeneralWarningProperty.FALSE_POSITIVE);
        return;
    }

    if (allDerefsAtDoomedLocations) {
        // Add a WarningProperty
        propertySet.addProperty(DoomedCodeWarningProperty.DOOMED_CODE);
    }
    boolean uniqueDereferenceLocations = uniqueLocations(derefLocationSet);

    if (!derefOutsideCatchBlock) {
        if (!uniqueDereferenceLocations || skipIfInsideCatchNull())
            propertySet.addProperty(GeneralWarningProperty.FALSE_POSITIVE);
        else
            propertySet.addProperty(NullDerefProperty.DEREFS_IN_CATCH_BLOCKS);
    }
    if (!isConsistent && !uniqueDereferenceLocations)
        // Add a WarningProperty
        propertySet.addProperty(NullDerefProperty.DEREFS_ARE_CLONED);

    addPropertiesForMethodContainingWarning(propertySet);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:48,代码来源:FindNullDeref.java


注:本文中的edu.umd.cs.findbugs.props.WarningPropertySet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。