diff --git a/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/AbstractFreeMarkerConfiguration.java b/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/AbstractFreeMarkerConfiguration.java index cfb47f20acb..d0c9beff200 100644 --- a/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/AbstractFreeMarkerConfiguration.java +++ b/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/AbstractFreeMarkerConfiguration.java @@ -49,7 +49,10 @@ abstract class AbstractFreeMarkerConfiguration { protected void applyProperties(FreeMarkerConfigurationFactory factory) { factory.setTemplateLoaderPaths(this.properties.getTemplateLoaderPath()); factory.setPreferFileSystemAccess(this.properties.isPreferFileSystemAccess()); - factory.setDefaultEncoding(this.properties.getCharsetName()); + String charsetName = this.properties.getCharsetName(); + if (charsetName != null) { + factory.setDefaultEncoding(charsetName); + } factory.setFreemarkerSettings(createFreeMarkerSettings()); factory.setFreemarkerVariables(createFreeMarkerVariables()); } diff --git a/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/FreeMarkerProperties.java b/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/FreeMarkerProperties.java index 3dc7c27843a..150be308454 100644 --- a/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/FreeMarkerProperties.java +++ b/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/FreeMarkerProperties.java @@ -22,6 +22,8 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.core.Ordered; import org.springframework.util.Assert; @@ -71,7 +73,7 @@ public class FreeMarkerProperties { /** * View names that can be resolved. */ - private String[] viewNames; + private String @Nullable [] viewNames; /** * Whether to check that the templates location exists. @@ -91,7 +93,7 @@ public class FreeMarkerProperties { /** * Name of the RequestContext attribute for all views. */ - private String requestContextAttribute; + private @Nullable String requestContextAttribute; /** * Whether all request attributes should be added to the model prior to merging with @@ -157,11 +159,11 @@ public class FreeMarkerProperties { return this.checkTemplateLocation; } - public String[] getViewNames() { + public String @Nullable [] getViewNames() { return this.viewNames; } - public void setViewNames(String[] viewNames) { + public void setViewNames(String @Nullable [] viewNames) { this.viewNames = viewNames; } @@ -191,7 +193,7 @@ public class FreeMarkerProperties { return this.charset; } - public String getCharsetName() { + public @Nullable String getCharsetName() { return (this.charset != null) ? this.charset.name() : null; } @@ -239,11 +241,11 @@ public class FreeMarkerProperties { this.suffix = suffix; } - public String getRequestContextAttribute() { + public @Nullable String getRequestContextAttribute() { return this.requestContextAttribute; } - public void setRequestContextAttribute(String requestContextAttribute) { + public void setRequestContextAttribute(@Nullable String requestContextAttribute) { this.requestContextAttribute = requestContextAttribute; } diff --git a/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/FreeMarkerTemplateAvailabilityProvider.java b/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/FreeMarkerTemplateAvailabilityProvider.java index f6167d5f44b..f9f69a7440b 100644 --- a/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/FreeMarkerTemplateAvailabilityProvider.java +++ b/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/FreeMarkerTemplateAvailabilityProvider.java @@ -20,6 +20,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.boot.autoconfigure.template.PathBasedTemplateAvailabilityProvider; @@ -69,7 +71,7 @@ public class FreeMarkerTemplateAvailabilityProvider extends PathBasedTemplateAva static class FreeMarkerTemplateAvailabilityRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { if (ClassUtils.isPresent(REQUIRED_CLASS_NAME, classLoader)) { BindableRuntimeHintsRegistrar.forTypes(FreeMarkerTemplateAvailabilityProperties.class) .registerHints(hints, classLoader); diff --git a/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/package-info.java b/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/package-info.java index 0fa1da4d696..f17f5e4fd69 100644 --- a/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/package-info.java +++ b/module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for FreeMarker. */ +@NullMarked package org.springframework.boot.freemarker.autoconfigure; + +import org.jspecify.annotations.NullMarked;