Commit Graph

1962 Commits

Author SHA1 Message Date
Yanming Zhou 6f11716b6f Use idiomatic AssertJ map assertions
See gh-31752
2023-12-05 10:01:38 +01:00
Sam Brannen d71853f105 Polish contribution
See gh-31531
2023-12-04 16:47:25 +01:00
Yanming Zhou 490b5c77fc Use switch expression where feasible 2023-12-04 15:42:55 +01:00
Sam Brannen c05b4ce776 Suppress warnings in Gradle build 2023-12-01 15:44:37 +01:00
Sébastien Deleuze 16ac495084 Introduce ORDER_ATTRIBUTE on AbstractBeanDefinition
This commit allows to define a bean order programmatically
at bean definition level (functional equivalent of
`@Order`).

If specified, the order attribute defined at bean
definition level overrides potential values set with
`@Order`.

See gh-30849
2023-11-30 18:09:00 +01:00
Juergen Hoeller c56c304536 PathEditor considers single-letter URI scheme as NIO path candidate
Closes gh-29881
2023-11-30 14:16:05 +01:00
Yanming Zhou feef98b73c Correct conversion from Resource[] with length 1 to Collection<Resource>
Fix GH-31693
2023-11-30 14:05:13 +01:00
Krane 894dce7cd8 Optimize loops on BeanDefinitionPropertiesCodeGenerator
Closes gh-31650
2023-11-24 16:30:24 +01:00
Juergen Hoeller 48f3c08395 Test for mixed order across bean factory hierarchy
See gh-28374
2023-11-22 12:38:04 +01:00
Johnny Lim 2b750926c3 Polishing
Closes gh-31522
2023-10-30 15:05:20 +01:00
Stéphane Nicoll 1762bf4a60 Fix code generation for null indexed argument value
This commit fixes code generation when an indexed constructor argument
value is null as the method is overloaded and need the value to be
cast to `Object`.

Closes gh-31508
2023-10-28 10:52:26 +02:00
Stéphane Nicoll 4977ef9cea Import ConstructorResolver to handle null values
Previously, ConstructorResolver would reject any candidate if the
parameter is `null`. The reason for that is that null does not carry
any type and the matching algorithm would systematically fail for that
argument.

This commit adds an extra check, and several tests, to validate that
a null value is taken into account.

Closes gh-31495
2023-10-25 17:59:11 +02:00
Juergen Hoeller 83870e35d1 TypeDescriptor/ResolvableType cache in GenericTypeAwarePropertyDescriptor
Closes gh-31490
2023-10-24 23:13:19 +02:00
Juergen Hoeller 93b0b66735 Merge branch '6.0.x'
# Conflicts:
#	spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
#	spring-core/src/main/java/org/springframework/core/ResolvableType.java
#	spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java
2023-10-24 22:58:31 +02:00
Juergen Hoeller 925fa0272b Polishing 2023-10-24 22:53:44 +02:00
Juergen Hoeller 09aa59f9e7 Avoid ResolvableType for simple assignability check in copyProperties
Closes gh-27246
2023-10-24 22:53:00 +02:00
Stéphane Nicoll 999b5d4462 Better error reporting when instance does not match factory method
This commit improves the handling of IllegalArgumentException in
SimpleInstantiationStrategy. Previously, only arguments mismatch were
handled but the exception can also be thrown if the factory instance
does not match the target method.

Closes gh-28897
2023-10-24 13:29:12 +02:00
Stéphane Nicoll 6299a9dfc9 Add tests for SimpleInstantiationStrategy 2023-10-24 13:29:12 +02:00
Juergen Hoeller 8712fdcd3b Polishing 2023-10-23 17:36:06 +02:00
Juergen Hoeller cf3a25bfac Merge branch '6.0.x' 2023-10-23 17:34:45 +02:00
Juergen Hoeller 6bdf7ad36a Polishing 2023-10-23 17:32:45 +02:00
Juergen Hoeller 6dc79b5105 Declare empty default postProcessBeanFactory method
Closes gh-31476
2023-10-23 16:56:05 +02:00
Stéphane Nicoll 3cb700c103 Merge branch '6.0.x' 2023-10-23 11:34:12 +02:00
Stéphane Nicoll f3dce4bb9a Polish "Ignore @Value on record property"
See gh-31433
2023-10-23 11:20:49 +02:00
Martin Lukas 70cb96c1d8 Ignore @Value on record property
See gh-31433
2023-10-23 11:15:24 +02:00
Sam Brannen 2d792f000a Polish "Apply SingleSpaceSeparator Checkstyle module"
See gh-31469
2023-10-22 14:18:18 +02:00
Johnny Lim 64e9fcad53 Apply SingleSpaceSeparator Checkstyle module
This commit also fixes its violations.

Closes gh-31469
2023-10-22 14:09:57 +02:00
Sam Brannen 37e6fe5b64 Update copyright headers 2023-10-22 11:28:40 +02:00
Stéphane Nicoll cf10cee16a Polish 2023-10-21 17:48:27 +02:00
Sébastien Deleuze fa57598327 Refine BeanFactory extensions to avoid type erasure when possible
Closes gh-31439
2023-10-18 13:25:42 +02:00
Johnny Lim 919faa2ce2 Order modifiers to align with JLS
This commit also applies Checkstyle ModifierOrder to enforce it.

See gh-31368
2023-10-17 16:13:56 +02:00
Stéphane Nicoll 9465ff0334 Add support for merging two BeanRegistrationAotContribution instances
Closes gh-31446
2023-10-17 12:31:06 +02:00
Sam Brannen 32b4f55d92 Update copyright headers 2023-10-16 16:19:55 +02:00
Stéphane Nicoll 607c84f960 Fix support for target arrays
This commits makes sure that a bean that produces an array can be
processed ahead of time. If the request target type is an array, its
component type is used.

Closes gh-31426
2023-10-13 15:33:32 +02:00
Stéphane Nicoll 85388aa642 Add AOT support for generic constructor argument values
This commit improves compatibility with the core container when running
in AOT mode by adding support for generic constructor argument values.

Previously, these were ignored altogether. We now have code generation
support for them as well as resolution that is similar to what
AbstractAutowiredCapableBeanFactory does in a regular runtime.

This commit also improves AOT support for XML bean configurations by
adding more support for TypedStringValue and inner bean definitions.

Closes gh-31420
2023-10-13 15:33:32 +02:00
Sam Brannen 364186e699 Polishing 2023-10-12 17:52:55 +02:00
Sam Brannen 047c2c1c20 Do not swallow failures in tests 2023-10-12 17:51:26 +02:00
Sam Brannen a4fe57a9e2 Restore imports for deprecated types in tests 2023-10-12 17:35:01 +02:00
Stephane Nicoll 37c2619fc4 Add AOT support for TypedStringValue
This commit adds support for TypeStringValue when generating AOT code.
If the value does not specify an explicit type, it's specified as is.
Otherwise, the TypeStringValue instance is restored via the appropriate
code generation.

Closes gh-29074
2023-10-12 14:11:53 +02:00
Stéphane Nicoll 15c19411f6 Harmonize exception handling
This commit applies the same catch block to orderForConsistence(Map)
than the one that's used for sets.

Closes gh-31419
2023-10-12 13:55:33 +02:00
Sam Brannen 25778e2f0e Clean up warnings in tests 2023-10-11 13:32:48 +02:00
Sam Brannen 00dde8bd88 Polishing 2023-10-11 13:32:47 +02:00
Stéphane Nicoll ea66883d79 Detect use of deprecated API
This commit is a best effort attempt at identifying the members that
code generation invokes and might be deprecated. It introduces
a CodeWarnings helper class that records warnings, with special
handling for `@Deprecated`.

See gh-29597
2023-10-10 20:08:04 +02:00
Stéphane Nicoll 35372e5e72 Simplify InstanceSupplierCodeGeneratorTests 2023-10-10 20:08:04 +02:00
Brian Clozel 8064659136 Register bean reflection hint for property fields
Prior to this commit, the bean definition properties code generator
would register hints for invoking the setter methods of registered
property values defined for the bean definition.
The internal algorithm is also reflecting on the Field to discover
annotations. Doing so actually calls `getDeclaredFields` to iterate on
the available fields. This is done recursively up the type hierarchy
until the field is found.

This commit registers the required reflection metadata.

Closes gh-31390
2023-10-09 20:03:06 +02:00
Brian Clozel 28c97610c2 Polish reflection hints on bean registration interfaces
This commit ensures that we register reflection hints on interfaces in
the entire type hierarchy, including extended interfaces.

Closes gh-31350
2023-10-03 16:02:29 +02:00
Brian Clozel 14c5228288 Remove reflection hints workarounds for GraalVM issues
This commit removes the previously introduced reflection hints that were
working around known issues in GraalVM.
Spring Framework 6.1 will require recent maintenance versions of GraalVM
and should not contribute such hints anymore.

Closes gh-30394
2023-10-03 13:37:26 +02:00
Brian Clozel 1fd54912d2 Polish reflection hints on bean registration interfaces
This commit ensures that we register reflection hints on interfaces in
the entire type hierarchy.

Closes gh-31350
2023-10-03 11:24:47 +02:00
Brian Clozel b832df6087 Add reflection hints for bean registration interfaces
Prior to this commit, the bean registration AOT contributions would
register introspection and invocation hints on both declared and public
methods for bean types. The bean introspection algorithm also looks at
default methods implemented by interfaces when collecting bean property
information.

This commit ensures that introspection hints are registered for all
implemented interfaces when registering beans.

Closes gh-31350
2023-10-02 19:33:05 +02:00
Sam Brannen bc3d98565c Update copyright headers 2023-09-23 13:36:41 +02:00
Sam Brannen a88d5d1c62 Polishing 2023-09-23 13:36:30 +02:00
Brian Clozel 1e5e8db0e0 Add missing reflection hint in BeanRegistrationsAotContribution
Prior to this commit, the `BeanRegistrationsAotContribution` would only
contribute introspection hints for declared methods. This does not cover
inherited public methods.

This commit adds the missing hint on public methods.

Fixes gh-31293
2023-09-22 10:36:38 +02:00
Brian Clozel a97ff39088 Add reflection hint on Publisher for bean destroy support
Prior to this commit, `DisposableBeanAdapter` supported reactive bean
destroy methods by detected if `Publisher` is available on the
classpath. The AOT engine did not contribute a reflection hint for this
call.

This commit ensures that this reflection hint is registered in all
cases, even if there are no destroy methods detected on beans.

Fixes gh-31278
2023-09-20 14:43:12 +02:00
Brian Clozel 8074f938b1 Add missing reflection hints on Jakarta types
This commit adds reflection hints for `jakarta.inject.Provider` and
ensures that hints are always contributed even if jakarta classes are
not on the classpath.

Fixes gh-31259
2023-09-19 15:46:13 +02:00
Stéphane Nicoll 05500373e2 Merge branch '6.0.x' 2023-09-18 17:02:26 +02:00
Stéphane Nicoll fef3cf8e58 Review AOT-generated code for beanClass and targetType
This commit reviews when an AOT-generated bean definition defines a
beanClass or targetType. Previously, a beanClass was not consistently
set which could lead to issues.

Closes gh-31242
2023-09-18 16:58:01 +02:00
Sam Brannen b05e46d502 Update copyright headers 2023-09-16 15:23:10 +02:00
Niharika Tiwari 9d7f9b5284
Improve wording in Javadoc for @⁠Autowired
#31235
2023-09-14 17:45:03 +02:00
Sam Brannen af13967e2a Polishing 2023-09-13 16:50:58 +02:00
Stephane Nicoll 01f717375b Introduce ObjectUtils#nullSafeHash(Object... element)
This commit deprecates the various nullSafeHashCode methods taking array
types as they are superseded by Arrays.hashCode now. This means that
the now only remaining nullSafeHashCode method does not trigger a
warning only if the target type is not an array. At the same time, there
are multiple use of this method on several elements, handling the
accumulation of hash codes.

For that reason, this commit also introduces a nullSafeHash that takes
an array of elements. The only difference between Objects.hash is that
this method handles arrays.

The codebase has been reviewed to use any of those two methods when it
is possible.

Closes gh-29051
2023-09-13 15:14:34 +02:00
Stephane Nicoll bf5ce82254 Move custom code fragments requirements at the right place
This commit moves the check on bean definitions having an instance
supplier where they are actually used.

Closes gh-31200
2023-09-11 17:13:04 +02:00
Stephane Nicoll 66a571fe27 Make constructorOrFactory method resolution optional
This commit allows a custom code fragment to provide the code to
create a bean without relying on ConstructorResolver. This is especially
important for use cases that derive from the default behaviour and
provide an instance supplier with the regular runtime scenario.

This is a breaking change for code fragments providing a custom
implementation of the related methods. As it turns out, almost all of
them did not need the Executable argument. Configuration class parsing
is the exception, where it needs to provide a different constructor in
the case of the proxy. To make this use case possible,
InstanceSupplierCodeGenerator has been made public.

Closes gh-31117
2023-09-11 15:55:22 +02:00
Sam Brannen 60d05d4204 Polishing 2023-09-08 19:29:28 +02:00
Stephane Nicoll e239753a1b Merge branch '6.0.x' 2023-08-27 18:03:59 +02:00
Stephane Nicoll 1396daa4b6 Polish "Make sure NoUniqueBeanDefinitionException to be serializable"
See gh-29753
2023-08-27 17:59:27 +02:00
Per Lundberg 1b409d5290 Make sure NoUniqueBeanDefinitionException to be serializable
See gh-29753
2023-08-27 17:56:58 +02:00
Stephane Nicoll 8efc7a958e Polish "Improve @Autowired method injection on mixed nullability args"
See gh-17215
2023-08-25 12:47:05 +02:00
陈其苗 32c0540424 Improve @Autowired method injection on mixed nullability args
See gh-17215
2023-08-25 12:44:16 +02:00
Stephane Nicoll 5878a0741e Polish "Add factory to create a NamedThreadLocal with an initial value"
See gh-24705
2023-08-23 18:58:12 +02:00
Stephane Nicoll 2b76c4d847 Polish "Wrap ternary operator within parentheses"
See gh-31076
2023-08-22 15:40:16 +02:00
Juergen Hoeller 45c20e34e4 Merge branch '6.0.x'
# Conflicts:
#	spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java
2023-08-14 19:29:14 +02:00
Juergen Hoeller 8b3ddeed05 Test factory-bean/method placeholders as well
See gh-20189
2023-08-14 19:28:12 +02:00
Juergen Hoeller 6baa60d454 Polishing 2023-08-12 14:51:02 +02:00
Juergen Hoeller 9ede1d07a0 Revise multiple beans resolution for custom collection types
Closes gh-30022
2023-08-12 12:48:14 +02:00
Sébastien Deleuze 0c477f14cc Polishing
See gh-28638
2023-08-09 11:14:42 +02:00
Sébastien Deleuze c38f053905 Add Kotlin value classes tests with primitive types
This commit adds more Kotlin value classes tests with
primitive types to ensure testing unwrapped use case.

See gh-28638
2023-08-09 11:12:56 +02:00
Sébastien Deleuze 88c2a25f12 Add support for Kotlin value classes in BeanUtils
This commit adds support for Kotlin value classes annotated
with @JvmInline to BeanUtils#findPrimaryConstructor.

This is only the first step, more refinements are expected
to be needed to achieve a comprehensive support of Kotlin
values classes in Spring Framework.

Closes gh-28638
2023-08-09 10:31:49 +02:00
Juergen Hoeller 3c34e69cc2 Merge branch '6.0.x' 2023-08-07 14:53:01 +02:00
Juergen Hoeller 156b3696a7 Reinstate Introspector.flushFromCaches() call for JDK ClassInfo cache
Closes gh-27781
2023-08-07 14:51:49 +02:00
Sam Brannen 526fc391ee Use Class#componentType() for consistency with arrayType()
Java 12 introduced java.lang.Class#componentType() as a shortcut for
getComponentType().

Since we started using arrayType() in fe5560400c, this commit switches
to componentType() for consistent API usage style.
2023-08-07 12:43:40 +03:00
Sam Brannen fe5560400c Use Class#arrayType() where feasible
Closes gh-31002
2023-08-07 12:07:46 +03:00
Juergen Hoeller eaf54b54c3 Detect illegal bean definition override during classpath scanning
Closes gh-25952
2023-08-06 14:03:29 +02:00
Sam Brannen 3758e5155c Merge branch '6.0.x' 2023-08-04 15:35:16 +03:00
xumengqi 07a1aea9c7 Skip array sort when the length of array not greater than 1
Closes gh-30934
2023-08-04 15:25:46 +03:00
Juergen Hoeller 4e863c5a75 Merge branch '6.0.x' 2023-08-04 02:40:17 +02:00
Juergen Hoeller 18966d048c Consistent equals/hashCode style (and related polishing) 2023-08-04 02:39:31 +02:00
Juergen Hoeller a6ff95a69c Restore restrictive getTypeForFactoryBeanFromAttributes check
See gh-29799
See gh-30987
2023-08-04 00:56:01 +02:00
Juergen Hoeller f7c3e6480a Merge branch '6.0.x'
# Conflicts:
#	spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
2023-08-04 00:49:20 +02:00
Juergen Hoeller 7e6612a920 Sort multiple @Autowired methods on same bean class via ASM
Closes gh-30359
2023-08-04 00:47:18 +02:00
Juergen Hoeller 9333ed22f6 Avoid repeated FactoryBean targetType check
See gh-30987
2023-08-04 00:47:04 +02:00
Juergen Hoeller d868f58e6e Merge branch '6.0.x'
# Conflicts:
#	spring-beans/src/test/java/org/springframework/beans/factory/annotation/LookupAnnotationTests.java
2023-08-03 18:11:08 +02:00
Juergen Hoeller 4b6fabbd2f Polishing 2023-08-03 18:10:13 +02:00
Juergen Hoeller cba2b6eaf4 Check FactoryBean targetType for generic type as well
Closes gh-30987
2023-08-03 18:10:07 +02:00
Juergen Hoeller 84b3335e71 Apply array editor to collection of same element type as well
Closes gh-24845
2023-08-03 17:55:54 +02:00
Juergen Hoeller c3e18bc173 Retain metadata during bean creation even with cacheBeanMetadata=false
Closes gh-23795
Closes gh-25749
2023-08-03 17:55:47 +02:00
Sam Brannen 2e07a72119 Delete duplicate DummyFactory 2023-08-02 11:09:15 +03:00
Juergen Hoeller d250a5155a Consistent dependency declarations 2023-08-02 00:56:50 +02:00
Sam Brannen 4b7d1e3a2c Delete duplicate DummyFactory 2023-08-02 11:29:15 +03:00
Sam Brannen 44d14811d3 Suppress deprecation warnings in test fixtures 2023-08-02 10:51:03 +03:00
Sam Brannen 89b85c81a7 Polishing 2023-08-02 10:21:06 +03:00