Buggy code:
public class DataSourceFactory { private static final Localizer _loc = Localizer . forPackage ( DataSourceFactory . class ) ; protected static Localizer _eloc = Localizer . forPackage ( DelegatingDataSource . class ) ; public static DataSource newDataSource ( JDBCConfiguration conf , boolean factory2 ) { String driver = ( factory2 ) ? conf . getConnection2DriverName ( ) : conf . getConnectionDriverName ( ) ; if ( StringUtils . isEmpty ( driver ) ) throw new org . apache . openjpa . util . UserException ( DataSourceFactory . _loc . get ( "no-driver" , driver ) ) . setFatal ( true ) ; ClassLoader loader = conf . getClassResolverInstance ( ) . getClassLoader ( DataSourceFactory . class , null ) ; String props = ( factory2 ) ? conf . getConnection2Properties ( ) : conf . getConnectionProperties ( ) ; try { Class driverClass ; try { driverClass = Class . forName ( driver , true , loader ) ; } catch ( ClassNotFoundException cnfe ) { driverClass = Class . forName ( driver ) ; } if ( Driver . class . isAssignableFrom ( driverClass ) ) { DriverDataSource ds = conf . newDriverDataSourceInstance ( ) ; ds . setClassLoader ( loader ) ; ds . setConnectionDriverName ( driver ) ; ds . setConnectionProperties ( Configurations . parseProperties ( props ) ) ; if ( ! factory2 ) { ds . setConnectionFactoryProperties ( Configurations . parseProperties ( conf . getConnectionFactoryProperties ( ) ) ) ; ds . setConnectionURL ( conf . getConnectionURL ( ) ) ; ds . setConnectionUserName ( conf . getConnectionUserName ( ) ) ; ds . setConnectionPassword ( conf . getConnectionPassword ( ) ) ; } else { ds . setConnectionFactoryProperties ( Configurations . parseProperties ( conf . getConnectionFactory2Properties ( ) ) ) ; ds . setConnectionURL ( conf . getConnection2URL ( ) ) ; ds . setConnectionUserName ( conf . getConnection2UserName ( ) ) ; ds . setConnectionPassword ( conf . getConnection2Password ( ) ) ; } return ds ; } if ( DataSource . class . isAssignableFrom ( driverClass ) ) { <START_BUG> return ( ( DataSource ) ( Configurations . newInstance ( driver , conf , props , ( ( ClassLoader ) ( AccessController . doPrivileged ( J2DoPrivHelper . getClassLoaderAction ( DataSource . class ) ) ) ) ) ) ) ; <END_BUG> } } catch ( OpenJPAException ke ) { throw ke ; } catch ( Exception e ) { throw DataSourceFactory . newConnectException ( conf , factory2 , e ) ; } throw new org . apache . openjpa . util . UserException ( DataSourceFactory . _loc . get ( "bad-driver" , driver ) ) . setFatal ( true ) ; } public static DecoratingDataSource decorateDataSource ( DataSource ds , JDBCConfiguration conf , boolean factory2 ) { } public static DecoratingDataSource installDBDictionary ( DBDictionary dict , DecoratingDataSource ds , final JDBCConfiguration conf , boolean factory2 ) { } static OpenJPAException newConnectException ( JDBCConfiguration conf , boolean factory2 , Exception cause ) { } public static DataSource defaultsDataSource ( DataSource ds , String user , String pass ) { } public static void closeDataSource ( DataSource ds ) { } private static class DefaultsDataSource extends DelegatingDataSource { private final String _user ; private final String _pass ; public DefaultsDataSource ( DataSource ds , String user , String pass ) { } public Connection getConnection ( ) throws SQLException { } public Connection getConnection ( String user , String pass ) throws SQLException { } } }

Fix:
return ( ( DataSource ) ( Configurations . newInstance ( driver , conf , props , AccessController . doPrivileged ( J2DoPrivHelper . getClassLoaderAction ( DataSource . class ) ) ) ) ) ;