You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2016/05/18 20:37:10 UTC

[Bug 59569] New: isWrapperFor/unwrap implementations incorrect

https://bz.apache.org/bugzilla/show_bug.cgi?id=59569

            Bug ID: 59569
           Summary: isWrapperFor/unwrap implementations incorrect
           Product: Tomcat Modules
           Version: unspecified
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: jdbc-pool
          Assignee: dev@tomcat.apache.org
          Reporter: batterseapower@hotmail.com

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);
       }
   }

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org