From 2b1e043c7ffd109526f720052bd25ebabad118ab Mon Sep 17 00:00:00 2001 From: Shay Keren Date: Mon, 9 Jun 2025 11:11:03 +0300 Subject: [PATCH 1/2] .get_string_or_string_from_dict at 0x11e0c3780> --- .../petclinic/errors/MonitorService.java | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java b/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java index af0ad68a219..7a9fb2aa843 100644 --- a/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java +++ b/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java @@ -9,7 +9,11 @@ import java.util.InvalidPropertiesFormatException; -@Component +@Component/** + * A monitoring service that simulates error conditions for demonstration purposes. + * This service intentionally throws IllegalStateException every 5 seconds + * as part of the application's error simulation functionality. + */ public class MonitorService implements SmartLifecycle { private boolean running = false; @@ -48,30 +52,34 @@ public void start() { // Start the background thread backgroundThread.start(); System.out.println("Background service started."); - } - - private void monitor() throws InvalidPropertiesFormatException { - Utils.throwException(IllegalStateException.class,"monitor failure"); - } - + }/** + * Monitors the system state. This method intentionally throws an IllegalStateException + * every 5 seconds as part of the application's error simulation functionality. + * The exception is used for demonstration purposes. + * + * @throws InvalidPropertiesFormatException if there's an invalid property format + */ +private void monitor() throws InvalidPropertiesFormatException { + Utils.throwException(IllegalStateException.class,"monitor failure"); +} - @Override - public void stop() { - // Stop the background task - running = false; - if (backgroundThread != null) { - try { - backgroundThread.join(); // Wait for the thread to finish - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } +@Override +public void stop() { + // Stop the background task + running = false; + if (backgroundThread != null) { + try { + backgroundThread.join(); // Wait for the thread to finish + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } - System.out.println("Background service stopped."); } + System.out.println("Background service stopped."); +} - @Override - public boolean isRunning() { - return false; - } +@Override +public boolean isRunning() { + return false; } +} \ No newline at end of file From c2defea4ec1f7d51ea4b50503d0c0629d8741b94 Mon Sep 17 00:00:00 2001 From: Shay Keren Date: Wed, 11 Jun 2025 15:04:54 +0300 Subject: [PATCH 2/2] docs: clarify IllegalStateException is intentional demo feature --- .../petclinic/errors/MonitorService.java | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java b/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java index 7a9fb2aa843..77c69d0d89f 100644 --- a/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java +++ b/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java @@ -9,12 +9,7 @@ import java.util.InvalidPropertiesFormatException; -@Component/** - * A monitoring service that simulates error conditions for demonstration purposes. - * This service intentionally throws IllegalStateException every 5 seconds - * as part of the application's error simulation functionality. - */ -public class MonitorService implements SmartLifecycle { +@Componentpublic class MonitorService implements SmartLifecycle { private boolean running = false; private Thread backgroundThread; @@ -53,33 +48,33 @@ public void start() { backgroundThread.start(); System.out.println("Background service started."); }/** - * Monitors the system state. This method intentionally throws an IllegalStateException - * every 5 seconds as part of the application's error simulation functionality. - * The exception is used for demonstration purposes. + * Monitors the system state. This method is intentionally designed to throw an + * IllegalStateException as a demonstration feature to simulate monitoring failures. * - * @throws InvalidPropertiesFormatException if there's an invalid property format + * @throws InvalidPropertiesFormatException if properties are invalid + * @throws IllegalStateException intentionally thrown to demonstrate error handling */ private void monitor() throws InvalidPropertiesFormatException { - Utils.throwException(IllegalStateException.class,"monitor failure"); + Utils.throwException(IllegalStateException.class,"monitor failure"); } @Override public void stop() { - // Stop the background task - running = false; - if (backgroundThread != null) { - try { - backgroundThread.join(); // Wait for the thread to finish - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - System.out.println("Background service stopped."); + // Stop the background task + running = false; + if (backgroundThread != null) { + try { + backgroundThread.join(); // Wait for the thread to finish + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + System.out.println("Background service stopped."); } @Override public boolean isRunning() { - return false; + return false; } } \ No newline at end of file