Java中有效的@SuppressWarnings警告名称列表是什么?
在@SuppressWarnings("")中位于("")之间的位。
Java中有效的@SuppressWarnings警告名称列表是什么?
在@SuppressWarnings("")中位于("")之间的位。
当前回答
我只想补充一点,在https://gist.github.com/vegaasen/157fbc6dce8545b7f12c上有一个IntelliJ抑制参数的主列表
它看起来相当全面。部分:
Warning Description - Warning Name
"Magic character" MagicCharacter
"Magic number" MagicNumber
'Comparator.compare()' method does not use parameter ComparatorMethodParameterNotUsed
'Connection.prepare*()' call with non-constant string JDBCPrepareStatementWithNonConstantString
'Iterator.hasNext()' which calls 'next()' IteratorHasNextCallsIteratorNext
'Iterator.next()' which can't throw 'NoSuchElementException' IteratorNextCanNotThrowNoSuchElementException
'Statement.execute()' call with non-constant string JDBCExecuteWithNonConstantString
'String.equals("")' StringEqualsEmptyString
'StringBuffer' may be 'StringBuilder' (JDK 5.0 only) StringBufferMayBeStringBuilder
'StringBuffer.toString()' in concatenation StringBufferToStringInConcatenation
'assert' statement AssertStatement
'assertEquals()' between objects of inconvertible types AssertEqualsBetweenInconvertibleTypes
'await()' not in loop AwaitNotInLoop
'await()' without corresponding 'signal()' AwaitWithoutCorrespondingSignal
'break' statement BreakStatement
'break' statement with label BreakStatementWithLabel
'catch' generic class CatchGenericClass
'clone()' does not call 'super.clone()' CloneDoesntCallSuperClone
其他回答
JSL 1.7
Oracle文档提到:
unchecked:未选中的警告由字符串“unchecked”标识。 deprecation:当使用了带有@Deprecated注解的类型、方法、字段或构造函数时(即被重写、调用或引用名称),Java编译器必须产生deprecation警告,除非:[…]在实体中使用@SuppressWarnings("deprecation")注释来抑制警告;或
然后解释了实现可以添加并记录它们自己的:
编译器供应商应该将他们支持的警告名称与这种注释类型结合起来记录。鼓励供应商合作,以确保相同的名称在多个编译器中工作。
这似乎是一个更完整的列表,在那里我发现了一些特定于Android-Studio的警告,我在其他地方找不到(例如SynchronizeOnNonFinalField)
https://jazzy.id.au/2008/10/30/list_of_suppresswarnings_arguments.html
哦,现在SO的指导方针与SO的限制相反。 一方面,我应该复制列表,而不是只提供链接。 但另一方面,这将超过允许的最大字符数。所以让我们希望这个链接不会断裂。
我最喜欢的是IntelliJ中的@SuppressWarnings(“WeakerAccess”),当它认为你应该使用一个比你正在使用的更弱的访问修饰符时,它不会抱怨。为了支持测试,我们必须对一些方法进行公共访问,而@VisibleForTesting注释并不能阻止警告。
埃塔: “匿名者”在@MattCampbell链接的页面上评论了以下非常有用的注释:
You shouldn't need to use this list for the purpose you are describing. IntelliJ will add those SuppressWarnings for you automatically if you ask it to. It has been capable of doing this for as many releases back as I remember. Just go to the location where you have the warning and type Alt-Enter (or select it in the Inspections list if you are seeing it there). When the menu comes up, showing the warning and offering to fix it for you (e.g. if the warning is "Method may be static" then "make static" is IntellJ's offer to fix it for you), instead of selecting "enter", just use the right arrow button to access the submenu, which will have options like "Edit inspection profile setting" and so forth. At the bottom of this list will be options like "Suppress all inspections for class", "Suppress for class", "Suppress for method", and occasionally "Suppress for statement". You probably want whichever one of these appears last on the list. Selecting one of these will add a @SuppressWarnings annotation (or comment in some cases) to your code suppressing the warning in question. You won't need to guess at which annotation to add, because IntelliJ will choose based on the warning you selected.
我只想补充一点,在https://gist.github.com/vegaasen/157fbc6dce8545b7f12c上有一个IntelliJ抑制参数的主列表
它看起来相当全面。部分:
Warning Description - Warning Name
"Magic character" MagicCharacter
"Magic number" MagicNumber
'Comparator.compare()' method does not use parameter ComparatorMethodParameterNotUsed
'Connection.prepare*()' call with non-constant string JDBCPrepareStatementWithNonConstantString
'Iterator.hasNext()' which calls 'next()' IteratorHasNextCallsIteratorNext
'Iterator.next()' which can't throw 'NoSuchElementException' IteratorNextCanNotThrowNoSuchElementException
'Statement.execute()' call with non-constant string JDBCExecuteWithNonConstantString
'String.equals("")' StringEqualsEmptyString
'StringBuffer' may be 'StringBuilder' (JDK 5.0 only) StringBufferMayBeStringBuilder
'StringBuffer.toString()' in concatenation StringBufferToStringInConcatenation
'assert' statement AssertStatement
'assertEquals()' between objects of inconvertible types AssertEqualsBetweenInconvertibleTypes
'await()' not in loop AwaitNotInLoop
'await()' without corresponding 'signal()' AwaitWithoutCorrespondingSignal
'break' statement BreakStatement
'break' statement with label BreakStatementWithLabel
'catch' generic class CatchGenericClass
'clone()' does not call 'super.clone()' CloneDoesntCallSuperClone
该列表是特定于编译器的。但是下面是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 路径 串行 最后 覆盖