Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java plugin 3.8 - S2583 false positive

Tags:

sonarqube

I think we found a false positive:

private static void copy(File from, File to) throws FileNotFoundException, IOException {
    FileChannel src = null;
    FileChannel dst = null;
    try {
        src = new FileInputStream(from).getChannel();
        dst = new FileOutputStream(to).getChannel();
        dst.transferFrom(src, 0, src.size());
    } finally {
        if (src != null) {

Change this condition so that it does not always evaluate to "true"

or do I miss anything? another example:

        if (lastUpdate == null|| lastUpdate != null && lastUpdate.before(new Date(System.currentTimeMillis() - 900000)))
like image 784
Roman Pickl Avatar asked Apr 30 '26 23:04

Roman Pickl


1 Answers

You are actually asking question for two different cases :

  1. You are hitting a known limitation https://jira.sonarsource.com/browse/SONARJAVA-1295 we plan to fix this (hard) one in the next release of java plugin.

  2. This one is actually not a false positive at all ! :) if your variable lastUpdate is null then the condition is true without evaluating the right hand side of the || and if it is false, then lastUpdate != null will always evaluate to true so you can actually remove it.

like image 93
benzonico Avatar answered May 05 '26 10:05

benzonico



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!