Use target of the FactoryBean only if the FactoryBean is public
This commit polishes 85d4a79 so that the target type of factory bean
is only considered if the FactoryBean is accessible. If the FactoryBean
requires protected access, we still generate the code in the package of
the FactoryBean.
Those two commits combined are actually providing a fix for the use
case described in gh-28809.
Closes gh-28809
This commit is contained in:
@@ -51,12 +51,19 @@ class DefaultBeanRegistrationCodeFragmentsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTargetOnConstructorToFactoryBean() {
|
||||
void getTargetOnConstructorToPublicFactoryBean() {
|
||||
RegisteredBean registeredBean = registerTestBean(TestBean.class);
|
||||
assertThat(createInstance(registeredBean).getTarget(registeredBean,
|
||||
TestBeanFactoryBean.class.getDeclaredConstructors()[0])).isEqualTo(TestBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTargetOnConstructorToProtectedFactoryBean() {
|
||||
RegisteredBean registeredBean = registerTestBean(TestBean.class);
|
||||
assertThat(createInstance(registeredBean).getTarget(registeredBean,
|
||||
PrivilegedTestBeanFactoryBean.class.getDeclaredConstructors()[0])).isEqualTo(PrivilegedTestBeanFactoryBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTargetOnMethod() {
|
||||
RegisteredBean registeredBean = registerTestBean(TestBean.class);
|
||||
@@ -135,13 +142,7 @@ class DefaultBeanRegistrationCodeFragmentsTests {
|
||||
return "Test";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
static class TestBean {
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class TestBeanFactoryBean implements FactoryBean<TestBean> {
|
||||
static class PrivilegedTestBeanFactoryBean implements FactoryBean<TestBean> {
|
||||
|
||||
@Override
|
||||
public TestBean getObject() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user