From 37528eb1366c8f2d89d95d8c660a8fea77d40997 Mon Sep 17 00:00:00 2001 From: geopark021 Date: Wed, 26 Nov 2025 18:18:29 +0900 Subject: [PATCH] Refactor code to use pattern matching for instanceof Replace explicit casts with pattern variables introduced in Java 16 to improve readability and remove redundancy. This commit updates the following classes: - CommandRunner - AnnotationsPropertySource Signed-off-by: geopark021 --- .../autoconfigure/properties/AnnotationsPropertySource.java | 2 +- .../org/springframework/boot/cli/command/CommandRunner.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java index 6a67cc266206..ab4792df0f8c 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java @@ -138,7 +138,7 @@ private void putProperties(String name, SkipPropertyMapping defaultSkip, Object } else if (value instanceof MergedAnnotation annotation) { for (Method attribute : annotation.getType().getDeclaredMethods()) { - collectProperties(name, defaultSkip, (MergedAnnotation) value, attribute, properties); + collectProperties(name, defaultSkip, annotation, attribute, properties); } } else { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java b/spring-boot-project/spring-boot-tools/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java index 9ceb76ce4c53..732225ca87cd 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java @@ -242,7 +242,7 @@ private int handleError(boolean debug, Exception ex) { if (ex instanceof CommandException commandException) { options = commandException.getOptions(); if (options.contains(CommandException.Option.RETHROW)) { - throw (CommandException) ex; + throw commandException; } } boolean couldNotShowMessage = false;