Java Code Examples for edu.umd.cs.findbugs.Priorities#HIGH_PRIORITY
The following examples show how to use
edu.umd.cs.findbugs.Priorities#HIGH_PRIORITY .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DumbMethods.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
private void checkForCompatibleLongComparison(OpcodeStack.Item left, OpcodeStack.Item right) { if (left.getSpecialKind() == Item.RESULT_OF_I2L && right.getConstant() != null) { long value = ((Number) right.getConstant()).longValue(); if ((value > Integer.MAX_VALUE || value < Integer.MIN_VALUE)) { int priority = Priorities.HIGH_PRIORITY; if (value == Integer.MAX_VALUE + 1L || value == Integer.MIN_VALUE - 1L) { priority = Priorities.NORMAL_PRIORITY; } String stringValue = IntAnnotation.getShortInteger(value) + "L"; if (value == 0xffffffffL) { stringValue = "0xffffffffL"; } else if (value == 0x80000000L) { stringValue = "0x80000000L"; } accumulator.accumulateBug(new BugInstance(this, "INT_BAD_COMPARISON_WITH_INT_VALUE", priority).addClassAndMethod(this) .addString(stringValue).describe(StringAnnotation.STRING_NONSTRING_CONSTANT_ROLE) .addValueSource(left, this), this); } } }
Example 2
Source File: Noise.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
public int getPriority() { int hash = getHash(); if ((hash & 0x1ff0) == 0) { hash = hash & 0xf; if (hash < 1) { return Priorities.HIGH_PRIORITY; } else if (hash < 1 + 2) { return Priorities.NORMAL_PRIORITY; } else if (hash < 1 + 2 + 4) { return Priorities.LOW_PRIORITY; } else { return Priorities.IGNORE_PRIORITY; } } else { return Priorities.IGNORE_PRIORITY + 1; } }
Example 3
Source File: ProjectFilterSettings.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Convert an integer warning priority threshold value to a String. */ public static String getIntPriorityAsString(int prio) { String minPriority; switch (prio) { case Priorities.EXP_PRIORITY: minPriority = ProjectFilterSettings.EXPERIMENTAL_PRIORITY; break; case Priorities.LOW_PRIORITY: minPriority = ProjectFilterSettings.LOW_PRIORITY; break; case Priorities.NORMAL_PRIORITY: minPriority = ProjectFilterSettings.MEDIUM_PRIORITY; break; case Priorities.HIGH_PRIORITY: minPriority = ProjectFilterSettings.HIGH_PRIORITY; break; default: minPriority = ProjectFilterSettings.DEFAULT_PRIORITY; break; } return minPriority; }
Example 4
Source File: CrossSiteScripting.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private int taintPriority(OpcodeStack.Item writing) { if (writing == null) { return Priorities.NORMAL_PRIORITY; } XMethod method = writing.getReturnValueOf(); if (method != null && "getParameter".equals(method.getName()) && "javax.servlet.http.HttpServletRequest".equals(method.getClassName())) { return Priorities.HIGH_PRIORITY; } return Priorities.NORMAL_PRIORITY; }
Example 5
Source File: InitializeNonnullFieldsInConstructor.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void visit(Code code) { boolean interesting = Const.CONSTRUCTOR_NAME.equals(getMethodName()) || Const.STATIC_INITIALIZER_NAME.equals(getMethodName()); if (!interesting) { return; } secondaryConstructor = false; HashSet<XField> needToInitialize = getMethod().isStatic() ? nonnullStaticFields : nonnullFields; if (needToInitialize.isEmpty()) { return; } // initialize any variables we want to initialize for the method super.visit(code); // make callbacks to sawOpcode for all opcodes if (!secondaryConstructor && !initializedFields.containsAll(needToInitialize)) { int priority = Priorities.NORMAL_PRIORITY; if (needToInitialize.size() - initializedFields.size() == 1 && needToInitialize.size() > 1) { priority = Priorities.HIGH_PRIORITY; } for (XField f : needToInitialize) { if (initializedFields.contains(f)) { continue; } BugInstance b = new BugInstance(this, "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", priority) .addClassAndMethod(this).addField(f); bugReporter.reportBug(b); } } initializedFields.clear(); }
Example 6
Source File: FindRefComparison.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
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 ("java.lang.Boolean".equals(lhs)) { 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()); refComparisonList.add(new WarningWithProperties(instance, new WarningPropertySet<>(), sourceLineAnnotation, location)); }
Example 7
Source File: CollectorBugReporter.java From sputnik with Apache License 2.0 | 5 votes |
@NotNull private Severity convert(int priority) { switch (priority) { case Priorities.IGNORE_PRIORITY: return Severity.IGNORE; case Priorities.EXP_PRIORITY: case Priorities.LOW_PRIORITY: case Priorities.NORMAL_PRIORITY: return Severity.INFO; case Priorities.HIGH_PRIORITY: return Severity.WARNING; default: throw new IllegalArgumentException("Priority " + priority + " is not supported"); } }
Example 8
Source File: SynchronizingOnContentsOfFieldToProtectField.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { // System.out.println(state + " " + getPC() + " " + Const.getOpcodeName(seen)); if (countDown == 2 && seen == Const.GOTO) { CodeException tryBlock = getSurroundingTryBlock(getPC()); if (tryBlock != null && tryBlock.getEndPC() == getPC()) { pendingBug.lowerPriority(); } } if (countDown > 0) { countDown--; if (countDown == 0) { if (seen == Const.MONITOREXIT) { pendingBug.lowerPriority(); } bugReporter.reportBug(pendingBug); pendingBug = null; } } if (seen == Const.PUTFIELD) { if (syncField != null && getPrevOpcode(1) != Const.ALOAD_0 && syncField.equals(getXFieldOperand())) { OpcodeStack.Item value = stack.getStackItem(0); int priority = Priorities.HIGH_PRIORITY; if (value.isNull()) { priority = Priorities.NORMAL_PRIORITY; } pendingBug = new BugInstance(this, "ML_SYNC_ON_FIELD_TO_GUARD_CHANGING_THAT_FIELD", priority) .addClassAndMethod(this).addField(syncField).addSourceLine(this); countDown = 2; } } if (seen == Const.MONITOREXIT) { pendingBug = null; countDown = 0; } if (seen == Const.MONITORENTER) { syncField = null; } switch (state) { case 0: if (seen == Const.ALOAD_0) { state = 1; } break; case 1: if (seen == Const.GETFIELD) { state = 2; field = getXFieldOperand(); } else { state = 0; } break; case 2: if (seen == Const.DUP) { state = 3; } else { state = 0; } break; case 3: if (isRegisterStore()) { state = 4; } else { state = 0; } break; case 4: if (seen == Const.MONITORENTER) { state = 0; syncField = field; } else { state = 0; } break; default: break; } }
Example 9
Source File: DontIgnoreResultOfPutIfAbsent.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
private static int getPriorityForBeingMutable(Type type) { if (type instanceof ArrayType) { return HIGH_PRIORITY; } else if (type instanceof ObjectType) { UnreadFieldsData unreadFields = AnalysisContext.currentAnalysisContext().getUnreadFieldsData(); ClassDescriptor cd = DescriptorFactory.getClassDescriptor((ObjectType) type); @SlashedClassName String className = cd.getClassName(); if (immutableClassNames.contains(className)) { return Priorities.LOW_PRIORITY; } XClass xClass = AnalysisContext.currentXFactory().getXClass(cd); if (xClass == null) { return Priorities.IGNORE_PRIORITY; } ClassDescriptor superclassDescriptor = xClass.getSuperclassDescriptor(); if (superclassDescriptor != null) { @SlashedClassName String superClassName = superclassDescriptor.getClassName(); if ("java/lang/Enum".equals(superClassName)) { return Priorities.LOW_PRIORITY; } } boolean hasMutableField = false; boolean hasUpdates = false; for (XField f : xClass.getXFields()) { if (!f.isStatic()) { if (!f.isFinal() && !f.isSynthetic()) { hasMutableField = true; if (unreadFields.isWrittenOutsideOfInitialization(f)) { hasUpdates = true; } } String signature = f.getSignature(); if (signature.startsWith("Ljava/util/concurrent") || signature.startsWith("Ljava/lang/StringB") || signature.charAt(0) == '[' || signature.indexOf("Map") >= 0 || signature.indexOf("List") >= 0 || signature.indexOf("Set") >= 0) { hasMutableField = hasUpdates = true; } } } if (!hasMutableField && !xClass.isInterface() && !xClass.isAbstract()) { return Priorities.LOW_PRIORITY; } if (hasUpdates || className.startsWith("java/util") || className.indexOf("Map") >= 0 || className.indexOf("List") >= 0) { return Priorities.HIGH_PRIORITY; } return Priorities.NORMAL_PRIORITY; } else { return Priorities.IGNORE_PRIORITY; } }
Example 10
Source File: AbstractInjectionDetector.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | 3 votes |
/** * The default implementation of <code>getPriority()</code> can be overridden if the severity and the confidence for risk * is particular. * * By default, injection will be rated "High" if the complete link between source and sink is made. * If it is not the case but concatenation with external source is made, "Medium" is used. * * @param taint Detail about the state of the value passed (Cumulative information leading to the variable passed). * @return Priorities interface values from 1 to 5 (Enum-like interface) */ protected int getPriority(Taint taint) { if (taint.isTainted()) { return Priorities.HIGH_PRIORITY; } else if (!taint.isSafe()) { return Priorities.NORMAL_PRIORITY; } else { return Priorities.IGNORE_PRIORITY; } }