mag*_*way 5 java intellij-idea sonarqube sonarlint sonarlint-intellij
如果我们有代码:
@Contract("null, _, _ -> fail")
static void ifNull(Object object, ErrorType errorType, Object... args) throws ServiceException {
if (object == null) {
ExceptionFactory.throwServiceException(errorType, args);
}
}
Run Code Online (Sandbox Code Playgroud)
和
private boolean checkSeqValue(Sequence sequence, @Nonnull Number value) {
...
}
Run Code Online (Sandbox Code Playgroud)
和某处:
ifNull(value, ErrorType.NOT_FOUND, "Value for a sequence", "name = " + seqName);
if (checkSeqValue(sequence, value)) {
result = value;
}
Run Code Online (Sandbox Code Playgroud)
然后 SonarLint 插件显示了一个严重错误:
鱿鱼:S2637“@NonNull”值不应设置为空
对于此调用的 checkSeqValue 参数 2 已标记javax.annotation.Nonnull
但传递了 null
直接检查:
if (value == null) {
throw new ServiceException();
}
if (!isNeedCheck || checkSeqValue(sequence, value)) {
result = value;
}
Run Code Online (Sandbox Code Playgroud)
不会给出任何声纳错误。
有人知道如何让声纳考虑@Contract注释吗?
SonarLint 插件版本 3.3.0.2482
声纳Qube 6.0
Intellij理念2018.1.1
多谢
归档时间: |
|
查看次数: |
363 次 |
最近记录: |