From ee10425b6d605b7671eeb31acb65273924ce8589 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Thu, 12 Sep 2024 17:26:09 +0800 Subject: [PATCH] Add tests to ensure private constructor is not used for binding See gh-42277 --- .../DefaultBindConstructorProviderTests.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/DefaultBindConstructorProviderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/DefaultBindConstructorProviderTests.java index 160773e52c..99ebc054eb 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/DefaultBindConstructorProviderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/DefaultBindConstructorProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * * @author Phillip Webb * @author Madhura Bhave + * @author Yanming Zhou */ class DefaultBindConstructorProviderTests { @@ -92,6 +93,12 @@ class DefaultBindConstructorProviderTests { .withMessageContaining("has more than one @ConstructorBinding"); } + @Test + void getBindConstructorWhenIsTypeWithPrivateConstructorReturnsNull() { + Constructor constructor = this.provider.getBindConstructor(TypeWithPrivateConstructor.class, false); + assertThat(constructor).isNull(); + } + @Test void getBindConstructorWhenIsMemberTypeWithPrivateConstructorReturnsNull() { Constructor constructor = this.provider.getBindConstructor(MemberTypeWithPrivateConstructor.Member.class, @@ -224,6 +231,13 @@ class DefaultBindConstructorProviderTests { } + static final class TypeWithPrivateConstructor { + + private TypeWithPrivateConstructor(Environment environment) { + } + + } + static class MemberTypeWithPrivateConstructor { static final class Member {