False positive on rule squid:2583 when using Optional, filter, if else if, and a get instruction

Hello,
I am using SonarQube Version 6.7.4 (build 38452), and found a false positive on rule squid:2583.
This happens when using java.util.Optional with filters, and I get the issue “Change this condition so that it does not always evaluate to “false”” on my “else if” condition.

Here is the minimal code sample I was able to reproduce the bug with :

package test;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.logging.Logger;

/**
 * Test S2583
 * 
 * @author vhemery
 */
public final class S2583FalsePositive {

    /**
     * Private constructor
     */
    private S2583FalsePositive() {
        // do nothing
    }

    /**
     * Test
     * 
     * @param string Hello!
     */
    public static void test(String string) {
        Predicate<String> startsWithH = s -> s.startsWith("H");
        Predicate<String> endsWithExcl = s -> s.endsWith("!");
        Optional<String> a = Optional.ofNullable(string).filter(startsWithH.or(endsWithExcl));
        if(a.filter(startsWithH).isPresent()) {
            Logger.getGlobal().info("Hello");
        } else if(a.filter(endsWithExcl).isPresent()) {
            Logger.getGlobal().info("ello!");
            /*
             * Comment a.get() to remove the false positive in the if above...
             */
            a.get();
        }
    }
}

The strangest part is that the false positive is not triggered when I remove the get instruction under the comment, whereas this should have no impact at all on the condition itself.

Hello @vhemery,
What version of SonarJava are you using ?
Have you tried analysing this code snippet with the very latest one ?
Alex.

I am using
SonarJava 5.4 (build 14284)

I haven’t tried with the latest one yet, since I don’t want to corrupt my working environment.

Test with a localhost latest sonar in progress…

OK. Just tested with the latest version and I can not reproduce this issue.
So this bug is definitely closed now.
Thank you.