From e8030e5eb57cecec3de332b9676deee33a4381ab Mon Sep 17 00:00:00 2001 From: djlee Date: Sun, 30 Nov 2025 00:35:02 +0900 Subject: [PATCH 1/2] Use Charset instead of String for Mustache template encoding The MustacheResourceTemplateLoader previously defined the template encoding as a String, defaulting to "UTF-8". This change replaces the field with a Charset and initializes it with StandardCharsets.UTF_8. Using Charset improves type safety and aligns with modern Spring Boot standards, while avoiding implicit charset lookup issues. Signed-off-by: djlee --- .../autoconfigure/MustacheResourceTemplateLoader.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheResourceTemplateLoader.java b/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheResourceTemplateLoader.java index b388ff0b33c3..9767d5b00093 100644 --- a/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheResourceTemplateLoader.java +++ b/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheResourceTemplateLoader.java @@ -18,6 +18,8 @@ import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import com.samskivert.mustache.Mustache; import com.samskivert.mustache.Mustache.Compiler; @@ -45,7 +47,7 @@ public class MustacheResourceTemplateLoader implements TemplateLoader, ResourceL private String suffix = ""; - private String charSet = "UTF-8"; + private Charset charSet = StandardCharsets.UTF_8; private ResourceLoader resourceLoader = new DefaultResourceLoader(null); @@ -61,7 +63,7 @@ public MustacheResourceTemplateLoader(String prefix, String suffix) { * Set the charset. * @param charSet the charset */ - public void setCharset(String charSet) { + public void setCharset(Charset charSet) { this.charSet = charSet; } From 164115ce5a3b5ca51cb3a873691864afc8a71afd Mon Sep 17 00:00:00 2001 From: djlee Date: Mon, 1 Dec 2025 14:19:37 +0900 Subject: [PATCH 2/2] Add Charset overload for Mustache template encoding Add setCharset(Charset) overload to MustacheResourceTemplateLoader while keeping setCharset(String) for backward compatibility. The String-based method is deprecated in favor of the Charset variant. Also deprecate MustacheProperties.getCharsetName() as it's primarily used with the deprecated setCharset(String) method. This change maintains backward compatibility while providing a more type-safe API that aligns with modern Java standards. See gh-48347 Signed-off-by: djlee --- .../mustache/autoconfigure/MustacheProperties.java | 6 ++++++ .../autoconfigure/MustacheResourceTemplateLoader.java | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheProperties.java b/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheProperties.java index 558d90b9e493..9ffe0d4a36de 100644 --- a/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheProperties.java +++ b/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheProperties.java @@ -124,6 +124,12 @@ public Charset getCharset() { return this.charset; } + /** + * Get the charset name. + * @return the charset name + * @deprecated since 4.1.0 in favor of {@link #getCharset()} + */ + @Deprecated(since = "4.1.0") public String getCharsetName() { return this.charset.name(); } diff --git a/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheResourceTemplateLoader.java b/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheResourceTemplateLoader.java index 9767d5b00093..094b69c18f3e 100644 --- a/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheResourceTemplateLoader.java +++ b/module/spring-boot-mustache/src/main/java/org/springframework/boot/mustache/autoconfigure/MustacheResourceTemplateLoader.java @@ -62,6 +62,17 @@ public MustacheResourceTemplateLoader(String prefix, String suffix) { /** * Set the charset. * @param charSet the charset + * @deprecated since 4.1.0 in favor of {@link #setCharset(Charset)} + */ + @Deprecated(since = "4.1.0") + public void setCharset(String charSet) { + this.charSet = Charset.forName(charSet); + } + + /** + * Set the charset. + * @param charSet the charset + * @since 4.1.0 */ public void setCharset(Charset charSet) { this.charSet = charSet;