Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a thread safety problem introduced by DBUTILS-124. #3

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/main/java/org/apache/commons/dbutils/BeanProcessor.java
Expand Up @@ -65,19 +65,9 @@ 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);
private static final List<PropertyHandler> propertyHandlers = new ArrayList<PropertyHandler>();

/**
* ResultSet column to bean property name overrides.
Expand All @@ -93,6 +83,14 @@ public class BeanProcessor {
primitiveDefaults.put(Long.TYPE, Long.valueOf(0L));
primitiveDefaults.put(Boolean.TYPE, Boolean.FALSE);
primitiveDefaults.put(Character.TYPE, Character.valueOf((char) 0));

for (ColumnHandler h : ServiceLoader.load(ColumnHandler.class)) {
columnHandlers.add(h);
}

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

/**
Expand Down