Skip to content

Commit b2d43f5

Browse files
committed
Merge branch '6.1.x'
2 parents 797f586 + bf08e0c commit b2d43f5

File tree

9 files changed

+42
-57
lines changed

9 files changed

+42
-57
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java

+2-30
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.
@@ -18,7 +18,6 @@
1818

1919
import java.lang.annotation.Annotation;
2020
import java.lang.reflect.Constructor;
21-
import java.lang.reflect.Field;
2221
import java.lang.reflect.Method;
2322
import java.util.Map;
2423
import java.util.StringTokenizer;
@@ -56,8 +55,6 @@
5655
*/
5756
public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFactory {
5857

59-
private static final String AJC_MAGIC = "ajc$";
60-
6158
private static final Class<?>[] ASPECTJ_ANNOTATION_CLASSES = new Class<?>[] {
6259
Pointcut.class, Around.class, Before.class, After.class, AfterReturning.class, AfterThrowing.class};
6360

@@ -68,37 +65,11 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
6865
protected final ParameterNameDiscoverer parameterNameDiscoverer = new AspectJAnnotationParameterNameDiscoverer();
6966

7067

71-
/**
72-
* We consider something to be an AspectJ aspect suitable for use by the Spring AOP system
73-
* if it has the @Aspect annotation, and was not compiled by ajc. The reason for this latter test
74-
* is that aspects written in the code-style (AspectJ language) also have the annotation present
75-
* when compiled by ajc with the -1.5 flag, yet they cannot be consumed by Spring AOP.
76-
*/
7768
@Override
7869
public boolean isAspect(Class<?> clazz) {
79-
return (hasAspectAnnotation(clazz) && !compiledByAjc(clazz));
80-
}
81-
82-
private boolean hasAspectAnnotation(Class<?> clazz) {
8370
return (AnnotationUtils.findAnnotation(clazz, Aspect.class) != null);
8471
}
8572

86-
/**
87-
* We need to detect this as "code-style" AspectJ aspects should not be
88-
* interpreted by Spring AOP.
89-
*/
90-
static boolean compiledByAjc(Class<?> clazz) {
91-
// The AJTypeSystem goes to great lengths to provide a uniform appearance between code-style and
92-
// annotation-style aspects. Therefore there is no 'clean' way to tell them apart. Here we rely on
93-
// an implementation detail of the AspectJ compiler.
94-
for (Field field : clazz.getDeclaredFields()) {
95-
if (field.getName().startsWith(AJC_MAGIC)) {
96-
return true;
97-
}
98-
}
99-
return false;
100-
}
101-
10273
@Override
10374
public void validate(Class<?> aspectClass) throws AopConfigException {
10475
AjType<?> ajType = AjTypeSystem.getAjType(aspectClass);
@@ -115,6 +86,7 @@ public void validate(Class<?> aspectClass) throws AopConfigException {
11586
}
11687
}
11788

89+
11890
/**
11991
* Find and return the first AspectJ annotation on the given method
12092
* (there <i>should</i> only be one anyway...).

spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessor.java

+15-2
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.
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.aop.aspectj.annotation;
1818

19+
import java.lang.reflect.Field;
20+
1921
import org.springframework.aot.generate.GenerationContext;
2022
import org.springframework.aot.hint.MemberCategory;
2123
import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
@@ -34,6 +36,8 @@
3436
*/
3537
class AspectJAdvisorBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
3638

39+
private static final String AJC_MAGIC = "ajc$";
40+
3741
private static final boolean aspectjPresent = ClassUtils.isPresent("org.aspectj.lang.annotation.Pointcut",
3842
AspectJAdvisorBeanRegistrationAotProcessor.class.getClassLoader());
3943

@@ -43,13 +47,22 @@ class AspectJAdvisorBeanRegistrationAotProcessor implements BeanRegistrationAotP
4347
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
4448
if (aspectjPresent) {
4549
Class<?> beanClass = registeredBean.getBeanClass();
46-
if (AbstractAspectJAdvisorFactory.compiledByAjc(beanClass)) {
50+
if (compiledByAjc(beanClass)) {
4751
return new AspectJAdvisorContribution(beanClass);
4852
}
4953
}
5054
return null;
5155
}
5256

57+
private static boolean compiledByAjc(Class<?> clazz) {
58+
for (Field field : clazz.getDeclaredFields()) {
59+
if (field.getName().startsWith(AJC_MAGIC)) {
60+
return true;
61+
}
62+
}
63+
return false;
64+
}
65+
5366

5467
private static class AspectJAdvisorContribution implements BeanRegistrationAotContribution {
5568

spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectMetadata.java

+11-5
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.
@@ -124,10 +124,16 @@ public AspectMetadata(Class<?> aspectClass, String aspectName) {
124124
* Extract contents from String of form {@code pertarget(contents)}.
125125
*/
126126
private String findPerClause(Class<?> aspectClass) {
127-
String str = aspectClass.getAnnotation(Aspect.class).value();
128-
int beginIndex = str.indexOf('(') + 1;
129-
int endIndex = str.length() - 1;
130-
return str.substring(beginIndex, endIndex);
127+
Aspect ann = aspectClass.getAnnotation(Aspect.class);
128+
if (ann == null) {
129+
return "";
130+
}
131+
String value = ann.value();
132+
int beginIndex = value.indexOf('(');
133+
if (beginIndex < 0) {
134+
return "";
135+
}
136+
return value.substring(beginIndex + 1, value.length() - 1);
131137
}
132138

133139

spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java

+1-1
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.

spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java

+2-2
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.
@@ -33,7 +33,7 @@
3333
import org.springframework.util.StringUtils;
3434

3535
/**
36-
* The default implementation of Spring's {@link SqlRowSet} interface, wrapping a
36+
* The common implementation of Spring's {@link SqlRowSet} interface, wrapping a
3737
* {@link java.sql.ResultSet}, catching any {@link SQLException SQLExceptions} and
3838
* translating them to a corresponding Spring {@link InvalidResultSetAccessException}.
3939
*

spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java

+1-6
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.
@@ -189,11 +189,6 @@ public void send(Message<?> message) {
189189
}
190190
}
191191

192-
@Override
193-
public void convertAndSend(Object payload) throws MessagingException {
194-
convertAndSend(payload, null);
195-
}
196-
197192
@Override
198193
public void convertAndSend(Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException {
199194
Destination defaultDestination = getDefaultDestination();

spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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.
@@ -290,7 +290,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
290290
* <p>This method should be used carefully, since it will block the thread
291291
* until the message becomes available or until the timeout value is exceeded.
292292
* <p>This will only work with a default destination specified!
293-
* @return the message produced for the consumer or {@code null} if the timeout expires.
293+
* @return the message produced for the consumer, or {@code null} if the timeout expires
294294
* @throws JmsException checked JMSException converted to unchecked
295295
*/
296296
@Nullable
@@ -303,7 +303,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
303303
* <p>This method should be used carefully, since it will block the thread
304304
* until the message becomes available or until the timeout value is exceeded.
305305
* @param destination the destination to receive a message from
306-
* @return the message produced for the consumer or {@code null} if the timeout expires.
306+
* @return the message produced for the consumer, or {@code null} if the timeout expires
307307
* @throws JmsException checked JMSException converted to unchecked
308308
*/
309309
@Nullable
@@ -317,7 +317,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
317317
* until the message becomes available or until the timeout value is exceeded.
318318
* @param destinationName the name of the destination to send this message to
319319
* (to be resolved to an actual destination by a DestinationResolver)
320-
* @return the message produced for the consumer or {@code null} if the timeout expires.
320+
* @return the message produced for the consumer, or {@code null} if the timeout expires
321321
* @throws JmsException checked JMSException converted to unchecked
322322
*/
323323
@Nullable
@@ -332,7 +332,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
332332
* <p>This will only work with a default destination specified!
333333
* @param messageSelector the JMS message selector expression (or {@code null} if none).
334334
* See the JMS specification for a detailed definition of selector expressions.
335-
* @return the message produced for the consumer or {@code null} if the timeout expires.
335+
* @return the message produced for the consumer, or {@code null} if the timeout expires
336336
* @throws JmsException checked JMSException converted to unchecked
337337
*/
338338
@Nullable
@@ -347,7 +347,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
347347
* @param destination the destination to receive a message from
348348
* @param messageSelector the JMS message selector expression (or {@code null} if none).
349349
* See the JMS specification for a detailed definition of selector expressions.
350-
* @return the message produced for the consumer or {@code null} if the timeout expires.
350+
* @return the message produced for the consumer, or {@code null} if the timeout expires
351351
* @throws JmsException checked JMSException converted to unchecked
352352
*/
353353
@Nullable
@@ -363,7 +363,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
363363
* (to be resolved to an actual destination by a DestinationResolver)
364364
* @param messageSelector the JMS message selector expression (or {@code null} if none).
365365
* See the JMS specification for a detailed definition of selector expressions.
366-
* @return the message produced for the consumer or {@code null} if the timeout expires.
366+
* @return the message produced for the consumer, or {@code null} if the timeout expires
367367
* @throws JmsException checked JMSException converted to unchecked
368368
*/
369369
@Nullable

spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageSendingTemplate.java

+2-3
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.
@@ -168,8 +168,7 @@ protected Message<?> doConvert(Object payload, @Nullable Map<String, Object> hea
168168

169169
Map<String, Object> headersToUse = processHeadersToSend(headers);
170170
if (headersToUse != null) {
171-
messageHeaders = (headersToUse instanceof MessageHeaders _messageHeaders ?
172-
_messageHeaders : new MessageHeaders(headersToUse));
171+
messageHeaders = (headersToUse instanceof MessageHeaders mh ? mh : new MessageHeaders(headersToUse));
173172
}
174173

175174
MessageConverter converter = getMessageConverter();

spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.

0 commit comments

Comments
 (0)