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")注释来抑制警告;或
然后解释了实现可以添加并记录它们自己的:
编译器供应商应该将他们支持的警告名称与这种注释类型结合起来记录。鼓励供应商合作,以确保相同的名称在多个编译器中工作。
如果你在使用SonarLint, 尝试上面的方法或类的整个鱿鱼串: @SuppressWarnings(“乌贼:S1172”)
这取决于您的IDE或编译器。
下面是Eclipse Galileo的列表:
all to suppress all warnings boxing to suppress warnings relative to boxing/unboxing operations cast to suppress warnings relative to cast operations dep-ann to suppress warnings relative to deprecated annotation deprecation to suppress warnings relative to deprecation fallthrough to suppress warnings relative to missing breaks in switch statements finally to suppress warnings relative to finally block that don’t return hiding to suppress warnings relative to locals that hide variable incomplete-switch to suppress warnings relative to missing entries in a switch statement (enum case) nls to suppress warnings relative to non-nls string literals null to suppress warnings relative to null analysis restriction to suppress warnings relative to usage of discouraged or forbidden references serial to suppress warnings relative to missing serialVersionUID field for a serializable class static-access to suppress warnings relative to incorrect static access synthetic-access to suppress warnings relative to unoptimized access from inner classes unchecked to suppress warnings relative to unchecked operations unqualified-field-access to suppress warnings relative to field access unqualified unused to suppress warnings relative to unused code
Indigo列表增加了:
压制相对于Javadoc警告的警告 原始类型来抑制与原始类型使用相关的警告 static-用于抑制相对于可声明为静态的方法的警告的方法 Super来抑制相对于覆盖没有Super调用的方法的警告
朱诺的列表增加了:
资源来抑制与使用Closeable类型资源相关的警告 Sync-override在覆盖同步方法时,由于缺少同步而抑制警告
Kepler和Luna使用与Juno相同的令牌列表(list)。
其他的将是相似的,但有所不同。
我只想补充一点,在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
允许所有值(未识别的值将被忽略)。已识别的列表是特定于编译器的。
在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 路径 串行 最后