Java中有效的@SuppressWarnings警告名称列表是什么?

在@SuppressWarnings("")中位于("")之间的位。


当前回答

如果你在使用SonarLint, 尝试上面的方法或类的整个鱿鱼串: @SuppressWarnings(“乌贼:S1172”)

其他回答

这似乎是一个更完整的列表,在那里我发现了一些特定于Android-Studio的警告,我在其他地方找不到(例如SynchronizeOnNonFinalField)

https://jazzy.id.au/2008/10/30/list_of_suppresswarnings_arguments.html

哦,现在SO的指导方针与SO的限制相反。 一方面,我应该复制列表,而不是只提供链接。 但另一方面,这将超过允许的最大字符数。所以让我们希望这个链接不会断裂。

如果你在使用SonarLint, 尝试上面的方法或类的整个鱿鱼串: @SuppressWarnings(“乌贼:S1172”)

该列表是特定于编译器的。但是下面是Eclipse支持的值:

allDeprecation deprecation even inside deprecated code allJavadoc invalid or missing javadoc assertIdentifier occurrence of assert used as identifier boxing autoboxing conversion charConcat when a char array is used in a string concatenation without being converted explicitly to a string conditionAssign possible accidental boolean assignment constructorName method with constructor name dep-ann missing @Deprecated annotation deprecation usage of deprecated type or member outside deprecated code discouraged use of types matching a discouraged access rule emptyBlock undocumented empty block enumSwitch, incomplete-switch incomplete enum switch fallthrough possible fall-through case fieldHiding field hiding another variable finalBound type parameter with final bound finally finally block not completing normally forbidden use of types matching a forbidden access rule hiding macro for fieldHiding, localHiding, typeHiding and maskedCatchBlock indirectStatic indirect reference to static member intfAnnotation annotation type used as super interface intfNonInherited interface non-inherited method compatibility javadoc invalid javadoc localHiding local variable hiding another variable maskedCatchBlocks hidden catch block nls non-nls string literals (lacking of tags //$NON-NLS-) noEffectAssign assignment with no effect null potential missing or redundant null check nullDereference missing null check over-ann missing @Override annotation paramAssign assignment to a parameter pkgDefaultMethod attempt to override package-default method raw usage a of raw type (instead of a parametrized type) semicolon unnecessary semicolon or empty statement serial missing serialVersionUID specialParamHiding constructor or setter parameter hiding another field static-access macro for indirectStatic and staticReceiver staticReceiver if a non static receiver is used to get a static field or call a static method super overriding a method without making a super invocation suppress enable @SuppressWarnings syntheticAccess, synthetic-access when performing synthetic access for innerclass tasks enable support for tasks tags in source code typeHiding type parameter hiding another type unchecked unchecked type operation unnecessaryElse unnecessary else clause unqualified-field-access, unqualifiedField unqualified reference to field unused macro for unusedArgument, unusedImport, unusedLabel, unusedLocal, unusedPrivate and unusedThrown unusedArgument unused method argument unusedImport unused import reference unusedLabel unused label unusedLocal unused local variable unusedPrivate unused private member declaration unusedThrown unused declared thrown exception uselessTypeCheck unnecessary cast/instanceof operation varargsCast varargs argument need explicit cast warningToken unhandled warning token in @SuppressWarnings

Sun JDK(1.6)支持的警告列表更短:

deprecation Check for use of depreciated items. unchecked Give more detail for unchecked conversion warnings that are mandated by the Java Language Specification. serial Warn about missing serialVersionUID definitions on serializable classes. finally Warn about finally clauses that cannot complete normally. fallthrough Check switch blocks for fall-through cases and provide a warning message for any that are found. path Check for a nonexistent path in environment paths (such as classpath).

最新的mac版javac(1.6.0_13)支持以下警告

所有 投 弃用 divzero 空 无节制的 fallthrough 路径 串行 最后 覆盖

允许所有值(未识别的值将被忽略)。已识别的列表是特定于编译器的。

在Java教程中,未选中和弃用被列为Java语言规范要求的两个警告,因此,它们对所有编译器都有效:

每个编译器警告都属于一个类别。Java语言规范列出了两个类别:弃用和未检查。

Java语言规范中定义它们的特定部分在不同版本之间是不一致的。在Java SE 8规范中,未选中和弃用被列为9.6.4.5节中的编译器警告。@SuppressWarnings和9.6.4.6 @Deprecated。

对于Sun的编译器,运行javac -X会给出该版本所能识别的所有值的列表。对于1.5.0_17,列表如下:

所有 弃用 无节制的 fallthrough 路径 串行 最后

我注意到IntelliJ中可以自动生成noinspection

确保你在声明之前没有计划@SuppressWarninigs 现在你可以自动生成特定的//noinspection,点击Alt+Enter当你有警告选择,然后使用右箭头键看到Suppress for…选项

当我想要压制来自IntelliJ的“switch有太少case标签”警告时,就结束在这里。我没有找到IntelliJ的@SuppressWarning支持的完整列表,但//noinspection为我做到了这一点。