Bug 59569 - isWrapperFor/unwrap implementations incorrect
Summary: isWrapperFor/unwrap implementations incorrect
Status: NEW
Alias: None
Product: Tomcat Modules
Classification: Unclassified
Component: jdbc-pool (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2016-05-18 20:37 UTC by Max Bolingbroke
Modified: 2016-05-18 20:37 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Max Bolingbroke 2016-05-18 20:37:10 UTC
In org.apache.tomcat.jdbc.pool.DataSourceProxy, isWrapperFor/unwrap always return false/null respectively. This is a spec violation, not least becaues unwrap should throw instead of returning null.

A similar issue affects org.apache.tomcat.jdbc.pool.ProxyConnection.

Correct implementations of these functions should look something like this (for DataSourceProxy):

   @SuppressWarnings("unused") // Has to match signature in DataSource
   public boolean isWrapperFor(Class<?> iface) throws SQLException {
       return poolProperties.getDataSource() instanceof DataSource && ((DataSource)poolProperties.getDataSource()).isWrapperFor(iface);

   @SuppressWarnings("unused") // Has to match signature in DataSource
   public <T> T unwrap(Class<T> iface) throws SQLException {
       if (poolProperties.getDataSource() instanceof DataSource) {
           return ((DataSource)poolProperties.getDataSource()).unwrap(iface);
       } else {
           throw new SQLException("Not a wrapper for " + iface);

And for ProxyConnection:

   public boolean isWrapperFor(Class<?> iface) throws SQLException {
       if (iface == XAConnection.class && connection.getXAConnection()!=null) {
           return true;
       } else {
           return connection.getConnection().isWrapperFor(iface);

   public Object unwrap(Class<?> iface) throws SQLException {
       if (iface == PooledConnection.class) {
           return connection;
       }else if (iface == XAConnection.class) {
           return connection.getXAConnection();
       } else {
           return connection.getConnection().unwrap(iface);