On 30 October 2013 14:38, <ma...@apache.org> wrote: > 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")
It would be helpful to add a comment as to why it is safe to suppress the warning, or if not, what is done about the CCE. In this case it looks as though the CCE is handled by the Exception catch below, but this should be documented so it is clear that this is intentional. > + 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"); > } > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org