8000 [Question] Are heuristics used when calculating the preconditions of functions? · Issue #1901 · facebook/infer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Question] Are heuristics used when calculating the preconditions of functions? #1901

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

Open
sujin0529 opened this issue Apr 29, 2025 · 0 comments

Comments

@sujin0529
Copy link
import java.lang.IllegalArgumentException;

class Obj {
        Object x;

        public Object getX() {
                return null;
        }
}

public class Main {
        public int g(int j) {
                if (j >= 10) {
                        return j + 1;
                }
                else if (j >= 5) {
                        return j;
                }
                else {
                        return 0;
                }
        }

        public int f(int i) {
                int j = g(i + 1);

                if (j == 0) {
                        throw new IllegalArgumentException();
                }
                else if (j == 6) {
                        return j;
                }


                Obj obj = new Obj();

                Object x = obj.getX();
                String str = x.toString(); // NPE
                return str.length();
        }
}

I analyzed this Java program using Infer's Pulse module.
While Pulse did not catch the NPE directly, I confirmed that it did detect the error as a latent issue.
During this process, I checked whether the precondition for function f was calculated correctly.
I found that the precondition related to the variable i in f was empty.
Because of this, I was wondering if there might be a heuristic that ignores the return value of functions that simply return a constant.
If I have misunderstood the relationship, I would appreciate it if you could let me know.

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

1 participant
0