Browse Source

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

pull/243/head
Mark Paluch 5 years ago
parent
commit
fc8d51cd3b
No known key found for this signature in database
GPG Key ID: 51A00FA751B91849
  1. 17
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactoryBean.java
  2. 6
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactoryBeanUnitTests.java

17
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactoryBean.java

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

6
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactoryBeanUnitTests.java

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

Loading…
Cancel
Save