Skip to content

Commit 6d5c312

Browse files
committed
Merge branch '6.1.x'
2 parents 1582f5f + 9a56a88 commit 6d5c312

File tree

8 files changed

+64
-27
lines changed

8 files changed

+64
-27
lines changed

spring-context/src/main/java/org/springframework/context/event/ApplicationContextEvent.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -29,7 +29,7 @@
2929
public abstract class ApplicationContextEvent extends ApplicationEvent {
3030

3131
/**
32-
* Create a new ContextStartedEvent.
32+
* Create a new {@code ApplicationContextEvent}.
3333
* @param source the {@code ApplicationContext} that the event is raised for
3434
* (must not be {@code null})
3535
*/

spring-context/src/main/java/org/springframework/context/event/ContextClosedEvent.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -29,7 +29,7 @@
2929
public class ContextClosedEvent extends ApplicationContextEvent {
3030

3131
/**
32-
* Creates a new ContextClosedEvent.
32+
* Create a new {@code ContextClosedEvent}.
3333
* @param source the {@code ApplicationContext} that has been closed
3434
* (must not be {@code null})
3535
*/

spring-context/src/main/java/org/springframework/context/event/ContextRefreshedEvent.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -29,7 +29,7 @@
2929
public class ContextRefreshedEvent extends ApplicationContextEvent {
3030

3131
/**
32-
* Create a new ContextRefreshedEvent.
32+
* Create a new {@code ContextRefreshedEvent}.
3333
* @param source the {@code ApplicationContext} that has been initialized
3434
* or refreshed (must not be {@code null})
3535
*/

spring-context/src/main/java/org/springframework/context/event/ContextStartedEvent.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -30,7 +30,7 @@
3030
public class ContextStartedEvent extends ApplicationContextEvent {
3131

3232
/**
33-
* Create a new ContextStartedEvent.
33+
* Create a new {@code ContextStartedEvent}.
3434
* @param source the {@code ApplicationContext} that has been started
3535
* (must not be {@code null})
3636
*/

spring-context/src/main/java/org/springframework/context/event/ContextStoppedEvent.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -30,7 +30,7 @@
3030
public class ContextStoppedEvent extends ApplicationContextEvent {
3131

3232
/**
33-
* Create a new ContextStoppedEvent.
33+
* Create a new {@code ContextStoppedEvent}.
3434
* @param source the {@code ApplicationContext} that has been stopped
3535
* (must not be {@code null})
3636
*/

spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationAdapter.java

+13-17
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ public Class<?>[] determineValidationGroups(Object target, Method method) {
234234

235235
@Override
236236
public final MethodValidationResult validateArguments(
237-
Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments,
238-
Class<?>[] groups) {
237+
Object target, Method method, @Nullable MethodParameter[] parameters,
238+
Object[] arguments, Class<?>[] groups) {
239239

240240
Set<ConstraintViolation<Object>> violations =
241241
invokeValidatorForArguments(target, method, arguments, groups);
@@ -256,23 +256,21 @@ public final Set<ConstraintViolation<Object>> invokeValidatorForArguments(
256256
Object target, Method method, Object[] arguments, Class<?>[] groups) {
257257

258258
ExecutableValidator execVal = this.validator.get().forExecutables();
259-
Set<ConstraintViolation<Object>> violations;
260259
try {
261-
violations = execVal.validateParameters(target, method, arguments, groups);
260+
return execVal.validateParameters(target, method, arguments, groups);
262261
}
263262
catch (IllegalArgumentException ex) {
264263
// Probably a generic type mismatch between interface and impl as reported in SPR-12237 / HV-1011
265264
// Let's try to find the bridged method on the implementation class...
266265
Method bridgedMethod = BridgeMethodResolver.getMostSpecificMethod(method, target.getClass());
267-
violations = execVal.validateParameters(target, bridgedMethod, arguments, groups);
266+
return execVal.validateParameters(target, bridgedMethod, arguments, groups);
268267
}
269-
return violations;
270268
}
271269

272270
@Override
273271
public final MethodValidationResult validateReturnValue(
274-
Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue,
275-
Class<?>[] groups) {
272+
Object target, Method method, @Nullable MethodParameter returnType,
273+
@Nullable Object returnValue, Class<?>[] groups) {
276274

277275
Set<ConstraintViolation<Object>> violations =
278276
invokeValidatorForReturnValue(target, method, returnValue, groups);
@@ -305,9 +303,9 @@ private MethodValidationResult adaptViolations(
305303
Map<Path.Node, ParamErrorsBuilder> nestedViolations = new LinkedHashMap<>();
306304

307305
for (ConstraintViolation<Object> violation : violations) {
308-
Iterator<Path.Node> itr = violation.getPropertyPath().iterator();
309-
while (itr.hasNext()) {
310-
Path.Node node = itr.next();
306+
Iterator<Path.Node> nodes = violation.getPropertyPath().iterator();
307+
while (nodes.hasNext()) {
308+
Path.Node node = nodes.next();
311309

312310
MethodParameter parameter;
313311
if (node.getKind().equals(ElementKind.PARAMETER)) {
@@ -328,8 +326,8 @@ else if (node.getKind().equals(ElementKind.RETURN_VALUE)) {
328326
// https://github.com/jakartaee/validation/issues/194
329327

330328
Path.Node parameterNode = node;
331-
if (itr.hasNext()) {
332-
node = itr.next();
329+
if (nodes.hasNext()) {
330+
node = nodes.next();
333331
}
334332

335333
Object value;
@@ -425,7 +423,6 @@ public interface ObjectNameResolver {
425423
* @return the name to use
426424
*/
427425
String resolveName(MethodParameter parameter, @Nullable Object value);
428-
429426
}
430427

431428

@@ -456,6 +453,7 @@ private final class ParamValidationResultBuilder {
456453
public ParamValidationResultBuilder(
457454
Object target, MethodParameter parameter, @Nullable Object value, @Nullable Object container,
458455
@Nullable Integer containerIndex, @Nullable Object containerKey) {
456+
459457
this.target = target;
460458
this.parameter = parameter;
461459
this.value = value;
@@ -473,7 +471,6 @@ public ParameterValidationResult build() {
473471
this.parameter, this.value, this.resolvableErrors, this.container,
474472
this.containerIndex, this.containerKey);
475473
}
476-
477474
}
478475

479476

@@ -527,8 +524,7 @@ public ParameterErrors build() {
527524

528525

529526
/**
530-
* Default algorithm to select an object name, as described in
531-
* {@link #setObjectNameResolver(ObjectNameResolver)}.
527+
* Default algorithm to select an object name, as described in {@link #setObjectNameResolver}.
532528
*/
533529
private static class DefaultObjectNameResolver implements ObjectNameResolver {
534530

spring-context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java

+36
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.junit.jupiter.api.Test;
2727

2828
import org.springframework.beans.factory.BeanFactory;
29+
import org.springframework.beans.factory.InitializingBean;
2930
import org.springframework.beans.factory.ObjectFactory;
3031
import org.springframework.beans.factory.annotation.Autowired;
3132
import org.springframework.beans.factory.annotation.Value;
@@ -43,6 +44,7 @@
4344
import org.springframework.core.annotation.AliasFor;
4445
import org.springframework.core.io.ClassPathResource;
4546
import org.springframework.core.io.Resource;
47+
import org.springframework.util.Assert;
4648

4749
import static org.assertj.core.api.Assertions.assertThat;
4850

@@ -183,6 +185,14 @@ void testValueInjectionWithProviderMethodArguments() {
183185
context.close();
184186
}
185187

188+
@Test
189+
void testValueInjectionWithAccidentalAutowiredAnnotations() {
190+
AnnotationConfigApplicationContext context =
191+
new AnnotationConfigApplicationContext(ValueConfigWithAccidentalAutowiredAnnotations.class);
192+
doTestValueInjection(context);
193+
context.close();
194+
}
195+
186196
private void doTestValueInjection(BeanFactory context) {
187197
System.clearProperty("myProp");
188198

@@ -494,6 +504,32 @@ public TestBean testBean2(@Value("#{systemProperties[myProp]}") Provider<String>
494504
}
495505

496506

507+
@Configuration
508+
static class ValueConfigWithAccidentalAutowiredAnnotations implements InitializingBean {
509+
510+
boolean invoked;
511+
512+
@Override
513+
public void afterPropertiesSet() {
514+
Assert.state(!invoked, "Factory method must not get invoked on startup");
515+
}
516+
517+
@Bean @Scope("prototype")
518+
@Autowired
519+
public TestBean testBean(@Value("#{systemProperties[myProp]}") Provider<String> name) {
520+
invoked = true;
521+
return new TestBean(name.get());
522+
}
523+
524+
@Bean @Scope("prototype")
525+
@Autowired
526+
public TestBean testBean2(@Value("#{systemProperties[myProp]}") Provider<String> name2) {
527+
invoked = true;
528+
return new TestBean(name2.get());
529+
}
530+
}
531+
532+
497533
@Configuration
498534
static class PropertiesConfig {
499535

spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java

+5
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,13 @@ private static Method searchForMatch(Class<?> type, Method bridgeMethod) {
276276
*/
277277
public static boolean isVisibilityBridgeMethodPair(Method bridgeMethod, Method bridgedMethod) {
278278
if (bridgeMethod == bridgedMethod) {
279+
// Same method: for common purposes, return true to proceed as if it was a visibility bridge.
279280
return true;
280281
}
282+
if (ClassUtils.getUserClass(bridgeMethod.getDeclaringClass()) != bridgeMethod.getDeclaringClass()) {
283+
// Method on generated subclass: return false to consistently ignore it for visibility purposes.
284+
return false;
285+
}
281286
return (bridgeMethod.getReturnType().equals(bridgedMethod.getReturnType()) &&
282287
bridgeMethod.getParameterCount() == bridgedMethod.getParameterCount() &&
283288
Arrays.equals(bridgeMethod.getParameterTypes(), bridgedMethod.getParameterTypes()));

0 commit comments

Comments
 (0)