Merge pull request #6056 from Martin Lippert

* gh-6056:
  Check factory method metadata to avoid NPE in devtools condition
pull/6118/head
Andy Wilkinson 9 years ago
commit 9bbdbae178

@ -140,6 +140,8 @@ public class DevToolsDataSourceAutoConfiguration {
BeanDefinition dataSourceDefinition = context.getRegistry() BeanDefinition dataSourceDefinition = context.getRegistry()
.getBeanDefinition(dataSourceBeanNames[0]); .getBeanDefinition(dataSourceBeanNames[0]);
if (dataSourceDefinition instanceof AnnotatedBeanDefinition if (dataSourceDefinition instanceof AnnotatedBeanDefinition
&& ((AnnotatedBeanDefinition) dataSourceDefinition)
.getFactoryMethodMetadata() != null
&& ((AnnotatedBeanDefinition) dataSourceDefinition) && ((AnnotatedBeanDefinition) dataSourceDefinition)
.getFactoryMethodMetadata().getDeclaringClassName() .getFactoryMethodMetadata().getDeclaringClassName()
.startsWith(DataSourceAutoConfiguration.class.getName())) { .startsWith(DataSourceAutoConfiguration.class.getName())) {

@ -26,6 +26,7 @@ import javax.sql.DataSource;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
@ -72,6 +73,20 @@ public class AbstractDevToolsDataSourceAutoConfigurationTests {
} }
} }
@Test
public void emptyFactoryMethodMetadataIgnored() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
DataSource dataSource = mock(DataSource.class);
AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(
dataSource.getClass());
context.registerBeanDefinition("dataSource", beanDefinition);
context.register(DataSourcePropertiesConfiguration.class);
context.register(DevToolsDataSourceAutoConfiguration.class);
context.refresh();
context.close();
}
protected final Statement configureDataSourceBehaviour(DataSource dataSource) protected final Statement configureDataSourceBehaviour(DataSource dataSource)
throws SQLException { throws SQLException {
Connection connection = mock(Connection.class); Connection connection = mock(Connection.class);

Loading…
Cancel
Save