Skip to content

Commit 608209c

Browse files
committed
Fix for issue #62. When using callSettersOnNulls MyBatis will create an
object even if a setter was called with a null. This used to work in 3.2.0 and 3.2.1 but was changed in 3.2.2. We are back to previous version.
1 parent 9f85c37 commit 608209c

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
/test.db.tmp
1818
/src/docbkx
1919
velocity.log
20+
/bin

src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,19 +365,17 @@ private boolean applyPropertyMappings(ResultSetWrapper rsw, ResultMap resultMap,
365365
|| propertyMapping.getResultSet() != null) {
366366
Object value = getPropertyMappingValue(rsw.getResultSet(), metaObject, propertyMapping, lazyLoader, columnPrefix);
367367
final String property = propertyMapping.getProperty(); // issue #541 make property optional
368-
if (value != NO_VALUE && property != null && (value != null || isCallSettersOnNulls(metaObject.getSetterType(property)))) { // issue #377, call setter on nulls
369-
metaObject.setValue(property, value);
368+
if (value != NO_VALUE && property != null && (value != null || configuration.isCallSettersOnNulls())) { // issue #377, call setter on nulls
369+
if (value != null || !metaObject.getSetterType(property).isPrimitive()) {
370+
metaObject.setValue(property, value);
371+
}
370372
foundValues = (value != null) || foundValues;
371373
}
372374
}
373375
}
374376
return foundValues;
375377
}
376378

377-
private boolean isCallSettersOnNulls(Class<?> propertyType) {
378-
return configuration.isCallSettersOnNulls() && !propertyType.isPrimitive();
379-
}
380-
381379
private Object getPropertyMappingValue(ResultSet rs, MetaObject metaResultObject, ResultMapping propertyMapping, ResultLoaderMap lazyLoader, String columnPrefix)
382380
throws SQLException {
383381
if (propertyMapping.getNestedQueryId() != null) {
@@ -415,9 +413,11 @@ private boolean applyAutomaticMappings(ResultSetWrapper rsw, ResultMap resultMap
415413
if (typeHandlerRegistry.hasTypeHandler(propertyType)) {
416414
final TypeHandler<?> typeHandler = rsw.getTypeHandler(propertyType, columnName);
417415
final Object value = typeHandler.getResult(rsw.getResultSet(), columnName);
418-
if (value != null || isCallSettersOnNulls(propertyType)) { // issue #377, call setter on nulls
419-
metaObject.setValue(property, value);
420-
foundValues = (value != null) || foundValues;
416+
if (value != null || configuration.isCallSettersOnNulls()) { // issue #377, call setter on nulls
417+
if (value != null || !propertyType.isPrimitive()) {
418+
metaObject.setValue(property, value);
419+
}
420+
foundValues = true;
421421
}
422422
}
423423
}

src/test/java/org/apache/ibatis/submitted/call_setters_on_nulls/CallSettersOnNullsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void shouldCallNullOnMapForSingleColumn() {
9595
try {
9696
Mapper mapper = sqlSession.getMapper(Mapper.class);
9797
List<Map<String, Object>> oneColumns = mapper.getNameOnly();
98-
Assert.assertNull(oneColumns.get(1));
98+
Assert.assertNotNull(oneColumns.get(1));
9999
} finally {
100100
sqlSession.close();
101101
}

0 commit comments

Comments
 (0)