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

JavaEE stub not working for Resource Leak Checker #5472

Closed
msridhar opened this issue Dec 27, 2022 · 3 comments
Closed

JavaEE stub not working for Resource Leak Checker #5472

msridhar opened this issue Dec 27, 2022 · 3 comments
Assignees

Comments

@msridhar
Copy link
Contributor

Input:

class Test {
    static void foo(javax.servlet.ServletResponse s) throws java.io.IOException {
	s.getWriter();
    }
}

In JavaEE.astub we have marked the getWriter() method as @NotOwning:

https://github.com/typetools/checker-framework/blob/master/checker/src/main/java/org/checkerframework/checker/mustcall/JavaEE.astub#L17-L17

And yet, compiling the above gives an error with 3.28.0:

$ ./checker-framework-3.28.0/checker/bin/javac -processor resourceleak -cp /path/to/javax.servlet-api-3.1.0.jar:. Test.java
Test.java:4: error: [required.method.not.called] @MustCall method close may not have been invoked on temp-var-1 or any of its aliases.
	s.getWriter();
	           ^
  The type of object is: java.io.PrintWriter.
  Reason for going out of scope: regular method exit
1 error

I used the following javax.servlet-api-3.1.0.jar in the classpath:

https://repo1.maven.org/maven2/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar

@kelloggm
Copy link
Contributor

There is a serious problem in AnnotatedTypeFactory#getDeclAnnotation, which (when called from MustCallConsistencyAnalyzer) is not producing the @NotOwning annotation from the stub file, contrary to its specification (checked via print-line debugging). I don't know what the cause of that problem is, but we should investigate further.

In the mean time, I'll open a PR that works around this problem in the short term by changing the @NotOwning annotations to @MustCall({}), delegating the work to the Must Call Checker.

@msridhar
Copy link
Contributor Author

There is a serious problem in AnnotatedTypeFactory#getDeclAnnotation, which (when called from MustCallConsistencyAnalyzer) is not producing the @NotOwning annotation from the stub file, contrary to its specification (checked via print-line debugging). I don't know what the cause of that problem is, but we should investigate further.

In the mean time, I'll open a PR that works around this problem in the short term by changing the @NotOwning annotations to @MustCall({}), delegating the work to the Must Call Checker.

Is there any chance we could fix the AnnotatedTypeFactory#getDeclAnnotation method instead of doing a workaround? My concern is that I'm not really sure where else the RLC is currently relying on reading annotations from stub files and it is not working. It's possible you were planning to do that and the workaround is just a super-fast temporary fix.

@kelloggm
Copy link
Contributor

kelloggm commented Dec 27, 2022 via email

@kelloggm kelloggm mentioned this issue Dec 27, 2022
wmdietl pushed a commit to eisop/checker-framework that referenced this issue Feb 8, 2023
The underlying problem is that `@NotOwning` and `@Owning` are owned by the Must Call Checker, not the Resource Leak Checker. So, only the Must Call Checker has access to such annotations if (and only if) they were written in stub files. I fixed both the problem described in typetools#5472 and all other uses of `getDeclAnnotation(elt)` involving `Owning` or `NotOwning` in the consistency analyzer.
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

2 participants