Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 10, 2026

Addresses feedback from #47952: System.exit(1) in async samples terminates the JVM, breaking any application that embeds or copies this code.

Changes

Removed System.exit(1) from error handlers in three async samples:

  • Sample06_GetAnalyzerAsync.java - Uses doFinally() for cleanup
  • Sample15_GrantCopyAuthAsync.java - Uses explicit latch.countDown() in handlers
  • Sample16_CreateAnalyzerWithLabelsAsync.java - Uses explicit latch.countDown() in handlers

Pattern

Before:

.subscribe(
    result -> { /* success */ },
    error -> {
        error.printStackTrace();
        System.exit(1);  // Kills JVM
    }
);

After (doFinally pattern):

.doFinally(signalType -> latch.countDown())
.subscribe(
    result -> { /* success */ },
    error -> { /* error logged in doOnError */ }
);

After (explicit pattern):

.subscribe(
    result -> { latch.countDown(); },
    error -> { latch.countDown(); }
);

Both patterns allow errors to propagate naturally without killing the process.


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

Co-authored-by: yungshinlintw <14239352+yungshinlintw@users.noreply.github.com>
Copilot AI changed the title [WIP] Update content understanding GA SDK for Java based on feedback Remove System.exit(1) from async samples Feb 10, 2026
Copilot AI requested a review from yungshinlintw February 10, 2026 14:52
@changjian-wang changjian-wang marked this pull request as ready for review February 11, 2026 02:50
@changjian-wang changjian-wang merged commit 3413eb8 into cu_sdk/ga Feb 11, 2026
6 checks passed
@changjian-wang changjian-wang deleted the copilot/sub-pr-47952-again branch February 11, 2026 02:51
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.

3 participants