commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hdevalke <...@git.apache.org>
Subject [GitHub] commons-dbutils pull request #3: Fixes a thread safety problem introduced by...
Date Tue, 10 Oct 2017 19:47:34 GMT
Github user hdevalke commented on a diff in the pull request:

    https://github.com/apache/commons-dbutils/pull/3#discussion_r143833029
  
    --- Diff: src/main/java/org/apache/commons/dbutils/BeanProcessor.java ---
    @@ -65,19 +65,21 @@
          */
         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);
    --- End diff --
    
    I didn't see there was already a static block initializing `primitiveDefaults`. I find
it more readable initializing each static variable in their own block. I did an update and
put all in one static block.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message