Allow non-public Kotlin classes/ctors to be instantiated

Closes gh-24712
This commit is contained in:
Tom van den Berge
2020-03-17 17:15:13 +01:00
committed by Sébastien Deleuze
parent 831a95154e
commit 107f88a7e4
3 changed files with 40 additions and 0 deletions

View File

@@ -95,6 +95,12 @@ class BeanUtilsTests {
BeanUtils.instantiateClass(ctor, null, null, "foo", null));
}
@Test
void testInstantiatePrivateClassWithPrivateConstructor() throws NoSuchMethodException {
Constructor<PrivateBeanWithPrivateConstructor> ctor = PrivateBeanWithPrivateConstructor.class.getDeclaredConstructor();
BeanUtils.instantiateClass(ctor);
}
@Test
void testGetPropertyDescriptors() throws Exception {
PropertyDescriptor[] actual = Introspector.getBeanInfo(TestBean.class).getPropertyDescriptors();
@@ -555,4 +561,10 @@ class BeanUtilsTests {
}
}
private static class PrivateBeanWithPrivateConstructor {
private PrivateBeanWithPrivateConstructor() {
}
}
}

View File

@@ -74,6 +74,22 @@ class KotlinBeanUtilsTests {
assertThat(baz.param2).isEqualTo(12)
}
@Test
@Suppress("UsePropertyAccessSyntax")
fun `Instantiate class with private constructor`() {
BeanUtils.instantiateClass(PrivateConstructor::class.java.getDeclaredConstructor())
}
@Test
fun `Instantiate class with protected constructor`() {
BeanUtils.instantiateClass(ProtectedConstructor::class.java.getDeclaredConstructor())
}
@Test
fun `Instantiate private class`() {
BeanUtils.instantiateClass(PrivateClass::class.java.getDeclaredConstructor())
}
class Foo(val param1: String, val param2: Int)
class Bar(val param1: String, val param2: Int = 12)
@@ -106,4 +122,10 @@ class KotlinBeanUtilsTests {
constructor(param1: String)
}
class PrivateConstructor private constructor()
open class ProtectedConstructor protected constructor()
private class PrivateClass
}