Skip to content

Commit 46ff56c

Browse files
committed
Add nullability annotations to module/spring-boot-groovy-templates
See gh-46587
1 parent 910a8a4 commit 46ff56c

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

module/spring-boot-groovy-templates/src/main/java/org/springframework/boot/groovy/template/autoconfigure/GroovyTemplateAvailabilityProvider.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 setResourceLoaderPath(List<String> resourceLoaderPath) {
6971
static class GroovyTemplateAvailabilityRuntimeHints 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(GroovyTemplateAvailabilityProperties.class)
7577
.registerHints(hints, classLoader);

module/spring-boot-groovy-templates/src/main/java/org/springframework/boot/groovy/template/autoconfigure/GroovyTemplateProperties.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424

2525
import groovy.text.markup.BaseTemplate;
26+
import org.jspecify.annotations.Nullable;
2627

2728
import org.springframework.boot.context.properties.ConfigurationProperties;
2829
import org.springframework.core.Ordered;
@@ -76,7 +77,7 @@ public class GroovyTemplateProperties {
7677
/**
7778
* View names that can be resolved.
7879
*/
79-
private String[] viewNames;
80+
private String @Nullable [] viewNames;
8081

8182
/**
8283
* Whether to check that the templates location exists.
@@ -141,7 +142,7 @@ public class GroovyTemplateProperties {
141142
/**
142143
* String used for auto-indents.
143144
*/
144-
private String autoIndentString;
145+
private @Nullable String autoIndentString;
145146

146147
/**
147148
* Whether new lines are rendered automatically.
@@ -156,7 +157,7 @@ public class GroovyTemplateProperties {
156157
/**
157158
* Encoding used to write the declaration heading.
158159
*/
159-
private String declarationEncoding;
160+
private @Nullable String declarationEncoding;
160161

161162
/**
162163
* Whether elements without a body should be written expanded (&lt;br&gt;&lt;/br&gt;)
@@ -167,12 +168,12 @@ public class GroovyTemplateProperties {
167168
/**
168169
* Default locale for template resolution.
169170
*/
170-
private Locale locale;
171+
private @Nullable Locale locale;
171172

172173
/**
173174
* String used to write a new line. Defaults to the system's line separator.
174175
*/
175-
private String newLineString;
176+
private @Nullable String newLineString;
176177

177178
/**
178179
* Template path.
@@ -200,11 +201,11 @@ public void setCheckTemplateLocation(boolean checkTemplateLocation) {
200201
this.checkTemplateLocation = checkTemplateLocation;
201202
}
202203

203-
public String[] getViewNames() {
204+
public String @Nullable [] getViewNames() {
204205
return this.viewNames;
205206
}
206207

207-
public void setViewNames(String[] viewNames) {
208+
public void setViewNames(String @Nullable [] viewNames) {
208209
this.viewNames = viewNames;
209210
}
210211

@@ -234,7 +235,7 @@ public Charset getCharset() {
234235
return this.charset;
235236
}
236237

237-
public String getCharsetName() {
238+
public @Nullable String getCharsetName() {
238239
return (this.charset != null) ? this.charset.name() : null;
239240
}
240241

@@ -258,11 +259,11 @@ public void setAutoIndent(boolean autoIndent) {
258259
this.autoIndent = autoIndent;
259260
}
260261

261-
public String getAutoIndentString() {
262+
public @Nullable String getAutoIndentString() {
262263
return this.autoIndentString;
263264
}
264265

265-
public void setAutoIndentString(String autoIndentString) {
266+
public void setAutoIndentString(@Nullable String autoIndentString) {
266267
this.autoIndentString = autoIndentString;
267268
}
268269

@@ -282,11 +283,11 @@ public void setBaseTemplateClass(Class<? extends BaseTemplate> baseTemplateClass
282283
this.baseTemplateClass = baseTemplateClass;
283284
}
284285

285-
public String getDeclarationEncoding() {
286+
public @Nullable String getDeclarationEncoding() {
286287
return this.declarationEncoding;
287288
}
288289

289-
public void setDeclarationEncoding(String declarationEncoding) {
290+
public void setDeclarationEncoding(@Nullable String declarationEncoding) {
290291
this.declarationEncoding = declarationEncoding;
291292
}
292293

@@ -298,19 +299,19 @@ public void setExpandEmptyElements(boolean expandEmptyElements) {
298299
this.expandEmptyElements = expandEmptyElements;
299300
}
300301

301-
public Locale getLocale() {
302+
public @Nullable Locale getLocale() {
302303
return this.locale;
303304
}
304305

305-
public void setLocale(Locale locale) {
306+
public void setLocale(@Nullable Locale locale) {
306307
this.locale = locale;
307308
}
308309

309-
public String getNewLineString() {
310+
public @Nullable String getNewLineString() {
310311
return this.newLineString;
311312
}
312313

313-
public void setNewLineString(String newLineString) {
314+
public void setNewLineString(@Nullable String newLineString) {
314315
this.newLineString = newLineString;
315316
}
316317

@@ -407,8 +408,9 @@ public void applyToMvcViewResolver(Object viewResolver) {
407408
resolver.setPrefix(getPrefix());
408409
resolver.setSuffix(getSuffix());
409410
resolver.setCache(isCache());
410-
if (getContentType() != null) {
411-
resolver.setContentType(getContentType().toString());
411+
MimeType contentType = getContentType();
412+
if (contentType != null) {
413+
resolver.setContentType(contentType.toString());
412414
}
413415
resolver.setViewNames(getViewNames());
414416
resolver.setExposeRequestAttributes(isExposeRequestAttributes());

module/spring-boot-groovy-templates/src/main/java/org/springframework/boot/groovy/template/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 Groovy templates.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.groovy.template.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)