Make canonical SpelParserConfiguration constructor package-private

The 9-arg canonical constructor for SpelParserConfiguration was
recently introduced to support the new maximumNestingDepth property in
7.1. However, this feature has not yet been released, and in the
interim we introduced a builder API which supersedes the use of those
constructors.

Since no released version has ever exposed this constructor publicly,
this commit converts it to package-private in favor of exclusively
using the builder to construct instances which need to override the
default value for maximumNestingDepth.

See gh-36723
See gh-37187
See gh-37190
This commit is contained in:
Sam Brannen
2026-09-08 12:59:07 +02:00
parent 30a07ed551
commit 1bc5bb0f90
2 changed files with 35 additions and 39 deletions
@@ -396,9 +396,7 @@ public class SpelParserConfiguration {
/**
* Create a new {@code SpelParserConfiguration} instance.
* <p><strong>NOTE</strong>: Favor {@link #builder()} for complete
* configuration control and the ability to override global defaults
* per use case.
* <p>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) {
@@ -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));
}
}
}