Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unreachable code from TransactionTemplate [SPR-10148] #14781

Closed
spring-projects-issues opened this issue Jan 6, 2013 · 3 comments
Closed
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: declined A suggestion or change that we don't feel we should currently apply type: task A general task

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 6, 2013

Elad Tabak opened SPR-10148 and commented

The method org.springframework.transaction.support.TransactionTemplate.exectue() have dead code where calling upon the TransactionCallback.doInTransaction() is surrounded with 'try/catch', only the last "catch" for "Exception" is unnecessary, since the "doInTransaction()" does not declare any checked exception to be thrown.
The last "catch" statement is actually dead/unreachable code, since only RuntimeExceptions and Errors can be thrown from the "doInTransaction" method.


Affects: 3.1.3

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 7, 2013

Juergen Hoeller commented

It's odd but this catch Exception block is necessary since reflectively called constructors in a TransactionCallback implementation may leak a catched Exception even through a signature that doesn't declare it. See #11027.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Elad Tabak commented

When you say "reflectively called constructors", do you mean Class.newInstance() methods? if that is the case then newInstance() throws InstantiationException which is checked exception, hence the TransactionCallback implementation won't compile.

I can see a possible case where you place a java proxy as callback, and the invoke method (of InvocationHandler) can throw Throwable, which may be checked exception.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 7, 2013

Juergen Hoeller commented

See the test case attached to #11027: It seems odd but it actually does make a difference.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: declined A suggestion or change that we don't feel we should currently apply type: task A general task
Projects
None yet
Development

No branches or pull requests

2 participants