False positive java:S2259: NullpointerException

The following stripped down code looks like a false positive:
grafik

(Problem in a.toAbsolutePath())

grafik

Raw code:

import org.apache.commons.lang3.Validate;
import java.nio.file.Path;
import java.nio.file.Paths;
import BaseException;

    private void x() {
        final var a = Paths.get("");
        try {
            y(a);
        } catch (final Exception e) {
            System.err.println(a.toAbsolutePath());
        }
    }

    private void y(final Path b) throws BaseException {
        Validate.notNull(b);
    }

My work-around is currently assert b != null; which removes the problem, but has the same effect for me. Changing Exception to BaseException would also remove it, but in this I need also to catch all Exceptions.

  • Community Edition
  • Version 9.5 (build 56709)

Best Regards,
Roland

Hey there.

I’ve moved your post to the section on reporting false-positives.

Please make sure you’ve included all information, including which product(s) you’re using and what version(s).