Skip to content

Commit 8686ee8

Browse files
committed
Merge pull request #42277 from quaff
* pr/42277: Add tests to ensure private constructor is not used for binding Closes gh-42277
2 parents 03e7be3 + ee10425 commit 8686ee8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/DefaultBindConstructorProviderTests.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@
3333
*
3434
* @author Phillip Webb
3535
* @author Madhura Bhave
36+
* @author Yanming Zhou
3637
*/
3738
class DefaultBindConstructorProviderTests {
3839

@@ -92,6 +93,12 @@ void getBindConstructorWhenHasTwoConstructorsWithBothConstructorBindingThrowsExc
9293
.withMessageContaining("has more than one @ConstructorBinding");
9394
}
9495

96+
@Test
97+
void getBindConstructorWhenIsTypeWithPrivateConstructorReturnsNull() {
98+
Constructor<?> constructor = this.provider.getBindConstructor(TypeWithPrivateConstructor.class, false);
99+
assertThat(constructor).isNull();
100+
}
101+
95102
@Test
96103
void getBindConstructorWhenIsMemberTypeWithPrivateConstructorReturnsNull() {
97104
Constructor<?> constructor = this.provider.getBindConstructor(MemberTypeWithPrivateConstructor.Member.class,
@@ -224,6 +231,13 @@ static class TwoConstructorsWithBothConstructorBinding {
224231

225232
}
226233

234+
static final class TypeWithPrivateConstructor {
235+
236+
private TypeWithPrivateConstructor(Environment environment) {
237+
}
238+
239+
}
240+
227241
static class MemberTypeWithPrivateConstructor {
228242

229243
static final class Member {

0 commit comments

Comments
 (0)