Skip to content

Commit 1712d69

Browse files
committed
Closes #16. Skip final static fields.
1 parent 150db6d commit 1712d69

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ protected boolean applyAutomaticMappings(ResultSet rs, List<String> unmappedColu
346346
}
347347
}
348348
final String property = metaObject.findProperty(propertyName, configuration.isMapUnderscoreToCamelCase());
349-
if (property != null &&metaObject.hasSetter(property) ) {
349+
if (property != null && metaObject.hasSetter(property)) {
350350
final Class<?> propertyType = metaObject.getSetterType(property);
351351
if (typeHandlerRegistry.hasTypeHandler(propertyType)) {
352352
final TypeHandler<?> typeHandler = resultColumnCache.getTypeHandler(propertyType, columnName);

src/main/java/org/apache/ibatis/reflection/Reflector.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,15 @@ private void addFields(Class<?> clazz) {
225225
// Ignored. This is only a final precaution, nothing we can do.
226226
}
227227
}
228-
int modifier=field.getModifiers();
229-
// issue 379 - removed the check for final because JDK 1.5 allows
230-
// modification of final fields through reflection (JSR-133). (JGB)
231-
// allow final but not final static
232-
if (field.isAccessible() && !(Modifier.isFinal(modifier) && Modifier.isStatic(modifier))) {
233-
if (!setMethods.containsKey(field.getName())) {
234-
addSetField(field);
228+
if (field.isAccessible()) {
229+
if (!setMethods.containsKey(field.getName())) {
230+
// issue #379 - removed the check for final because JDK 1.5 allows
231+
// modification of final fields through reflection (JSR-133). (JGB)
232+
// pr #16 - final static can only be set by the classloader
233+
int modifiers = field.getModifiers();
234+
if (!(Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers))) {
235+
addSetField(field);
236+
}
235237
}
236238
if (!getMethods.containsKey(field.getName())) {
237239
addGetField(field);

src/test/java/org/apache/ibatis/submitted/automapping/Book.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
package org.apache.ibatis.submitted.automapping;
1717

1818
public class Book {
19-
public static final Integer version=0;
20-
private String name;
19+
public static final Integer version = 0;
20+
private String name;
2121

22-
public String getName() {
23-
return name;
24-
}
22+
public String getName() {
23+
return name;
24+
}
2525

26-
public void setName(String name) {
27-
this.name = name;
28-
}
26+
public void setName(String name) {
27+
this.name = name;
28+
}
2929

3030
}

src/test/java/org/apache/ibatis/submitted/automapping/Mapper.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</resultMap>
3333

3434
<select id="getBooks" resultMap="bookResult">
35-
select version,name from books
35+
select version, name from books
3636
</select>
3737

3838
<select id="getArticle" resultType="org.apache.ibatis.submitted.automapping.Article">

0 commit comments

Comments
 (0)