Allow null method for getTransactionAttribute

Update MatchAlwaysTransactionAttributeSource.getTransactionAttribute
to allow a null method argument. Passing a null method is not
recommended and is not indicated as valid in the Javadoc, however,
this was allowed in previous versions of Spring.

Issue: SPR-11048
master
Phillip Webb 11 years ago
parent 5d8fac86d7
commit d371886988
  1. 8
      spring-core/src/main/java/org/springframework/util/ClassUtils.java
  2. 2
      spring-tx/src/main/java/org/springframework/transaction/interceptor/MatchAlwaysTransactionAttributeSource.java
  3. 10
      spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionAttributeSourceTests.java

@ -778,8 +778,12 @@ public abstract class ClassUtils {
* @return {@code true} if the method can be considered as user-declared; [@code false} otherwise
*/
public static boolean isUserLevelMethod(Method method) {
return (method.isBridge() ||
(!method.isSynthetic() && !method.getDeclaringClass().getName().equals("groovy.lang.GroovyObject")));
Assert.notNull(method, "Method must not be null");
return (method.isBridge() || (!method.isSynthetic() && !isGroovyObjectMethod(method)));
}
private static boolean isGroovyObjectMethod(Method method) {
return method.getDeclaringClass().getName().equals("groovy.lang.GroovyObject");
}
/**

@ -53,7 +53,7 @@ public class MatchAlwaysTransactionAttributeSource implements TransactionAttribu
@Override
public TransactionAttribute getTransactionAttribute(Method method, Class<?> targetClass) {
return (ClassUtils.isUserLevelMethod(method) ? this.transactionAttribute : null);
return (method == null || ClassUtils.isUserLevelMethod(method) ? this.transactionAttribute : null);
}

@ -54,6 +54,16 @@ public final class TransactionAttributeSourceTests {
assertTrue(TransactionDefinition.PROPAGATION_SUPPORTS == ta.getPropagationBehavior());
}
@Test
public void testMatchAlwaysTransactionAttributeSourceWithNulls() throws Exception {
MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource();
TransactionDefinition definition = tas.getTransactionAttribute(null, null);
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, definition.getPropagationBehavior());
assertEquals(TransactionDefinition.ISOLATION_DEFAULT, definition.getIsolationLevel());
assertEquals(TransactionDefinition.TIMEOUT_DEFAULT, definition.getTimeout());
assertFalse(definition.isReadOnly());
}
@SuppressWarnings("unchecked")
@Ignore // no longer works now that setMethodMap has been parameterized
@Test

Loading…
Cancel
Save