diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java b/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java index e14e5209e48..2e5cf073293 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java @@ -396,9 +396,7 @@ public class SpelParserConfiguration { /** * Create a new {@code SpelParserConfiguration} instance. - *

NOTE: Favor {@link #builder()} for complete - * configuration control and the ability to override global defaults - * per use case. + *

This is the internal, canonical constructor. * @param compilerMode the compiler mode that parsers using this configuration * should use; must not be {@code null} * @param compilerClassLoader the {@code ClassLoader} to use as the basis for @@ -418,10 +416,8 @@ public class SpelParserConfiguration { * @param maximumNestingDepth the maximum nesting depth permitted within a SpEL * expression; must be a positive number * @since 7.1 - * @deprecated as of Spring Framework 7.1, in favor of the {@linkplain #builder() builder API} */ - @Deprecated(since = "7.1") - public SpelParserConfiguration(SpelCompilerMode compilerMode, @Nullable ClassLoader compilerClassLoader, + SpelParserConfiguration(SpelCompilerMode compilerMode, @Nullable ClassLoader compilerClassLoader, boolean autoGrowNullReferences, boolean autoGrowCollections, int maximumAutoGrowSize, int maximumExpressionLength, int maximumOperations, int maximumBigPowerBits, int maximumNestingDepth) { diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SpelParserConfigurationTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SpelParserConfigurationTests.java index a3a9bc8c84b..08d35b451c6 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SpelParserConfigurationTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SpelParserConfigurationTests.java @@ -102,6 +102,39 @@ class SpelParserConfigurationTests { assertThatIllegalArgumentException().isThrownBy(() -> builder.maximumNestingDepth(0)); } + @Test + void canonicalConstructorAppliesAllValues() { + ClassLoader classLoader = getClass().getClassLoader(); + SpelParserConfiguration configuration = new SpelParserConfiguration( + SpelCompilerMode.IMMEDIATE, classLoader, true, true, 99, 100, 101, 102, 103); + + assertThat(configuration.getCompilerMode()).isEqualTo(SpelCompilerMode.IMMEDIATE); + assertThat(configuration.getCompilerClassLoader()).isSameAs(classLoader); + assertThat(configuration.isAutoGrowNullReferences()).isTrue(); + assertThat(configuration.isAutoGrowCollections()).isTrue(); + assertThat(configuration.getMaximumAutoGrowSize()).isEqualTo(99); + assertThat(configuration.getMaximumExpressionLength()).isEqualTo(100); + assertThat(configuration.getMaximumOperations()).isEqualTo(101); + assertThat(configuration.getMaximumBigPowerBits()).isEqualTo(102); + assertThat(configuration.getMaximumNestingDepth()).isEqualTo(103); + } + + @Test + void canonicalConstructorRejectsInvalidValues() { + assertThatIllegalArgumentException().isThrownBy(() -> + new SpelParserConfiguration(null, null, false, false, 0, 1, 1, 1, 1)); + assertThatIllegalArgumentException().isThrownBy(() -> + new SpelParserConfiguration(SpelCompilerMode.OFF, null, false, false, -1, 1, 1, 1, 1)); + assertThatIllegalArgumentException().isThrownBy(() -> + new SpelParserConfiguration(SpelCompilerMode.OFF, null, false, false, 0, 0, 1, 1, 1)); + assertThatIllegalArgumentException().isThrownBy(() -> + new SpelParserConfiguration(SpelCompilerMode.OFF, null, false, false, 0, 1, 0, 1, 1)); + assertThatIllegalArgumentException().isThrownBy(() -> + new SpelParserConfiguration(SpelCompilerMode.OFF, null, false, false, 0, 1, 1, 0, 1)); + assertThatIllegalArgumentException().isThrownBy(() -> + new SpelParserConfiguration(SpelCompilerMode.OFF, null, false, false, 0, 1, 1, 1, 0)); + } + /** * Regression tests for the legacy constructors in {@link SpelParserConfiguration}. @@ -211,39 +244,6 @@ class SpelParserConfigurationTests { .isEqualTo(SpelParserConfiguration.DEFAULT_MAX_EXPRESSION_NESTING_DEPTH); } - @Test - void canonicalConstructorAppliesAllValues() { - ClassLoader classLoader = getClass().getClassLoader(); - SpelParserConfiguration configuration = new SpelParserConfiguration( - SpelCompilerMode.IMMEDIATE, classLoader, true, true, 99, 100, 101, 102, 103); - - assertThat(configuration.getCompilerMode()).isEqualTo(SpelCompilerMode.IMMEDIATE); - assertThat(configuration.getCompilerClassLoader()).isSameAs(classLoader); - assertThat(configuration.isAutoGrowNullReferences()).isTrue(); - assertThat(configuration.isAutoGrowCollections()).isTrue(); - assertThat(configuration.getMaximumAutoGrowSize()).isEqualTo(99); - assertThat(configuration.getMaximumExpressionLength()).isEqualTo(100); - assertThat(configuration.getMaximumOperations()).isEqualTo(101); - assertThat(configuration.getMaximumBigPowerBits()).isEqualTo(102); - assertThat(configuration.getMaximumNestingDepth()).isEqualTo(103); - } - - @Test - void canonicalConstructorRejectsInvalidValues() { - assertThatIllegalArgumentException().isThrownBy(() -> - new SpelParserConfiguration(null, null, false, false, 0, 1, 1, 1, 1)); - assertThatIllegalArgumentException().isThrownBy(() -> - new SpelParserConfiguration(SpelCompilerMode.OFF, null, false, false, -1, 1, 1, 1, 1)); - assertThatIllegalArgumentException().isThrownBy(() -> - new SpelParserConfiguration(SpelCompilerMode.OFF, null, false, false, 0, 0, 1, 1, 1)); - assertThatIllegalArgumentException().isThrownBy(() -> - new SpelParserConfiguration(SpelCompilerMode.OFF, null, false, false, 0, 1, 0, 1, 1)); - assertThatIllegalArgumentException().isThrownBy(() -> - new SpelParserConfiguration(SpelCompilerMode.OFF, null, false, false, 0, 1, 1, 0, 1)); - assertThatIllegalArgumentException().isThrownBy(() -> - new SpelParserConfiguration(SpelCompilerMode.OFF, null, false, false, 0, 1, 1, 1, 0)); - } - } }