Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive with OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE #778

Open
victornoel opened this issue Oct 18, 2018 · 4 comments
Open

False positive with OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE #778

victornoel opened this issue Oct 18, 2018 · 4 comments

Comments

@victornoel
Copy link

The following code:

public class Test {
    public Test() {
        Optional.empty().orElseGet(
            () -> Optional.ofNullable(Test.class.getResourceAsStream("file"))
                .orElseThrow(() -> new IllegalArgumentException("invalid file file in classpath")));
    }
}

raises: Test.lambda$0() may fail to clean up java.io.InputStream [Of Concern(20), Normal confidence].

I think it shouldn't :)

@ThrawnCA
Copy link
Contributor

You're getting a resource as a stream. What code will close the stream?

@victornoel
Copy link
Author

@ThrawnCA yep, sorry, by making the example minimal I removed any reality to it :)

Here is an updated one:

public class Test {
    public Test() throws IllegalArgumentException, IOException {
        try (InputStream s =
            Optional.<InputStream>empty().orElseGet(() -> Optional.ofNullable(Test.class.getResourceAsStream("file"))
                .orElseThrow(() -> new IllegalArgumentException("invalid file file in classpath")))) {

        }
    }
}

@iloveeclipse
Copy link
Member

Code compiled with Java 11? If yes, known JDK bug.

@victornoel
Copy link
Author

@iloveeclipse no, it is with Java 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants