Java 声纳不';不考虑合同注释
如果我们有代码:Java 声纳不';不考虑合同注释,java,intellij-idea,sonarqube,sonarlint,sonarlint-intellij,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); } } 及 在某处: if
@Contract("null, _, _ -> fail")
static void ifNull(Object object, ErrorType errorType, Object... args) throws ServiceException {
if (object == null) {
ExceptionFactory.throwServiceException(errorType, args);
}
}
及
在某处:
ifNull(value, ErrorType.NOT_FOUND, "Value for a sequence", "name = " + seqName);
if (checkSeqValue(sequence, value)) {
result = value;
}
然后SonarLint插件显示了一个关键错误:
squid:S2637“@NonNull”值不应设置为null
对于checkSeqValue,此调用的参数2标记为javax.annotation.Nonnull
但传递了null
直接检查:
if (value == null) {
throw new ServiceException();
}
if (!isNeedCheck || checkSeqValue(sequence, value)) {
result = value;
}
没有任何声纳错误
有人知道如何让sonar考虑@Contract annotation吗
SonarLint插件版本3.3.0.2482
声纳QUBE 6.0
Intellij idea 2018.1.1
非常感谢我也可以为sonarqube 7.1确认这一点。
if (value == null) {
throw new ServiceException();
}
if (!isNeedCheck || checkSeqValue(sequence, value)) {
result = value;
}