Skip to content

Java Scanner can't be marked closed properly. #571

Description

@GaiZhenbiao

Environment:

  • VS Code Version:1.54.3
  • Extension Version:v0.13.0
  • JDK Type & Version:15.0.1
  • OS Type & Version: Windows 10 x64 20H2

Step to Reproduce:
Write Java codes that contains for sentences between a Scanner declaration and scanner.close().For example:

import java.util.Scanner;

public class Main{
    public static void main(String args[]) {
        long max = 0;
        long odd = 0;
        long even = 0;
        long i = 0;
        Scanner reader = new Scanner(System.in);
        max = reader.nextLong();
        for (i = 3; i <= max; i += 3) {
            if ((i & 1) == 1) {
                odd += 1;
            } else {
                even += 1;
            }
        }
        System.out.println(odd + "," + even);
        reader.close();
    }
}

there would be yellow waves under "reader" in declaration:
image

It said that reader wasn't closed properly, but when I add a line reader.nextLong();, exceptions raised said reader was closed. So reader actually was closed properly, but the extension marked wrong.

Expected Behavior:

No warnings when I write reachable close() sentences.

Actual Behavior:

A warning appeared said "Resource leak".

Related Issues:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions