fb-contrib icon indicating copy to clipboard operation
fb-contrib copied to clipboard

false-positive? in `EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS`

Open Vampire opened this issue 1 month ago • 1 comments

With this code:

    public void foo() throws Exception {
    }

    public void bar() {
        java.util.Collections.emptyList().forEach(foo -> {
            try {
                foo();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    }

    public void baz() {
        java.util.Collections.emptyList().forEach(foo -> bam());
    }

    public void bam() {
        try {
            foo();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

the pattern is happy with bar() as the forEach must not throw a checked exception.

But it complains about bam (even if it is private static) where the try-catch is moved to an own method for better readability / maintainability.

Maybe the pattern can be made not detected if used like this in the same class?

Vampire avatar Dec 01 '25 14:12 Vampire

it's likely that lambda's were synthetic, and ignored, which wasn't a thing at the time. i'll check

mebigfatguy avatar Dec 01 '25 17:12 mebigfatguy