Skip to content

Commit efe2d57

Browse files
committed
Add nullability annotations to module/spring-boot-freemarker
See gh-46587
1 parent fe98648 commit efe2d57

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/AbstractFreeMarkerConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ protected final FreeMarkerProperties getProperties() {
4949
protected void applyProperties(FreeMarkerConfigurationFactory factory) {
5050
factory.setTemplateLoaderPaths(this.properties.getTemplateLoaderPath());
5151
factory.setPreferFileSystemAccess(this.properties.isPreferFileSystemAccess());
52-
factory.setDefaultEncoding(this.properties.getCharsetName());
52+
String charsetName = this.properties.getCharsetName();
53+
if (charsetName != null) {
54+
factory.setDefaultEncoding(charsetName);
55+
}
5356
factory.setFreemarkerSettings(createFreeMarkerSettings());
5457
factory.setFreemarkerVariables(createFreeMarkerVariables());
5558
}

module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/FreeMarkerProperties.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.LinkedHashMap;
2323
import java.util.Map;
2424

25+
import org.jspecify.annotations.Nullable;
26+
2527
import org.springframework.boot.context.properties.ConfigurationProperties;
2628
import org.springframework.core.Ordered;
2729
import org.springframework.util.Assert;
@@ -71,7 +73,7 @@ public class FreeMarkerProperties {
7173
/**
7274
* View names that can be resolved.
7375
*/
74-
private String[] viewNames;
76+
private String @Nullable [] viewNames;
7577

7678
/**
7779
* Whether to check that the templates location exists.
@@ -91,7 +93,7 @@ public class FreeMarkerProperties {
9193
/**
9294
* Name of the RequestContext attribute for all views.
9395
*/
94-
private String requestContextAttribute;
96+
private @Nullable String requestContextAttribute;
9597

9698
/**
9799
* Whether all request attributes should be added to the model prior to merging with
@@ -157,11 +159,11 @@ public boolean isCheckTemplateLocation() {
157159
return this.checkTemplateLocation;
158160
}
159161

160-
public String[] getViewNames() {
162+
public String @Nullable [] getViewNames() {
161163
return this.viewNames;
162164
}
163165

164-
public void setViewNames(String[] viewNames) {
166+
public void setViewNames(String @Nullable [] viewNames) {
165167
this.viewNames = viewNames;
166168
}
167169

@@ -191,7 +193,7 @@ public Charset getCharset() {
191193
return this.charset;
192194
}
193195

194-
public String getCharsetName() {
196+
public @Nullable String getCharsetName() {
195197
return (this.charset != null) ? this.charset.name() : null;
196198
}
197199

@@ -239,11 +241,11 @@ public void setSuffix(String suffix) {
239241
this.suffix = suffix;
240242
}
241243

242-
public String getRequestContextAttribute() {
244+
public @Nullable String getRequestContextAttribute() {
243245
return this.requestContextAttribute;
244246
}
245247

246-
public void setRequestContextAttribute(String requestContextAttribute) {
248+
public void setRequestContextAttribute(@Nullable String requestContextAttribute) {
247249
this.requestContextAttribute = requestContextAttribute;
248250
}
249251

module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/FreeMarkerTemplateAvailabilityProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.aot.hint.RuntimeHints;
2426
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2527
import org.springframework.boot.autoconfigure.template.PathBasedTemplateAvailabilityProvider;
@@ -69,7 +71,7 @@ public void setTemplateLoaderPath(List<String> templateLoaderPath) {
6971
static class FreeMarkerTemplateAvailabilityRuntimeHints implements RuntimeHintsRegistrar {
7072

7173
@Override
72-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
74+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
7375
if (ClassUtils.isPresent(REQUIRED_CLASS_NAME, classLoader)) {
7476
BindableRuntimeHintsRegistrar.forTypes(FreeMarkerTemplateAvailabilityProperties.class)
7577
.registerHints(hints, classLoader);

module/spring-boot-freemarker/src/main/java/org/springframework/boot/freemarker/autoconfigure/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for FreeMarker.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.freemarker.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)