Skip to content

Commit 38cda36

Browse files
committed
Circumvent AutoClosable in transactional proxies only when the class implements AutoClosable
1 parent a54c8f3 commit 38cda36

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

core/src/main/java/org/seedstack/seed/core/internal/transaction/TransactionalClassProxy.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
package org.seedstack.seed.core.internal.transaction;
910

1011
import java.lang.reflect.InvocationTargetException;
@@ -42,7 +43,9 @@ public static <T> T create(Class<T> clazz, final TransactionalLink<T> transactio
4243
try {
4344
ProxyFactory factory = new ProxyFactory();
4445
factory.setSuperclass(clazz);
45-
factory.setInterfaces(new Class<?>[]{IgnoreAutoCloseable.class});
46+
if (AutoCloseable.class.isAssignableFrom(clazz)) {
47+
factory.setInterfaces(new Class<?>[]{IgnoreAutoCloseable.class});
48+
}
4649
factory.setFilter(method -> !method.getDeclaringClass().equals(Object.class));
4750
return (T) factory.create(new Class<?>[0], new Object[0], new TransactionalClassProxy<>(transactionalLink));
4851
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {

core/src/main/java/org/seedstack/seed/core/internal/transaction/TransactionalProxy.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
package org.seedstack.seed.core.internal.transaction;
910

1011
import java.lang.reflect.InvocationHandler;
@@ -38,8 +39,13 @@ private TransactionalProxy(TransactionalLink<T> transactionalLink) {
3839
*/
3940
@SuppressWarnings("unchecked")
4041
public static <T> T create(Class<T> clazz, TransactionalLink<T> transactionalLink) {
41-
return (T) Proxy.newProxyInstance(TransactionalProxy.class.getClassLoader(),
42-
new Class<?>[]{IgnoreAutoCloseable.class, clazz}, new TransactionalProxy<>(transactionalLink));
42+
if (AutoCloseable.class.isAssignableFrom(clazz)) {
43+
return (T) Proxy.newProxyInstance(TransactionalProxy.class.getClassLoader(),
44+
new Class<?>[]{IgnoreAutoCloseable.class, clazz}, new TransactionalProxy<>(transactionalLink));
45+
} else {
46+
return (T) Proxy.newProxyInstance(TransactionalProxy.class.getClassLoader(),
47+
new Class<?>[]{clazz}, new TransactionalProxy<>(transactionalLink));
48+
}
4349
}
4450

4551
@Override

0 commit comments

Comments
 (0)