commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brett Porter <>
Subject DBCP 1.1: bug in InstanceKeyDataSourceFactory
Date Thu, 23 Oct 2003 06:42:36 GMT
I took DBCP 1.1 for a spin today (I was going to try CVS today, but for the
release - if only it had been earlier! :)
There's a fatal bug in InstanceKeyDataSourceFactory that means you can't
instantiate more than one factory. I'm using this via Tomcat 4.
There is this function that is called first:
                    String key = null;
                    if (name != null) 
                        key = name.toString();
                        obj = instanceMap.get(key); 
                    if (obj == null)
                        InstanceKeyDataSource ds = getNewInstance(ref);
                        setCommonProperties(ref, ds);
                        obj = ds;
                        if (key != null) 
                            instanceMap.put(key, ds);

So, key = something like "myDb", which is put into instanceMap.
But then there is:
    synchronized static String registerNewInstance(InstanceKeyDataSource ds)
        int max = 0;
        Iterator i = instanceMap.keySet().iterator();
        while (i.hasNext()) {
            Object obj =;
            if (obj instanceof String) 
                max = Math.max(max, Integer.parseInt((String)obj));
        String instanceKey = String.valueOf(max + 1);
        // put a placeholder here for now, so other instances will not
        // take our key.  we will replace with a pool when ready.
        instanceMap.put(instanceKey, ds);
        return instanceKey;

The Math.max line throws a NumberFormatException, because the key is assumed
to be an int, but it is "myDb".
What is the way to resolve this? My feeling is that it just doesn't set max
if the key is not a number, so the first one gets "0", etc. Is that ok?
Brett Porter
Team Leader, Core Systems
f2 network ~ everything essential

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message