[ http://issues.apache.org/jira/browse/DBCP-80?page=all ]
Brett Porter updated DBCP-80:
-----------------------------
Bugzilla Id: (was: 24082)
Reporter: Brett Porter (was: Brett Porter)
> NumberFormatException: For input string: "myDB" in
> InstanceKeyDataSourceFactory
> -------------------------------------------------------------------------------
>
> Key: DBCP-80
> URL: http://issues.apache.org/jira/browse/DBCP-80
> Project: Commons Dbcp
> Issue Type: Bug
> Affects Versions: 1.1 Final
> Environment: Operating System: All
> Platform: All
> Reporter: Brett Porter
> Priority: Blocker
> Attachments: bug-24082-patch.diff
>
>
> 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:
> InstanceKeyDataSourceFactory.getObjectInstance()
> ...
> 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 = i.next();
> 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? I've done
> this and it seems to work, so I'll attach that quick fix as a patch.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]