From 127d320636d6b372c06d51190fc6e16ae1437a6a Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 8 Sep 2022 18:24:21 -0700 Subject: [PATCH] Refactor code to work around Eclipse compiler bug Refactor code to work around the Eclipse compiler bug reported at https://github.com/eclipse-jdt/eclipse.jdt.core/issues/378 Closes gh-32264 --- .../org/springframework/boot/SpringApplication.java | 13 ++++++++----- .../ReactiveWebServerApplicationContextFactory.java | 11 +++++++---- .../ServletWebServerApplicationContextFactory.java | 11 +++++++---- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index d7adbea769..89426423e8 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -456,11 +456,14 @@ public class SpringApplication { if (this.environment != null) { return this.environment; } - return switch (this.webApplicationType) { - case SERVLET -> new ApplicationServletEnvironment(); - case REACTIVE -> new ApplicationReactiveWebEnvironment(); - default -> new ApplicationEnvironment(); - }; + switch (this.webApplicationType) { + case SERVLET: + return new ApplicationServletEnvironment(); + case REACTIVE: + return new ApplicationReactiveWebEnvironment(); + default: + return new ApplicationEnvironment(); + } } /** diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextFactory.java index 9064cd1ca8..0c2b7b2c6b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextFactory.java @@ -33,11 +33,14 @@ class ReactiveWebServerApplicationContextFactory implements ApplicationContextFa @Override public ConfigurableApplicationContext create(WebApplicationType webApplicationType) { - if (webApplicationType != WebApplicationType.REACTIVE) { - return null; + return (webApplicationType != WebApplicationType.REACTIVE) ? null : createContext(); + } + + private ConfigurableApplicationContext createContext() { + if (!AotDetector.useGeneratedArtifacts()) { + return new AnnotationConfigReactiveWebServerApplicationContext(); } - return AotDetector.useGeneratedArtifacts() ? new ReactiveWebServerApplicationContext() - : new AnnotationConfigReactiveWebServerApplicationContext(); + return new ReactiveWebServerApplicationContext(); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextFactory.java index 9682a779cf..46cfb6bfdb 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextFactory.java @@ -33,11 +33,14 @@ class ServletWebServerApplicationContextFactory implements ApplicationContextFac @Override public ConfigurableApplicationContext create(WebApplicationType webApplicationType) { - if (webApplicationType != WebApplicationType.SERVLET) { - return null; + return (webApplicationType != WebApplicationType.SERVLET) ? null : createContext(); + } + + private ConfigurableApplicationContext createContext() { + if (!AotDetector.useGeneratedArtifacts()) { + return new AnnotationConfigServletWebServerApplicationContext(); } - return AotDetector.useGeneratedArtifacts() ? new ServletWebServerApplicationContext() - : new AnnotationConfigServletWebServerApplicationContext(); + return new ServletWebServerApplicationContext(); } }