本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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));
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
示例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);
}