commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1537111 - /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
Date Wed, 30 Oct 2013 14:38:54 GMT
Author: markt
Date: Wed Oct 30 14:38:54 2013
New Revision: 1537111

URL: http://svn.apache.org/r1537111
Log:
Use generics. Structure code so explicit @SuppressWarnings annotations can be used rather
than adding one that covers the entire method.

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=1537111&r1=1537110&r2=1537111&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 Wed Oct
30 14:38:54 2013
@@ -1691,20 +1691,27 @@ public class BasicDataSource implements 
      */
     protected ConnectionFactory createConnectionFactory() throws SQLException {
         // Load the JDBC driver class
-        Class driverFromCCL = null;
+        Class<Driver> driverFromCCL = null;
         if (driverClassName != null) {
             try {
                 try {
                     if (driverClassLoader == null) {
-                        driverFromCCL = Class.forName(driverClassName);
+                        @SuppressWarnings("unchecked")
+                        Class<Driver> c =
+                                (Class<Driver>) Class.forName(driverClassName);
+                        driverFromCCL = c;
                     } else {
-                        driverFromCCL = Class.forName(
+                        @SuppressWarnings("unchecked")
+                        Class<Driver> c = (Class<Driver>) Class.forName(
                                 driverClassName, true, driverClassLoader);
+                        driverFromCCL = c;
                     }
                 } catch (ClassNotFoundException cnfe) {
-                    driverFromCCL = Thread.currentThread(
+                    @SuppressWarnings("unchecked")
+                    Class<Driver> c = (Class<Driver>) Thread.currentThread(
                             ).getContextClassLoader().loadClass(
                                     driverClassName);
+                    driverFromCCL = c;
                 }
             } catch (Exception t) {
                 String message = "Cannot load JDBC driver class '" +
@@ -1723,7 +1730,7 @@ public class BasicDataSource implements 
             } else {
                 // Usage of DriverManager is not possible, as it does not
                 // respect the ContextClassLoader
-                driver = (Driver) driverFromCCL.newInstance();
+                driver = driverFromCCL.newInstance();
                 if (!driver.acceptsURL(url)) {
                     throw new SQLException("No suitable driver", "08001");
                 }



Mime
View raw message