Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.5.14
-
None
-
None
Description
One of my colleagues noticed that ASTTransformationCustomizer is not able to create correct getter method names for fields starting with 'i' when the default locale is Turkish.
Since i is capitalized in Turkish, `org.codehaus.groovy.runtime.MetaClassHelper#capitalize` method creates getter as "getİd" instead of "getId" for field "id".
Below you can find two sample test scenarios. While the first test using Turkish Locale fails, the second test using English Locale is successful.
package com.inomera.groovytest; import groovy.lang.GroovyClassLoader; import groovy.transform.CompileStatic; import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; import org.codehaus.groovy.control.customizers.SecureASTCustomizer; import org.junit.jupiter.api.Test; import org.springframework.util.ClassUtils; import java.util.List; import java.util.Locale; import java.util.Map; public class GroovyClassLoaderTest { @Test void parseClass_withTurkishLocale_parsesSuccessfully() { Locale.setDefault(new Locale("tr", "TR")); final var source = "import com.inomera.groovytest.GroovyClassLoaderTest.SimpleClass\n" + "def simpleObject = new SimpleClass(\"test\")\n" + "def id = simpleObject.id"; createGroovyClassLoader().parseClass(source); } @Test void parseClass_withEnglishLocale_parsesSuccessfully() { Locale.setDefault(new Locale("en", "US")); final var source = "import com.inomera.groovytest.GroovyClassLoaderTest.SimpleClass\n" + "def simpleObject = new SimpleClass(\"test\")\n" + "def id = simpleObject.id"; createGroovyClassLoader().parseClass(source); } private GroovyClassLoader createGroovyClassLoader() { final var secureASTCustomizer = new SecureASTCustomizer(); final var classMethodBlacklistTransformer = buildSandboxTypeCheckingTransformation(); final CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); compilerConfiguration.addCompilationCustomizers(secureASTCustomizer); compilerConfiguration.addCompilationCustomizers(classMethodBlacklistTransformer); return new GroovyClassLoader(ClassUtils.getDefaultClassLoader(), compilerConfiguration, false); } private ASTTransformationCustomizer buildSandboxTypeCheckingTransformation() { //final var extensions = List.of(SandboxTypeCheckingExtension.class.getName()); final var extensions = List.of(); final var annotationParameterValues = Map.of("extensions", extensions); return new ASTTransformationCustomizer(annotationParameterValues, CompileStatic.class); } public static class SimpleClass { private final String id; public SimpleClass(String id) { this.id = id; } public String getId() { return id; } } }
And the output of the test is:
script16321469570821381547815.groovy: 3: Access to com.inomera.groovytest.GroovyClassLoaderTest$SimpleClass#id is forbidden @ line 3, column 10. def id = simpleObject.id ^ 1 error