Skip to content

Commit c44bb29

Browse files
committed
Polishing
1 parent 0c22866 commit c44bb29

File tree

6 files changed

+58
-78
lines changed

6 files changed

+58
-78
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -333,12 +333,12 @@ public boolean matches(Method method, Class<?> targetClass, Object... args) {
333333
Object targetObject = null;
334334
Object thisObject = null;
335335
try {
336-
MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
337-
targetObject = mi.getThis();
338-
if (!(mi instanceof ProxyMethodInvocation _pmi)) {
339-
throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
336+
MethodInvocation curr = ExposeInvocationInterceptor.currentInvocation();
337+
targetObject = curr.getThis();
338+
if (!(curr instanceof ProxyMethodInvocation currPmi)) {
339+
throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + curr);
340340
}
341-
pmi = _pmi;
341+
pmi = currPmi;
342342
thisObject = pmi.getProxy();
343343
}
344344
catch (IllegalStateException ex) {

spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutTests.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323

2424
import org.aopalliance.intercept.MethodInterceptor;
2525
import org.aopalliance.intercept.MethodInvocation;
26-
import org.aspectj.weaver.tools.PointcutExpression;
2726
import org.aspectj.weaver.tools.PointcutPrimitive;
2827
import org.aspectj.weaver.tools.UnsupportedPointcutPrimitiveException;
2928
import org.junit.jupiter.api.BeforeEach;
@@ -65,7 +64,7 @@ public class AspectJExpressionPointcutTests {
6564

6665

6766
@BeforeEach
68-
public void setUp() throws NoSuchMethodException {
67+
public void setup() throws NoSuchMethodException {
6968
getAge = TestBean.class.getMethod("getAge");
7069
setAge = TestBean.class.getMethod("setAge", int.class);
7170
setSomeNumber = TestBean.class.getMethod("setSomeNumber", Number.class);
@@ -246,14 +245,13 @@ public void testDynamicMatchingProxy() {
246245
@Test
247246
public void testInvalidExpression() {
248247
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number) && args(Double)";
249-
assertThatIllegalArgumentException().isThrownBy(
250-
getPointcut(expression)::getClassFilter); // call to getClassFilter forces resolution
248+
assertThatIllegalArgumentException().isThrownBy(getPointcut(expression)::getClassFilter); // call to getClassFilter forces resolution
251249
}
252250

253251
private TestBean getAdvisedProxy(String pointcutExpression, CallCountingInterceptor interceptor) {
254252
TestBean target = new TestBean();
255253

256-
Pointcut pointcut = getPointcut(pointcutExpression);
254+
AspectJExpressionPointcut pointcut = getPointcut(pointcutExpression);
257255

258256
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
259257
advisor.setAdvice(interceptor);
@@ -277,40 +275,31 @@ private void assertMatchesTestBeanClass(ClassFilter classFilter) {
277275
@Test
278276
public void testWithUnsupportedPointcutPrimitive() {
279277
String expression = "call(int org.springframework.beans.testfixture.beans.TestBean.getAge())";
280-
assertThatExceptionOfType(UnsupportedPointcutPrimitiveException.class).isThrownBy(() ->
281-
getPointcut(expression).getClassFilter()) // call to getClassFilter forces resolution...
282-
.satisfies(ex -> assertThat(ex.getUnsupportedPrimitive()).isEqualTo(PointcutPrimitive.CALL));
278+
assertThatExceptionOfType(UnsupportedPointcutPrimitiveException.class)
279+
.isThrownBy(() -> getPointcut(expression).getClassFilter()) // call to getClassFilter forces resolution...
280+
.satisfies(ex -> assertThat(ex.getUnsupportedPrimitive()).isEqualTo(PointcutPrimitive.CALL));
283281
}
284282

285283
@Test
286284
public void testAndSubstitution() {
287-
Pointcut pc = getPointcut("execution(* *(..)) and args(String)");
288-
PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
289-
assertThat(expr.getPointcutExpression()).isEqualTo("execution(* *(..)) && args(String)");
285+
AspectJExpressionPointcut pc = getPointcut("execution(* *(..)) and args(String)");
286+
String expr = pc.getPointcutExpression().getPointcutExpression();
287+
assertThat(expr).isEqualTo("execution(* *(..)) && args(String)");
290288
}
291289

292290
@Test
293291
public void testMultipleAndSubstitutions() {
294-
Pointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)");
295-
PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
296-
assertThat(expr.getPointcutExpression()).isEqualTo("execution(* *(..)) && args(String) && this(Object)");
292+
AspectJExpressionPointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)");
293+
String expr = pc.getPointcutExpression().getPointcutExpression();
294+
assertThat(expr).isEqualTo("execution(* *(..)) && args(String) && this(Object)");
297295
}
298296

299-
private Pointcut getPointcut(String expression) {
297+
private AspectJExpressionPointcut getPointcut(String expression) {
300298
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
301299
pointcut.setExpression(expression);
302300
return pointcut;
303301
}
304302

305-
306-
public static class OtherIOther implements IOther {
307-
308-
@Override
309-
public void absquatulate() {
310-
// Empty
311-
}
312-
}
313-
314303
@Test
315304
public void testMatchGenericArgument() {
316305
String expression = "execution(* set*(java.util.List<org.springframework.beans.testfixture.beans.TestBean>) )";
@@ -505,6 +494,15 @@ public void testAnnotationOnMethodArgumentsWithWildcards() throws Exception {
505494
}
506495

507496

497+
public static class OtherIOther implements IOther {
498+
499+
@Override
500+
public void absquatulate() {
501+
// Empty
502+
}
503+
}
504+
505+
508506
public static class HasGeneric {
509507

510508
public void setFriends(List<TestBean> friends) {

spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -595,7 +595,6 @@ public void refresh() throws BeansException, IllegalStateException {
595595
StartupStep beanPostProcess = this.applicationStartup.start("spring.context.beans.post-process");
596596
// Invoke factory processors registered as beans in the context.
597597
invokeBeanFactoryPostProcessors(beanFactory);
598-
599598
// Register bean processors that intercept bean creation.
600599
registerBeanPostProcessors(beanFactory);
601600
beanPostProcess.end();

spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests.java

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -220,16 +220,16 @@ void cglibProxyClassIsCachedAcrossApplicationContextsForPerTargetAspect() {
220220
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(configClass)) {
221221
testBean1 = context.getBean(TestBean.class);
222222
assertThat(AopUtils.isCglibProxy(testBean1)).as("CGLIB proxy").isTrue();
223-
assertThat(testBean1.getClass().getInterfaces())
224-
.containsExactlyInAnyOrder(Factory.class, SpringProxy.class, Advised.class);
223+
assertThat(testBean1.getClass().getInterfaces()).containsExactlyInAnyOrder(
224+
Factory.class, SpringProxy.class, Advised.class);
225225
}
226226

227227
// Round #2
228228
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(configClass)) {
229229
testBean2 = context.getBean(TestBean.class);
230230
assertThat(AopUtils.isCglibProxy(testBean2)).as("CGLIB proxy").isTrue();
231-
assertThat(testBean2.getClass().getInterfaces())
232-
.containsExactlyInAnyOrder(Factory.class, SpringProxy.class, Advised.class);
231+
assertThat(testBean2.getClass().getInterfaces()).containsExactlyInAnyOrder(
232+
Factory.class, SpringProxy.class, Advised.class);
233233
}
234234

235235
assertThat(testBean1.getClass()).isSameAs(testBean2.getClass());
@@ -344,8 +344,8 @@ void lambdaIsAlwaysProxiedWithJdkProxy(Class<?> configClass) {
344344
Supplier<String> supplier = context.getBean(Supplier.class);
345345
assertThat(AopUtils.isAopProxy(supplier)).as("AOP proxy").isTrue();
346346
assertThat(AopUtils.isJdkDynamicProxy(supplier)).as("JDK Dynamic proxy").isTrue();
347-
assertThat(supplier.getClass().getInterfaces())
348-
.containsExactlyInAnyOrder(Supplier.class, SpringProxy.class, Advised.class, DecoratingProxy.class);
347+
assertThat(supplier.getClass().getInterfaces()).containsExactlyInAnyOrder(
348+
Supplier.class, SpringProxy.class, Advised.class, DecoratingProxy.class);
349349
assertThat(supplier.get()).isEqualTo("advised: lambda");
350350
}
351351
}
@@ -357,26 +357,14 @@ void lambdaIsAlwaysProxiedWithJdkProxyWithIntroductions(Class<?> configClass) {
357357
MessageGenerator messageGenerator = context.getBean(MessageGenerator.class);
358358
assertThat(AopUtils.isAopProxy(messageGenerator)).as("AOP proxy").isTrue();
359359
assertThat(AopUtils.isJdkDynamicProxy(messageGenerator)).as("JDK Dynamic proxy").isTrue();
360-
assertThat(messageGenerator.getClass().getInterfaces())
361-
.containsExactlyInAnyOrder(MessageGenerator.class, Mixin.class, SpringProxy.class, Advised.class, DecoratingProxy.class);
360+
assertThat(messageGenerator.getClass().getInterfaces()).containsExactlyInAnyOrder(
361+
MessageGenerator.class, Mixin.class, SpringProxy.class, Advised.class, DecoratingProxy.class);
362362
assertThat(messageGenerator.generateMessage()).isEqualTo("mixin: lambda");
363363
}
364364
}
365365

366-
/**
367-
* Returns a new {@link ClassPathXmlApplicationContext} for the file ending in <var>fileSuffix</var>.
368-
*/
369366
private ClassPathXmlApplicationContext newContext(String fileSuffix) {
370-
return new ClassPathXmlApplicationContext(qName(fileSuffix), getClass());
371-
}
372-
373-
/**
374-
* Returns the relatively qualified name for <var>fileSuffix</var>.
375-
* e.g. for a fileSuffix='foo.xml', this method will return
376-
* 'AspectJAutoProxyCreatorTests-foo.xml'
377-
*/
378-
private String qName(String fileSuffix) {
379-
return String.format("%s-%s", getClass().getSimpleName(), fileSuffix);
367+
return new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-" + fileSuffix, getClass());
380368
}
381369

382370
}
@@ -416,7 +404,6 @@ class DummyAspectWithParameter {
416404
public Object test(ProceedingJoinPoint pjp, int age) throws Throwable {
417405
return pjp.proceed();
418406
}
419-
420407
}
421408

422409
class DummyFactoryBean implements FactoryBean<Object> {
@@ -435,7 +422,6 @@ public Class<?> getObjectType() {
435422
public boolean isSingleton() {
436423
throw new UnsupportedOperationException();
437424
}
438-
439425
}
440426

441427
@Aspect
@@ -591,7 +577,6 @@ public int unreliable() {
591577
}
592578
return this.calls;
593579
}
594-
595580
}
596581

597582
@SuppressWarnings("serial")
@@ -607,7 +592,6 @@ public TestBeanAdvisor() {
607592
public boolean matches(Method method, @Nullable Class<?> targetClass) {
608593
return ITestBean.class.isAssignableFrom(targetClass);
609594
}
610-
611595
}
612596

613597
abstract class AbstractProxyTargetClassConfig {
@@ -661,6 +645,7 @@ PerTargetAspect perTargetAspect() {
661645

662646
@FunctionalInterface
663647
interface MessageGenerator {
648+
664649
String generateMessage();
665650
}
666651

@@ -678,7 +663,6 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
678663
public boolean implementsInterface(Class<?> intf) {
679664
return Mixin.class.isAssignableFrom(intf);
680665
}
681-
682666
}
683667

684668
@SuppressWarnings("serial")
@@ -708,7 +692,6 @@ public ClassFilter getClassFilter() {
708692
public void validateInterfaces() {
709693
/* no-op */
710694
}
711-
712695
}
713696

714697
abstract class AbstractMixinConfig {
@@ -722,7 +705,6 @@ MessageGenerator messageGenerator() {
722705
MixinAdvisor mixinAdvisor() {
723706
return new MixinAdvisor();
724707
}
725-
726708
}
727709

728710
@Configuration(proxyBeanMethods = false)

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1177,7 +1177,7 @@ public <T> T execute(CallableStatementCreator csc, CallableStatementCallback<T>
11771177
Assert.notNull(action, "Callback object must not be null");
11781178
if (logger.isDebugEnabled()) {
11791179
String sql = getSql(csc);
1180-
logger.debug("Calling stored procedure" + (sql != null ? " [" + sql + "]" : ""));
1180+
logger.debug("Calling stored procedure" + (sql != null ? " [" + sql + "]" : ""));
11811181
}
11821182

11831183
Connection con = DataSourceUtils.getConnection(obtainDataSource());

spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -87,8 +87,8 @@ void errorCodeTranslation() {
8787
SQLException dupKeyEx = new SQLException("", "", 10);
8888
DataAccessException dataAccessException = translator.translate("task", "SQL", dupKeyEx);
8989
assertThat(dataAccessException)
90-
.isInstanceOf(DataIntegrityViolationException.class)
91-
.hasCause(dupKeyEx);
90+
.isInstanceOf(DataIntegrityViolationException.class)
91+
.hasCause(dupKeyEx);
9292

9393
// Test fallback. We assume that no database will ever return this error code,
9494
// but 07xxx will be bad grammar picked up by the fallback SQLState translator
@@ -102,8 +102,8 @@ private void checkTranslation(int errorCode, Class<? extends Exception> expected
102102
SQLException sqlException = new SQLException("", "", errorCode);
103103
DataAccessException dataAccessException = this.translator.translate("", "", sqlException);
104104
assertThat(dataAccessException)
105-
.isInstanceOf(expectedType)
106-
.hasCause(sqlException);
105+
.isInstanceOf(expectedType)
106+
.hasCause(sqlException);
107107
}
108108

109109
@Test
@@ -122,8 +122,8 @@ void dataTruncationTranslation() {
122122
DataTruncation dataTruncation = new DataTruncation(1, true, true, 1, 1, dataAccessEx);
123123
DataAccessException dataAccessException = translator.translate("task", "SQL", dataTruncation);
124124
assertThat(dataAccessException)
125-
.isInstanceOf(DataAccessResourceFailureException.class)
126-
.hasCause(dataTruncation);
125+
.isInstanceOf(DataAccessResourceFailureException.class)
126+
.hasCause(dataTruncation);
127127
}
128128

129129
@Test
@@ -153,8 +153,8 @@ protected DataAccessException customTranslate(String task, @Nullable String sql,
153153
// Shouldn't custom translate this
154154
DataAccessException dataAccessException = translator.translate(TASK, SQL, integrityViolationEx);
155155
assertThat(dataAccessException)
156-
.isInstanceOf(DataIntegrityViolationException.class)
157-
.hasCause(integrityViolationEx);
156+
.isInstanceOf(DataIntegrityViolationException.class)
157+
.hasCause(integrityViolationEx);
158158
}
159159

160160
@Test
@@ -176,15 +176,15 @@ void customExceptionTranslation() {
176176
SQLException badSqlEx = new SQLException("", "", 1);
177177
DataAccessException dataAccessException = translator.translate(TASK, SQL, badSqlEx);
178178
assertThat(dataAccessException)
179-
.isInstanceOf(CustomErrorCodeException.class)
180-
.hasCause(badSqlEx);
179+
.isInstanceOf(CustomErrorCodeException.class)
180+
.hasCause(badSqlEx);
181181

182182
// Shouldn't custom translate this
183183
SQLException invResEx = new SQLException("", "", 3);
184184
dataAccessException = translator.translate(TASK, SQL, invResEx);
185185
assertThat(dataAccessException)
186-
.isInstanceOf(DataIntegrityViolationException.class)
187-
.hasCause(invResEx);
186+
.isInstanceOf(DataIntegrityViolationException.class)
187+
.hasCause(invResEx);
188188

189189
// Shouldn't custom translate this - invalid class
190190
assertThatIllegalArgumentException().isThrownBy(() -> customTranslation.setExceptionClass(String.class));
@@ -209,7 +209,8 @@ void dataSourceInitialization() throws Exception {
209209

210210
reset(dataSource);
211211
given(dataSource.getConnection()).willReturn(connection);
212-
assertThat(translator.translate("test", null, duplicateKeyException)).isInstanceOf(DuplicateKeyException.class);
212+
assertThat(translator.translate("test", null, duplicateKeyException))
213+
.isInstanceOf(DuplicateKeyException.class);
213214

214215
verify(connection).close();
215216
}

0 commit comments

Comments
 (0)