Add nullability annotations to module/spring-boot-freemarker

See gh-46587
This commit is contained in:
Moritz Halbritter
2025-08-01 09:16:10 +02:00
parent fe9864847f
commit efe2d5732b
4 changed files with 19 additions and 9 deletions
@@ -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());
}
@@ -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;
}
@@ -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);
@@ -17,4 +17,7 @@
/**
* Auto-configuration for FreeMarker.
*/
@NullMarked
package org.springframework.boot.freemarker.autoconfigure;
import org.jspecify.annotations.NullMarked;