[java] CloseResource: Disallow allowedResourceTypes classes returned by certain methods
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 5.5k
- Forks
- 1.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 54
Description
Is your feature request related to a problem? Please describe.
By default, java.util.stream.Stream is part of the default allowedResourceTypes, which makes a lot of sense as the vast majority of Stream instances never need to be closed. However, there are some cases, where streams really should be closed - the reason why I'm opening this one is because I found some resource leaks in JPA/Hibernate code. It called TypedQuery#getResultStream(). This returns a Stream backed by a ResultSet, which needs to be closed, which happens when the Stream is closed
Describe the solution you'd like
A new config option, basically the inverse of allowedResourceMethodPatterns, which allows me to list some method calls returning Closeables, which are listed in allowedResourceTypes, but should result in a warning nonetheless
Describe alternatives you've considered
I briefly considered removing Stream from allowedResourceTypes, but quickly stopped considering it, after I did it and saw the very, very long list of warnings this produced :)
Additional context
This is basically the inverse of https://github.com/pmd/pmd/pull/6437
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the CloseResource rule and its existing allowedResourceMethodPatterns configuration, then trace how returned resource types are exempted. Add the requested inverse configuration for selected method calls and verify that those calls produce warnings while ordinary allowed Stream returns remain exempt.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100