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

@CreatesMustCallFor create an obligation on exceptional successors #6221

Open
wants to merge 45 commits into
base: master
Choose a base branch
from

Conversation

Nargeshdb
Copy link
Contributor

Fix #6050.

@msridhar msridhar removed their request for review October 3, 2023 16:13
@msridhar
Copy link
Contributor

msridhar commented Oct 3, 2023

@Nargeshdb please request my review once you are done with your code cleanup here, thanks!

* The fully-qualified names of the exception types that are ignored by this checker when
* computing dataflow stores.
*/
protected static final Set<String> ignoredExceptionTypes =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a full review but a quick question. Does this need to respect the new setting around ignored exceptions that were added recently?

* The fully-qualified names of the exception types that are ignored by this checker when
* computing dataflow stores.
*/
protected static final Set<@CanonicalName String> ignoredExceptionTypes =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nargeshdb my question remains, shouldn't this set of exceptions be configurable using the same setting added in #6242?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relatedly, #6242 added a mechanism for matching all subtypes of an exception type in addition to matching by name. We should try to be as consistent as possible here and share code if possible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nargeshdb any thoughts on the above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already addressed your comment here. There is a method in this class like what we have here, but it's overridden in MustCallAnnotatedTypeFactory to match all subtypes of an exception type. Is there anything else that I missed regarding consistency with 6242?

Copy link
Contributor

@msridhar msridhar Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being unclear. #6242 added an option -AresourceLeakIgnoredExceptions to specify which exception types should be ignored by the RLC. This PR moves some of that logic to the Must Call Checker. And, as far as I can see, the method in this class, MustCallAnalysis, ignored the setting entirely. This is similar to what is done in the CalledMethodsAnalysis, I agree. What I don't fully understand is:

  1. Why does this PR added the method MustCallAnalysis#isIgnoredExceptionType()? Was this an oversight from before and it should have been there all along? This method seems unrelated to the command line setting.
  2. Why does this PR move the logic for the ignored exceptions command-line setting from the Resource Leak Checker to the Must Call Checker?

Thanks a lot!

Copy link
Contributor

@msridhar msridhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments below.

Generally, I am concerned that this change will lead to a lot of new reports. For Socket.bind() we have good evidence that these reports will be true positives, but there may be other cases where a @CreatesMustCallFor method only creates an obligation on its normal exit. We may need to eventually add support for a new annotation (@CreatesMustCallForOnNormal?) to express this property, with corresponding verification.

* The fully-qualified names of the exception types that are ignored by this checker when
* computing dataflow stores.
*/
protected static final Set<@CanonicalName String> ignoredExceptionTypes =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relatedly, #6242 added a mechanism for matching all subtypes of an exception type in addition to matching by name. We should try to be as consistent as possible here and share code if possible

Comment on lines 238 to 239
return MustCallAnalysis.ignoredExceptionTypes.contains(
TypesUtils.getQualifiedName((DeclaredType) exceptionType));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here about relationship to #6242

checker/tests/resourceleak/AssignNullInExceptionBlock.java Outdated Show resolved Hide resolved
checker/tests/resourceleak/BindFail.java Outdated Show resolved Hide resolved
checker/tests/resourceleak/BindFail.java Outdated Show resolved Hide resolved
// use the type's default must-call type instead. For String, this is @MustCall({}),
// so no error is issued. This rule is important to avoid false positives in realistic
// code (such as the first getMode() method in this class).
// :: error: required.method.not.called
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot understand why the behavior of this test changes due to this PR; there is no @CreatesMustCallFor anywhere here. Can you explain?

@mernst
Copy link
Member

mernst commented Jan 16, 2024

@msridhar Would you be willing to take over this pull request (either to complete it or to close it)?

@msridhar
Copy link
Contributor

I was hoping @Nargeshdb could still finish this up. @Nargeshdb what do you think?

Copy link
Contributor

@msridhar msridhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nargeshdb still hoping to land this one :-) Had a couple more questions

* The fully-qualified names of the exception types that are ignored by this checker when
* computing dataflow stores.
*/
protected static final Set<@CanonicalName String> ignoredExceptionTypes =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nargeshdb any thoughts on the above?

checker/tests/resourceleak/ACSocketTest.java Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

@CreatesMustCallFor should also create an obligation on exceptional successors
4 participants