commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1537543 - /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
Date Thu, 31 Oct 2013 16:12:55 GMT
Author: sebb
Date: Thu Oct 31 16:12:55 2013
New Revision: 1537543

URL: http://svn.apache.org/r1537543
Log:
Rework to avoid unchecked cast warnings

Modified:
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java?rev=1537543&r1=1537542&r2=1537543&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java Thu Oct
31 16:12:55 2013
@@ -1738,23 +1738,21 @@ public class BasicDataSource implements 
         Driver driverToUse = this.driver;
 
         if (driverToUse == null) {
-            Class<Driver> driverFromCCL = null;
+            Class<?> driverFromCCL = null;
             if (driverClassName != null) {
                 try {
                     try {
                         if (driverClassLoader == null) {
-                            driverFromCCL = (Class<Driver>) Class.forName(driverClassName);
+                            driverFromCCL = Class.forName(driverClassName);
                         } else {
-                            driverFromCCL = (Class<Driver>) Class.forName(
+                            driverFromCCL = Class.forName(
                                     driverClassName, true, driverClassLoader);
                         }
                     } catch (ClassNotFoundException cnfe) {
-                        driverFromCCL = (Class<Driver>) Thread.currentThread(
+                        driverFromCCL = Thread.currentThread(
                                 ).getContextClassLoader().loadClass(
                                         driverClassName);
                     }
-                	// N.B. the casts above may cause ClassCastException if classname is not
correct
-                	// This is caught below
                 } catch (Exception t) {
                     String message = "Cannot load JDBC driver class '" +
                         driverClassName + "'";
@@ -1770,7 +1768,8 @@ public class BasicDataSource implements 
                 } else {
                     // Usage of DriverManager is not possible, as it does not
                     // respect the ContextClassLoader
-                    driverToUse = driverFromCCL.newInstance();
+                	// N.B. This cast may cause ClassCastException which is handled below
+                    driverToUse = (Driver) driverFromCCL.newInstance();
                     if (!driverToUse.acceptsURL(url)) {
                         throw new SQLException("No suitable driver", "08001");
                     }



Mime
View raw message