Java – resource never closed in try with resources when method linking

try(InputStream in = url.openStream(); Scanner scanner = new Scanner(in).useDelimiter("\\A")) {
try(InputStream in = url.openStream(); Scanner scanner = new Scanner(in).useDelimiter("\\A")) {

} catch(IOException e) {
    e.printStackTrace();
}

This line

warn:

Resource leak: <unassigned Closeable> value' is never closed

If I delete usedelimiter (string), it will disappear

Usedelimiter (string) does not return a new instance (it returns this instance). Why do I receive this warning? Is this a mistake?

I am using eclipse 4.4 My question has nothing to do with this, because different situations will give warnings

Solution

Yes, it looks like an error in the leak checker I suggest submitting an error report The initial Google search seems to indicate that one does not yet exist

Although I guess you can claim that it is impossible to solve the problem correctly The problem is that it is difficult to statically prove that usedelimiter returns it without many special shells

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>