SonarCloud reports the problem in JavacFileManager.SortFiles.REVERSE definition:
Neither "Math.abs" nor negation should be used on numbers that could be "MIN_VALUE" REVERSE { @Override public int compare(Path f1, Path f2) { return -f1.getFileName().compareTo(f2.getFileName()); } } Since `compareTo` can technically return `MIN_VALUE`, we cannot simply negate it. Luckily, we can just swap the `f1` and `f2` comparison order to achieve the same effect without exposing us to this corner case. ------------- Commit messages: - 8263514: Minor issue in JavacFileManager.SortFiles.REVERSE Changes: https://git.openjdk.java.net/jdk/pull/2970/files Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=2970&range=00 Issue: https://bugs.openjdk.java.net/browse/JDK-8263514 Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod Patch: https://git.openjdk.java.net/jdk/pull/2970.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/2970/head:pull/2970 PR: https://git.openjdk.java.net/jdk/pull/2970 |
On Fri, 12 Mar 2021 13:52:51 GMT, Aleksey Shipilev <[hidden email]> wrote:
> SonarCloud reports the problem in JavacFileManager.SortFiles.REVERSE definition: > Neither "Math.abs" nor negation should be used on numbers that could be "MIN_VALUE" > > REVERSE { > @Override > public int compare(Path f1, Path f2) { > return -f1.getFileName().compareTo(f2.getFileName()); > } > } > > Since `compareTo` can technically return `MIN_VALUE`, we cannot simply negate it. Luckily, we can just swap the `f1` and `f2` comparison order to achieve the same effect without exposing us to this corner case. looks good ------------- Marked as reviewed by vromero (Reviewer). PR: https://git.openjdk.java.net/jdk/pull/2970 |
On Mon, 15 Mar 2021 17:22:12 GMT, Vicente Romero <[hidden email]> wrote:
>> SonarCloud reports the problem in JavacFileManager.SortFiles.REVERSE definition: >> Neither "Math.abs" nor negation should be used on numbers that could be "MIN_VALUE" >> >> REVERSE { >> @Override >> public int compare(Path f1, Path f2) { >> return -f1.getFileName().compareTo(f2.getFileName()); >> } >> } >> >> Since `compareTo` can technically return `MIN_VALUE`, we cannot simply negate it. Luckily, we can just swap the `f1` and `f2` comparison order to achieve the same effect without exposing us to this corner case. > > looks good Thanks! ------------- PR: https://git.openjdk.java.net/jdk/pull/2970 |
In reply to this post by Aleksey Shipilev-5
On Fri, 12 Mar 2021 13:52:51 GMT, Aleksey Shipilev <[hidden email]> wrote:
> SonarCloud reports the problem in JavacFileManager.SortFiles.REVERSE definition: > Neither "Math.abs" nor negation should be used on numbers that could be "MIN_VALUE" > > REVERSE { > @Override > public int compare(Path f1, Path f2) { > return -f1.getFileName().compareTo(f2.getFileName()); > } > } > > Since `compareTo` can technically return `MIN_VALUE`, we cannot simply negate it. Luckily, we can just swap the `f1` and `f2` comparison order to achieve the same effect without exposing us to this corner case. This pull request has now been integrated. Changeset: 5ab52448 Author: Aleksey Shipilev <[hidden email]> URL: https://git.openjdk.java.net/jdk/commit/5ab52448 Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod 8263514: Minor issue in JavacFileManager.SortFiles.REVERSE Reviewed-by: vromero ------------- PR: https://git.openjdk.java.net/jdk/pull/2970 |
Free forum by Nabble | Edit this page |