【发布时间】:2021-01-05 03:42:50
【问题描述】:
您好,我正在使用 sonarqube 分析我的代码,并遇到以下方法的错误
final Boolean active = this.fromApiJsonHelper.extractBooleanNamed(GroupingTypesApiConstants.activeParamName, element);
if (active != null) {
if (active.booleanValue()) {
final LocalDate joinedDate = this.fromApiJsonHelper.extractLocalDateNamed(
GroupingTypesApiConstants.activationDateParamName, element);
baseDataValidator.reset().parameter(GroupingTypesApiConstants.activationDateParamName).value(joinedDate).notNull();
} else {
// TODO - KW - not using config for now - just supporting move
// to pending or active out of box.
final boolean isPendingApprovalEnabled = true;
if (!isPendingApprovalEnabled) {
baseDataValidator.reset().parameter(GroupingTypesApiConstants.activeParamName)
.failWithCode(".pending.status.not.allowed");
}
}
} else {
baseDataValidator.reset().parameter(ClientApiConstants.activeParamName).value(active).trueOrFalseRequired(false);
}
sonarqube 说“在语句“if (!isPendingApprovalEnabled)”中更改此条件,使其不会总是评估为“false”
【问题讨论】:
-
该代码似乎作为占位符存在。您可以忽略该警告,因为它不是最终代码。
-
所以我改变了规则?并接受?
-
为什么要在代码库中放置从未被调用的代码?
-
我不知道具体的 SonarCube 规则,但您可以尝试将标志设为
private static final boolean字段。我已经多次将其用于条件编译。也许 SonarCube 会毫无征兆地接受这一点。
标签: java if-statement sonarqube