RFR: 8263514: Minor issue in JavacFileManager.SortFiles.REVERSE

Aleksey Shipilev shade at openjdk.java.net
Mon Mar 15 17:41:10 UTC 2021


On Mon, 15 Mar 2021 17:22:12 GMT, Vicente Romero <vromero at openjdk.org> 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


More information about the compiler-dev mailing list