Skip to content

Commit

Permalink
Fixes a thread safety problem introduced by DBUTILS-124.
Browse files Browse the repository at this point in the history
ColumnHandlers and PropertyHandlers are preloaded in a list as the ServiceLoader instances are not thread safe
  • Loading branch information
hdevalke committed Oct 5, 2017
1 parent 5dad813 commit 59d1140
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/main/java/org/apache/commons/dbutils/BeanProcessor.java
Expand Up @@ -65,19 +65,21 @@ public class BeanProcessor {
*/
private static final Map<Class<?>, Object> primitiveDefaults = new HashMap<Class<?>, Object>();

/**
* ServiceLoader to find <code>ColumnHandler</code> implementations on the classpath. The iterator for this is
* lazy and each time <code>iterator()</code> is called.
*/
// FIXME: I think this instantiates new handlers on each iterator() call. This might be worth caching upfront.
private static final ServiceLoader<ColumnHandler> columnHandlers = ServiceLoader.load(ColumnHandler.class);
private static final List<ColumnHandler> columnHandlers = new ArrayList<ColumnHandler>();

/**
* ServiceLoader to find <code>PropertyHandler</code> implementations on the classpath. The iterator for this is
* lazy and each time <code>iterator()</code> is called.
*/
// FIXME: I think this instantiates new handlers on each iterator() call. This might be worth caching upfront.
private static final ServiceLoader<PropertyHandler> propertyHandlers = ServiceLoader.load(PropertyHandler.class);
static{
for (ColumnHandler h : ServiceLoader.load(ColumnHandler.class)) {
columnHandlers.add(h);
}
}

private static final List<PropertyHandler> propertyHandlers = new ArrayList<PropertyHandler>();

static {
for (PropertyHandler h : ServiceLoader.load(PropertyHandler.class)) {
propertyHandlers.add(h);
}
}

/**
* ResultSet column to bean property name overrides.
Expand Down

0 comments on commit 59d1140

Please sign in to comment.