Turn on ArgumentSelectionDefectChecker and fix the issue
Details: https://errorprone.info/bugpattern/ArgumentSelectionDefectChecker
The following error is fixed:
error: [ArgumentSelectionDefectChecker]
The following arguments may have been swapped:
'Math.max(voteMin, blockAllowMin)' for formal parameter 'min',
'Math.min(voteMax, blockAllowMax)' for formal parameter 'max'.
Either add clarifying `/* paramName= */` comments, or swap the
arguments if that is what was intended
....
Did you mean
'permissionName, /* min= */Math.max(voteMin, blockAllowMin),
/* max= */Math.min(voteMax, blockAllowMax));'
or
'permissionName, Math.min(voteMax, blockAllowMax),
Math.max(voteMin, blockAllowMin));'
?
Change-Id: I8242c6dc243b21150e726421ce07cd8a49d6decd
diff --git a/java/com/google/gerrit/server/permissions/RefControl.java b/java/com/google/gerrit/server/permissions/RefControl.java
index 27e73f0..6b51335 100644
--- a/java/com/google/gerrit/server/permissions/RefControl.java
+++ b/java/com/google/gerrit/server/permissions/RefControl.java
@@ -364,7 +364,9 @@
}
return new PermissionRange(
- permissionName, Math.max(voteMin, blockAllowMin), Math.min(voteMax, blockAllowMax));
+ permissionName,
+ /* min= */ Math.max(voteMin, blockAllowMin),
+ /* max= */ Math.min(voteMax, blockAllowMax));
}
private boolean isBlocked(String permissionName, boolean isChangeOwner, boolean withForce) {
@@ -560,7 +562,8 @@
break;
case FORGE_COMMITTER:
pde.setAdvice(
- "You need 'Forge Committer' rights to push commits with another user as committer.");
+ "You need 'Forge Committer' rights to push commits with another user as"
+ + " committer.");
break;
case FORGE_SERVER:
pde.setAdvice(
diff --git a/tools/BUILD b/tools/BUILD
index a912279..632156b 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -83,7 +83,7 @@
"-Xep:AlwaysThrows:ERROR",
"-Xep:AmbiguousMethodReference:ERROR",
"-Xep:AnnotateFormatMethod:ERROR",
- # "-Xep:ArgumentSelectionDefectChecker:WARN",
+ "-Xep:ArgumentSelectionDefectChecker:ERROR",
"-Xep:ArrayAsKeyOfSetOrMap:ERROR",
"-Xep:ArrayEquals:ERROR",
"-Xep:ArrayFillIncompatibleType:ERROR",