Repository: micronaut-projects/micronaut-core
File: context/src/main/java/io/micronaut/runtime/Micronaut.java (Java)

Code before:
                    Thread mainThread = Thread.currentThread();
                    boolean finalKeepAlive = keepAlive;
                    CountDownLatch countDownLatch = new CountDownLatch(1);
                    if (embeddedApplication.isShutdownHookNeeded()) {
                        try {
                            Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                                if (LOG.isInfoEnabled()) {
                                    LOG.info("Embedded Application shutting down");
                                }
                                try (applicationContext) {
                                /* stop the application without checking if it is running,
                                   as it may have already opened some resources before starting */
                                    embeddedApplication.stop();
                                    countDownLatch.countDown();
                                    if (finalKeepAlive) {
                                        mainThread.interrupt();
                                    }
                                }
                            }));
                        } catch (IllegalStateException e) {
                            try (applicationContext) {
                                embeddedApplication.stop();
                            } catch (Throwable stopError) {
                                LOG.error("Embedded Application shutting down", stopError);
                            }
                            LOG.warn("Embedded Application: {}", e.getMessage());
                        }
                    }

                    if (keepAlive) {
                        new Thread(() -> {
                            try {
                                if (!embeddedApplication.isRunning()) {
                                    countDownLatch.countDown();
                                    Thread.sleep(1000);
                                }
                            } catch (InterruptedException e) {
                                Thread.currentThread().interrupt();
                            }
                        }, SHUTDOWN_MONITOR_THREAD).start();

                        boolean interrupted = false;
                        while (true) {
                            try {
                                countDownLatch.await();
                                break;
                            } catch (InterruptedException e) {
                                interrupted = true;
                                Thread.currentThread().interrupt();
                            }
                        }

Review comment (bug):
```suggestion
                            LOG.warn("Failed to register shutdown hook", e);
```

Code after:
                    Thread mainThread = Thread.currentThread();
                    boolean finalKeepAlive = keepAlive;
                    CountDownLatch countDownLatch = new CountDownLatch(1);
                    if (embeddedApplication.isShutdownHookNeeded()) {
                        try {
                            Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                                if (LOG.isInfoEnabled()) {
                                    LOG.info("Embedded Application shutting down");
                                }
                                try (applicationContext) {
                                /* stop the application without checking if it is running,
                                   as it may have already opened some resources before starting */
                                    embeddedApplication.stop();
                                    countDownLatch.countDown();
                                    if (finalKeepAlive) {
                                        mainThread.interrupt();
                                    }
                                }
                            }));
                        } catch (IllegalStateException e) {
                            try (applicationContext) {
                                embeddedApplication.stop();
                            } catch (Throwable stopError) {
                                LOG.error("Embedded Application shutting down", stopError);
                            }
                            LOG.warn("Failed to register shutdown hook", e);
                        }
                    }

                    if (keepAlive) {
                        new Thread(() -> {
                            try {
                                if (!embeddedApplication.isRunning()) {
                                    countDownLatch.countDown();
                                    Thread.sleep(1000);
                                }
                            } catch (InterruptedException e) {
                                Thread.currentThread().interrupt();
                            }
                        }, SHUTDOWN_MONITOR_THREAD).start();

                        boolean interrupted = false;
                        while (true) {
                            try {
                                countDownLatch.await();
                                break;
                            } catch (InterruptedException e) {
                                interrupted = true;
                                Thread.currentThread().interrupt();
                            }
                        }