Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

Addresses code review feedback to eliminate the @SuppressWarnings("resource") annotation by refactoring Scanner initialization from method-level to class-level scope.

Changes

  • Moved Scanner instantiation from getUserApproval() to a static final field CONSOLE_SCANNER
  • Removed resource leak suppression warning
  • Added documentation clarifying that System.in Scanner should remain open for application lifetime

Before

private static boolean getUserApproval() {
    @SuppressWarnings("resource")
    Scanner scanner = new Scanner(System.in);
    while (true) {
        System.out.print("Approve MCP call? (y/n): ");
        String input = scanner.nextLine().trim().toLowerCase();
        // ...
    }
}

After

// Scanner for user input (reused across approval requests)
// This Scanner wraps System.in and should not be closed to allow continued console input
private static final Scanner CONSOLE_SCANNER = new Scanner(System.in);

private static boolean getUserApproval() {
    while (true) {
        System.out.print("Approve MCP call? (y/n): ");
        String input = CONSOLE_SCANNER.nextLine().trim().toLowerCase();
        // ...
    }
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Xiting Zhang and others added 3 commits January 14, 2026 12:36
Copilot AI and others added 2 commits January 14, 2026 20:54
Co-authored-by: xitzhang <11403681+xitzhang@users.noreply.github.com>
Co-authored-by: xitzhang <11403681+xitzhang@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback on MCP sample with V2026_01_01_PREVIEW support Refactor MCP sample to use class-level Scanner Jan 14, 2026
Copilot AI requested a review from xitzhang January 14, 2026 20:56
Base automatically changed from xitzhang/asyncmcpsample to main January 20, 2026 19:11
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.

2 participants