Skip to content

DelegatingDataSource incorrectly implements java.sql.Wrapper [SPR-9770] #14404

@spring-projects-issues

Description

@spring-projects-issues

Juan M. Tula opened SPR-9770 and commented

Status Quo

Spring's DelegatingDataSource does not correctly implement the java.sql.Wrapper interface.

Analysis

According to the documentation for the unwrap() and isWrapper() methods, if the receiver implements the received interface, it should return itself, something like this:

public <T> T unwrap(Class<T> iface) throws SQLException {
	T result;
	if(iface.isInstance(this)) {
		result = iface.cast(this);
	} else {
		result = getTargetDataSource().unwrap(iface);
	}
	return result;
}

But the implementation is currently this:

public <T> T unwrap(Class<T> iface) throws SQLException {
	return getTargetDataSource().unwrap(iface);
}

So, a call to new DelegatingDataSource().unwrap(DelegatingDataSource.class) will fail instead of returning itself.


Affects: 3.1 GA

Reference URL: http://docs.oracle.com/javase/6/docs/api/java/sql/Wrapper.html?is-external=true

Issue Links:

0 votes, 6 watchers

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions