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:
Stephane Nicoll
2022-07-19 21:00:55 +02:00
parent 978cdfff46
commit d6345db7c9
4 changed files with 76 additions and 9 deletions

View File

@@ -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 {