DATAJDBC-586 - Guard JdbcRepositoryFactoryBean against setting null values for properties.

This commit is contained in:
Mark Paluch
2020-07-30 16:43:12 +02:00
parent 08a2d39380
commit fc8d51cd3b
2 changed files with 18 additions and 5 deletions

View File

@@ -96,12 +96,17 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
@Autowired
protected void setMappingContext(RelationalMappingContext mappingContext) {
Assert.notNull(mappingContext, "MappingContext must not be null");
super.setMappingContext(mappingContext);
this.mappingContext = mappingContext;
}
@Autowired
protected void setDialect(Dialect dialect) {
Assert.notNull(dialect, "Dialect must not be null");
this.dialect = dialect;
}
@@ -109,6 +114,9 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
* @param dataAccessStrategy can be {@literal null}.
*/
public void setDataAccessStrategy(DataAccessStrategy dataAccessStrategy) {
Assert.notNull(dataAccessStrategy, "DataAccessStrategy must not be null");
this.dataAccessStrategy = dataAccessStrategy;
}
@@ -118,15 +126,24 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
*/
@Autowired(required = false)
public void setQueryMappingConfiguration(QueryMappingConfiguration queryMappingConfiguration) {
Assert.notNull(queryMappingConfiguration, "QueryMappingConfiguration must not be null");
this.queryMappingConfiguration = queryMappingConfiguration;
}
public void setJdbcOperations(NamedParameterJdbcOperations operations) {
Assert.notNull(operations, "NamedParameterJdbcOperations must not be null");
this.operations = operations;
}
@Autowired
public void setConverter(JdbcConverter converter) {
Assert.notNull(converter, "JdbcConverter must not be null");
this.converter = converter;
}

View File

@@ -97,17 +97,13 @@ public class JdbcRepositoryFactoryBeanUnitTests {
@Test(expected = IllegalArgumentException.class) // DATAJDBC-151
public void requiresListableBeanFactory() {
factoryBean.setBeanFactory(mock(BeanFactory.class));
}
@Test(expected = IllegalStateException.class) // DATAJDBC-155
@Test(expected = IllegalArgumentException.class) // DATAJDBC-155
public void afterPropertiesThrowsExceptionWhenNoMappingContextSet() {
factoryBean.setMappingContext(null);
factoryBean.setApplicationEventPublisher(publisher);
factoryBean.setBeanFactory(beanFactory);
factoryBean.afterPropertiesSet();
}
@Test // DATAJDBC-155