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

Infer: eradicate and try-catch #226

Open
pontusbostrom opened this issue Dec 29, 2015 · 4 comments
Open

Infer: eradicate and try-catch #226

pontusbostrom opened this issue Dec 29, 2015 · 4 comments

Comments

@pontusbostrom
Copy link

It seems that infer: eradicate treats catch-blocks as never executed, at least in some cases. Below is an example class that "infer -a eradicate" claims has no issues. If the assignment "path = null" is moved after the catch-block (or into the try-block) then the assignment "filePath = path" is (correctly) flagged as an error. Is this a bug in infer or an issue with models?

public class ExceptionTest {
    String filePath = "";
    public OutputStream returnStream(){
        File file = null;
        OutputStream stream = null;
        String path = null;
        try{
            file = File.createTempFile("tmp", "tmp");
            stream = new FileOutputStream(file);
            path = file.getAbsolutePath();
        }catch(IOException e) {
            path = null;
        }
        filePath = path;
        return stream;
    }
}
@cristianoc
Copy link
Contributor

Thanks for the report. It seems to be a library modelling issue, as calling a locally defined method declared as throwing IOException causes the expected error to be reported.
Stay tuned.

@cristianoc
Copy link
Contributor

Currently Infer does not analyze the jar of the standard library to get information on declared exceptions.
Turning to wishlist.

@pontusbostrom
Copy link
Author

Thank you for your reply, and good to know this is on the wishlist. As a workaround, I tried to add a model of the method with the correct throws clause. However, it seems that adding a model that throws exceptions doesn't help in this case. Is this also not supported yet?

@cristianoc
Copy link
Contributor

Eradicate uses a different modeling mechanism than the core Infer analysis, with tables for annotations instead of actual code, as the implementation of called methods is not used by Eradicate's analysis.
It would be easy to add tables for exceptions as well, as a temporary solution while the full solution is being developed.

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

No branches or pull requests

3 participants