Skip to content

Commit fc8d51c

Browse files
committed
DATAJDBC-586 - Guard JdbcRepositoryFactoryBean against setting null values for properties.
1 parent 08a2d39 commit fc8d51c

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,27 @@ protected RepositoryFactorySupport doCreateRepositoryFactory() {
9696
@Autowired
9797
protected void setMappingContext(RelationalMappingContext mappingContext) {
9898

99+
Assert.notNull(mappingContext, "MappingContext must not be null");
100+
99101
super.setMappingContext(mappingContext);
100102
this.mappingContext = mappingContext;
101103
}
102104

103105
@Autowired
104106
protected void setDialect(Dialect dialect) {
107+
108+
Assert.notNull(dialect, "Dialect must not be null");
109+
105110
this.dialect = dialect;
106111
}
107112

108113
/**
109114
* @param dataAccessStrategy can be {@literal null}.
110115
*/
111116
public void setDataAccessStrategy(DataAccessStrategy dataAccessStrategy) {
117+
118+
Assert.notNull(dataAccessStrategy, "DataAccessStrategy must not be null");
119+
112120
this.dataAccessStrategy = dataAccessStrategy;
113121
}
114122

@@ -118,15 +126,24 @@ public void setDataAccessStrategy(DataAccessStrategy dataAccessStrategy) {
118126
*/
119127
@Autowired(required = false)
120128
public void setQueryMappingConfiguration(QueryMappingConfiguration queryMappingConfiguration) {
129+
130+
Assert.notNull(queryMappingConfiguration, "QueryMappingConfiguration must not be null");
131+
121132
this.queryMappingConfiguration = queryMappingConfiguration;
122133
}
123134

124135
public void setJdbcOperations(NamedParameterJdbcOperations operations) {
136+
137+
Assert.notNull(operations, "NamedParameterJdbcOperations must not be null");
138+
125139
this.operations = operations;
126140
}
127141

128142
@Autowired
129143
public void setConverter(JdbcConverter converter) {
144+
145+
Assert.notNull(converter, "JdbcConverter must not be null");
146+
130147
this.converter = converter;
131148
}
132149

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,13 @@ public void setsUpBasicInstanceCorrectly() {
9797

9898
@Test(expected = IllegalArgumentException.class) // DATAJDBC-151
9999
public void requiresListableBeanFactory() {
100-
101100
factoryBean.setBeanFactory(mock(BeanFactory.class));
102101
}
103102

104-
@Test(expected = IllegalStateException.class) // DATAJDBC-155
103+
@Test(expected = IllegalArgumentException.class) // DATAJDBC-155
105104
public void afterPropertiesThrowsExceptionWhenNoMappingContextSet() {
106105

107106
factoryBean.setMappingContext(null);
108-
factoryBean.setApplicationEventPublisher(publisher);
109-
factoryBean.setBeanFactory(beanFactory);
110-
factoryBean.afterPropertiesSet();
111107
}
112108

113109
@Test // DATAJDBC-155

0 commit comments

Comments
 (0)