eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

false alarm of Resource leak warning

Open Eskibear opened this issue 4 years ago • 1 comments

Given below piece of code, JDT.LS issues a false alarm of "Resource leak".

import java.util.Scanner;

public class Sample {
	public static void main(String[] args) {	
		Scanner reader = new Scanner(System.in);
		int i = 0;
		for (i = 0; i < 1; i++) {
		}
		reader.close();
	}
}

image

It's reproduced in both VS Code and Eclipse.

More clues:

  • If we define i inside for-loop as for (int i =0; i<1; i++)..., the warning is gone.
  • In IntelliJ IDEA 2020 or some older version Eclipse e.g. 2019-03 (4.11.0), no such warning.
  • Same issue discussed in a reddit thread 9 months ago.

Eskibear avatar Mar 17 '21 07:03 Eskibear

Looking through JDT bugzilla, I see quite a few cases over the years of unexpected resource leaks reported. None seem as straightforward as this though. I think our best bet is to file these upstream, much like https://bugs.eclipse.org/bugs/show_bug.cgi?id=561589 (redhat-developer/vscode-java#1349) .

rgrunber avatar Mar 30 '21 14:03 rgrunber