Commit Graph

3242 Commits

Author SHA1 Message Date
Johnny Lim ccec75c98d Add missing TreeSet to CollectionFactory.createCollection()
See gh-28949
2022-08-11 08:22:11 +02:00
Juergen Hoeller b31a15851e Support for pre-generated CGLIB proxy classes (in AOT scenarios)
Includes runtime storing of generated classes to a directory specified by the "cglib.generatedClasses" system property. Avoids lazy CGLIB fast-class generation and replaces generated Enhancer and MethodWrapper key classes with equivalent record types. Introduces support for early type determination in InstantiationStrategy, AopProxy and SmartInstantiationAwareBeanPostProcessor - in order to trigger CGLIB class generation in refreshForAotProcessing (through early determineBeanType calls for bean definitions).

Closes gh-28115
2022-08-10 23:30:19 +02:00
Sam Brannen 0944c9a99c Remove `throws IOException` from DefaultGenerationContext.writeGeneratedContent()
The `throws` declaration is unnecessary since writeGeneratedContent()
will never throw an IOException.
2022-08-06 14:34:04 +03:00
Sam Brannen a466179bc8 Polish and sync TestGenerationContext implementations
- new constructor for providing InMemoryGeneratedFiles
- writeGeneratedContent() now throws UncheckedIOException
2022-08-06 14:08:49 +03:00
Stephane Nicoll 6685e78c36 Deprecate NestedIOException
NestedIOException has been removed in Spring Framework 6 and this commit
marks it as deprecated in 5.x. Users that were relying on this exception
should use IOException directly.

Closes gh-28929
2022-08-05 10:04:47 +02:00
Stephane Nicoll 9264d97880 Restore GeneratedTypeReference
Closes gh-28926
2022-08-04 16:30:59 +02:00
Sam Brannen 31503df415 Fix Javadoc link syntax plus polishing 2022-08-04 13:52:40 +03:00
Brian Clozel 34266f22c7 Merge branch '5.3.x' 2022-08-03 23:16:13 +02:00
Brian Clozel 0caa2ac696 Customize connection in UrlResource getInputStream
Prior to this commit, the `AbstractFileResolvingResource` would
provide a default implementation for `customizeConnection` which only
sets the HTTP request method as "HEAD".
While this is consistent with its usage within that class (in
`exists()`, `contentLength()` or `lastModified()`), this is not opened
for general usage by sub-classes.

`UrlResource` is an example of that, where its `getInputStream()` method
does not call this customization method.

This not only prevents implementations from calling
`customizeConnection` in various cases, but it also misleads developers
as they might think that customizations will be applied automatically.

This commit ensures that `customizeConnection` is called in all relevant
places and that the configuration of the HTTP method is instead done in
each method as it is use case specific.

Fixes gh-28909
2022-08-03 23:13:52 +02:00
Phillip Webb 4a23d9234c Include shadow source jars in eclipse setup
See gh-28892
2022-08-01 11:28:01 +01:00
Ikko Ashimine 4ac9b7bff2 Fix typo in BasicJsonWriter.java
See gh-28890
2022-08-01 09:17:28 +02:00
Sam Brannen e4395f2f8b Clean up warnings and polishing 2022-07-31 14:14:56 +03:00
Phillip Webb 9d1e9703ae Include shadowed jar source in published source artifacts
Add a new `ShadowSource` Gradle task and update `spring-core.gradle`
to include source for cglib, javapoet and objenesis.

Closes gh-28892

Co-authored-by: Andy Wilkinson <wilkinsona@vmware.com>
2022-07-30 10:25:58 +01:00
Stephane Nicoll 916a871fbc Add dedicated hint support for composable annotations
This commit adds a dedicated method for annotations that are used as
meta-annotation when the composed annotation does not require to be
visible at runtime.

Closes gh-28887
2022-07-29 15:38:09 +02:00
Stephane Nicoll 56a8c1a9db Register proxy hint for meta-annotations with attribute override
Closes gh-28767
2022-07-29 13:23:32 +02:00
Stephane Nicoll 28ca0dd642 Merge branch '5.3.x' 2022-07-29 09:31:50 +02:00
Stephane Nicoll aef4b0ec5a Upgrade copyright year of changed file
See gh-28885
2022-07-29 09:29:58 +02:00
wpp 675e0b94c1 Fix typo in Javadoc of AbstractEncoder
See gh-28885
2022-07-29 09:29:35 +02:00
Brian Clozel 10e4965f99 Guard against new Spring modules in ApiDiff task
Prior to this commit, the ApiDiff Gradle task would be configured for
all submodules of the Spring Framework project and would assume that
they all existed for the baseline version considered for the API diff.

This would cause issues when:
* the sub-project is not published as it's not an official "spring-*"
  module
* the "spring-*" module is new and did not exist for the baseline
  version

This commit ensures that only "spring-*" modules are considered for this
task and that we trigger an early resolution of the baseline version -
if the version doesn't exist, a warn message is logged and we assume
that this is a new module, to be compared with an empty configuration.

This commit also renames the "spring-core-graalvm" project to
"graalvm-feature", since this sub-project is not an official module
published to Maven Central, but rather an internal dependency.

Fixes gh-28818
2022-07-28 10:51:53 +02:00
Stephane Nicoll 498668fc57 Deprecate SpringFactoriesLoader#loadFactoryNames
Closes gh-27954
2022-07-27 17:56:33 +02:00
Arjen Poutsma b38a5df563 Javadoc 2022-07-27 13:54:09 +02:00
Arjen Poutsma 2aa74c9121 Deprecate ListenableFuture in favor of CompletableFuture
This commit deprecates ListenableFuture in favor of CompletableFuture.
ListenableFuture was introduced in Spring Framework 4.0, when
CompletableFuture was not yet available. Spring now requires JDK 17, so
having our own type no longer seems necessary.

Major changes in this commit include:
- Deprecation of ListenableFuture and related types
  (ListenableFutureCallback, SettableListenableFuture, etc.)
- Deprecation of AsyncListenableTaskExecutor in favor of default methods
  in AsyncTaskExecutor (submitCompletable).
- AsyncHandlerMethodReturnValueHandler now has toCompletableFuture
  instead of toListenableFuture.
- WebSocketClient now has execute methods, which do the same as
  doHandshake, but return CompletableFutures (cf. the reactive
  WebSocketClient).

All other changes
- add an overloaded method that takes a CompletableFuture parameter
  instead of ListenableFuture, and/or
- add a method with a 'Async' suffix that returns a CompletableFuture
  instead of a ListenableFuture (connectAsync, sendAsync).

Closes gh-27780
2022-07-27 12:41:35 +02:00
Stephane Nicoll 3d5003ad63 Introduce TestGenerationContext
This commit polishes DefaultGenerationContext to make the method
that flushes generated classes more explicit. It now throws an
IOException and TestGenerationContext has been updated to handle
that to ease its use in code that can't throw such an exception.

As this use case is likely to happen outside the Spring Framework,
this commit adds such a convenience to spring-test as well.

Closes gh-28877
2022-07-26 17:56:17 +02:00
Stephane Nicoll 9573fc96ec Polish 2022-07-25 13:45:46 +02:00
Phillip Webb 578f155809 Polishing 2022-07-18 15:01:51 +01:00
Stephane Nicoll 444e06fa22 Harmonize visibility of RuntimeHints builders
Closes gh-28835
2022-07-18 14:09:52 +02:00
Phillip Webb 87b83e8291 Make MethodName package-private
Closes gh-28832
2022-07-18 11:20:43 +01:00
Phillip Webb f2d31b7a20 Migrate AOT tests to use GeneratedClasses and refine/polish AOT APIs
Migrate all AOT tests to make use of `GeneratedClasses` rather than
directly generating Java files. This commit also refines and polishes
AOT APIs to being greater consistency.

Specifically:

	- The `MethodGenerator` interface has been removed in favor of
	  working directly with `GeneratedMethods`.
	- The visibility of several constructors and methods has been
	  reduced to package-private.
	- The `using(...)` and `builder` methods have been removed in
	  favor of setting the `Consumer` callbacks directly as
	  constructor arguments.
	- Variable names for builders are now named `type` or `method`
	  depending on what they're building.

Closes gh-28831
2022-07-18 08:40:59 +01:00
rstoyanchev f814fb420b Merge branch '5.3.x' 2022-07-13 19:21:33 +01:00
rstoyanchev cdd4e8cd7f Improve regex support for URL path matching
Closes gh-28815
2022-07-13 18:43:51 +01:00
Sam Brannen 0fb9de5d0e Merge branch '5.3.x' 2022-07-13 16:36:01 +02:00
Marc Wrobel bd3499671c Fix typos in test code
This commit fixes typos in test class names, test method names, and
test variable names.

Closes gh-28807
2022-07-13 16:24:11 +02:00
Sam Brannen aae9050351 Merge branch '5.3.x'
# Conflicts:
#	spring-context/src/main/java/org/springframework/scheduling/annotation/Async.java
#	spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContextBuilder.java
#	spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java
#	spring-core/src/main/java/org/springframework/util/MimeType.java
2022-07-13 14:55:30 +02:00
Sam Brannen ea27206a32 Polishing 2022-07-13 14:45:31 +02:00
Marc Wrobel bc15f839cd Fix and improve Javadoc in spring-core
See gh-28802
2022-07-13 14:45:13 +02:00
Sam Brannen 353666627f Polishing 2022-07-13 12:18:29 +02:00
Juergen Hoeller dfae4eec2d Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-core/src/main/java/org/springframework/cglib/core/ReflectUtils.java
#	spring-core/src/main/java/org/springframework/core/ResolvableType.java
#	spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java
#	spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java
2022-07-13 11:16:13 +02:00
Juergen Hoeller a3e46a2db7 ResolvableType.forInstance returns NONE for null instance
Closes gh-28776
2022-07-13 11:10:35 +02:00
Juergen Hoeller de1b938e2e Improve diagnostics for CGLIB ClassLoader mismatch with --add-opens hint
Closes gh-28747
2022-07-13 11:10:00 +02:00
Juergen Hoeller d72aeac319 Create well-known non-interface types without using reflection
Closes gh-28718
2022-07-13 11:09:43 +02:00
Stephane Nicoll 2c92d7da8f Harmonize RuntimeHintsRegistrar implementations
Closes gh-28801
2022-07-12 18:30:23 +02:00
Stephane Nicoll 44d7e2775f Polish 2022-07-12 16:16:12 +02:00
Stephane Nicoll 54a3f66d1d Move RuntimeHints predicate support to a dedicated package
This commit moves `RuntimeHintsPredicate` and its support classes that
form a cohesive concept in a dedicated `.predicate` package.

Closes gh-28799
2022-07-12 16:16:12 +02:00
Stephane Nicoll 40c8b7c59f Stop using package protected code
See gh-28799
2022-07-12 16:16:12 +02:00
Sam Brannen 5c2870ebd9 Test support for serializable records in SerializationUtils
See gh-28798
2022-07-12 15:35:13 +02:00
Stephane Nicoll ee6a4e7c1e Add predicates for Serialization hints
Closes gh-28772
2022-07-11 16:37:12 -04:00
Sam Brannen 255a52bc7a Fix attribute aliasing in @Reflective
See gh-28469
2022-07-11 19:14:39 +02:00
Sam Brannen c991aa9a78 Add missing package-info 2022-07-11 18:18:29 +02:00
Sam Brannen c86d193a78 Polish AotDetector 2022-07-11 18:18:08 +02:00
Sam Brannen 656dc549b1 Reject JDK proxy hint registration for sealed interfaces
Closes gh-28786
2022-07-11 17:48:40 +02:00
Sam Brannen 5c2ee249b5 Polish ProxyHintsTests 2022-07-11 17:48:39 +02:00
Sam Brannen d8003e326d Revert "Introduce ProxyHints.registerJdkProxy(String...)"
This reverses commit b560c10d4c.

See gh-28781
2022-07-11 17:48:39 +02:00
Sam Brannen 5178e9c28e Simplify hint registration for Spring AOP proxies
Prior to this commit, when users wished to register proxy hints for a
Spring AOP JDK dynamic proxy, they were required to explicitly specify
SpringProxy, Advised, and DecoratingProxy along with user interfaces.

This commit simplifies hint registration for Spring AOP proxies by
introducing two completeJdkProxyInterfaces() methods in AopProxyUtils,
one that accepts strings and one that accepts classes that represent
the user-specified interfaces implemented the user component to be
proxied. The SpringProxy, Advised, and DecoratingProxy interfaces are
appended to the user-specified interfaces and returned as the complete
set of interfaces that the proxy will implement.

Closes gh-28745
2022-07-10 20:10:12 +02:00
Sam Brannen b560c10d4c Introduce ProxyHints.registerJdkProxy(String...)
Since users might not have a concrete need to work with TypeReference,
this commit introduces ProxyHints.registerJdkProxy(String...) to
simplify use of the API for registering a dynamic proxy based on fully
qualified class names of the required interfaces.

Closes gh-28781
2022-07-10 18:54:16 +02:00
Sam Brannen 9db43037fe Polishing 2022-07-10 18:31:58 +02:00
Sam Brannen d7b45b7c8e Improve diagnostics for convention-based annotation attribute overrides
The warning message logged for an annotation that still uses
convention-based overrides now includes a concrete suggestion for how
the problem may potentially be fixed.

  WARN - Support for convention-based annotation attribute overrides is
  deprecated and will be removed in Spring Framework 6.1. Please
  annotate the 'locations' attribute in
  @org.springframework.core.annotation.MergedAnnotationsTests$ConventionBasedComposedContextConfiguration
  with an appropriate @AliasFor declaration -- for example,
  @AliasFor(annotation = org.springframework.core.annotation.MergedAnnotationsTests$ContextConfiguration.class).

See gh-28760
2022-07-09 17:15:17 +02:00
Sam Brannen 597873746c Update test annotations due to removal of AnnotationAttributesReadingVisitor
Annotations are no longer required to be public when looked up via
ASM since 6.0 M1.
2022-07-09 16:50:24 +02:00
Sam Brannen 2af08cf163 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/annotation/TypeMappedAnnotationTests.java
#	spring-test/src/test/java/org/springframework/test/context/junit4/TimedSpringRunnerTests.java
#	spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java
#	spring-test/src/test/java/org/springframework/test/util/OverriddenMetaAnnotationAttributesTests.java
2022-07-09 16:24:04 +02:00
Sam Brannen d274e893a6 Remove superfluous static declaration for enum, annotation, & interface 2022-07-09 16:16:13 +02:00
Sam Brannen 73d92d66b9 Stop using convention-based annotation attribute overrides in tests
This commit replaces convention-based annotation attribute overrides in
tests with explicit use of @AliasFor -- except for tests in spring-core,
since we still want to test our support for convention-based annotation
attribute overrides.

See gh-28760
2022-07-08 19:28:14 +02:00
Sam Brannen 6812de7b82 Polishing 2022-07-08 19:24:15 +02:00
Sam Brannen 9f7cbe1234 Polishing 2022-07-07 17:50:45 +02:00
Sam Brannen a68f5b1674 Deprecate convention-based annotation attribute overrides
Implicit convention-based annotation attribute overrides have been
supported for a long time; however, Spring Framework 4.2 introduced
support for explicit annotation attribute overrides via @AliasFor.

Since explicit overrides are favorable to implicit overrides, and since
the support for convention-based overrides increases the complexity of
Spring's annotation search algorithms, this commit deprecates
convention-based overrides and logs a WARNING whey the are encountered.

For example, the following message is logged for a test that still
uses convention-based overrides. A log message is generated for each
such attribute in a given annotation but only once per application run.

  WARN Support for convention-based annotation attribute overrides is
  deprecated and will be removed in Spring Framework 6.1. Please
  annotate the 'basePackages' attribute in
  @org.springframework.context.annotation.ConfigurationClassPostProcessorTests$ComposedConfigurationWithAttributeOverrides
  with an appropriate @AliasFor declaration.

Closes gh-28760
2022-07-07 17:36:16 +02:00
Sam Brannen 81acbe7e2f Ensure AnnotationTypeMapping properly tracks convention-based mappings
AnnotationTypeMapping.addConventionMappings() sometimes adds
convention-based mappings that it should not.

For example, in certain circumstances an explicit annotation attribute
override configured via @AliasFor can be incorrectly mapped as
convention-based.

Although this does not appear to cause negative side effects (other
than unnecessary processing), this is technically a bug, and this
commit address this issue.

Closes gh-28773
2022-07-07 17:33:27 +02:00
Sébastien Deleuze 5397d4721b Recognize PRESENT fields in native classpath checks at build time
This pattern is used in Spring Boot.

See gh-28624
2022-07-07 11:48:43 +02:00
Sébastien Deleuze cdf01ede8d Perform Reactor native classpath checks at build time
See gh-28624
2022-07-06 16:39:00 +02:00
Sam Brannen a122a0e8c8 Simplify RuntimeHintsUtilsTests 2022-07-06 15:24:16 +02:00
Sam Brannen c54b1519e4 Merge branch '5.3.x' 2022-07-06 13:20:16 +02:00
Sam Brannen 323dbb912e Move convention-based attribute override tests to @Nested class 2022-07-06 13:19:41 +02:00
Sam Brannen a194fa0e87 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java
2022-07-06 11:51:09 +02:00
Sam Brannen 07960d4918 Polishing 2022-07-06 11:44:15 +02:00
Sam Brannen 07cfcbc3a9 Move convention-based attribute override tests to @Nested class 2022-07-06 11:42:39 +02:00
Sam Brannen d533eb4a55 Use Set.of() in StringToBooleanConverter 2022-07-05 14:10:33 +02:00
Sam Brannen 613aac5009 Merge branch '5.3.x' 2022-07-05 13:57:54 +02:00
Sam Brannen 2af27d899f Trim string input in Converters where whitespace is irrelevant
Closes gh-28756
2022-07-05 13:53:00 +02:00
Sam Brannen 338609a168 Merge branch '5.3.x' 2022-07-04 19:31:47 +02:00
Sam Brannen 2bf5f7a6b3 Introduce lenient parsing in DataSize regarding whitespace
Prior to this commit, a DataSize input string could not be parsed if it
contained any whitespace.

With this commit, a DataSize input string can contain leading, trailing,
or 'in between' whitespace. For example, the following will be parsed
to the same DataSize value.

- "1024B"
- "1024 B"
- " 1024B "
- " 1024 B "

Closes gh-28643
2022-07-04 19:24:58 +02:00
Sam Brannen bf39492c34 Introduce StringUtils.trimAllWhitespace(CharSequence)
Closes gh-28757
2022-07-04 19:24:45 +02:00
Sébastien Deleuze b64edebadc Improve ConstantFieldFeature compatibility
This commit makes ConstantFieldFeature
compatible with GraalVM 22.2 while retaining
GraalVM 22.1 compatibility.

See gh-28624
2022-07-04 11:59:01 +02:00
Sam Brannen ce5076ffe8 Merge branch '5.3.x' 2022-07-03 18:05:36 +02:00
Sam Brannen f732fab820 Delete unused imports and dead code in CGLIB fork 2022-07-03 17:30:30 +02:00
Brian Clozel 7a3e8bf648 Fix NPE in Constructor predicate
This commit fixes a NullPointerException issue in the constructor hint
predicate. Prior to this commit, a hint for a constructor was directly
looked up and dereferenced a type hint without checking if there was one
first.
2022-06-30 18:20:38 +02:00
Sébastien Deleuze 9135921d1d Move BindingReflectionHintsRegistrar to spring-context
Closes gh-28735
2022-06-30 11:56:08 +02:00
Sébastien Deleuze c5cf7c0ab0 Polishing
See gh-28635
2022-06-30 11:44:44 +02:00
Sébastien Deleuze da68781b9e Add support for records in BindingReflectionHintsRegistrar
Closes gh-28721
2022-06-30 11:43:16 +02:00
Moritz Halbritter 89a6101b2e Only use JPMS exports as we don't need reflection access
See gh-28624
See gh-28732
2022-06-30 10:26:49 +02:00
Moritz Halbritter 1a88451369 Open GraalVM internals to the ConstantFieldFeature
This is needed as GraalVM 22.2 enabled the module system when building
native-images and all plugins have to participate in it.

See gh-28624
Closes gh-28732
2022-06-30 10:08:06 +02:00
Sébastien Deleuze 8d08b1d323 Make *_PRESENT fields constant at build time
See gh-28624
2022-06-29 12:31:46 +02:00
Sam Brannen 1374d6d912 Merge branch '5.3.x' 2022-06-28 14:24:58 +02:00
Sam Brannen 622fc3edf7 Fix merged annotation attributes regression
Commit d6768ccc18 introduced a regression in the support for merging
annotation attributes in a multi-level annotation hierarchy.

This commit addresses that issue by ensuring that a merged annotation
is once again synthesized if a meta-annotation in the annotation
hierarchy declares attributes that override attributes in the target
annotation.

Closes gh-28716
2022-06-28 14:22:53 +02:00
Sébastien Deleuze efb83fa064 Prevent duplicated logs in ConstantFieldSubstitutionProcessor
See gh-28624
2022-06-27 19:08:37 +02:00
Sébastien Deleuze f8508c805f Refine KotlinDetector for compliance with ConstantFieldFeature
After this commit, KotlinDetector#kotlinPresent is
computed at build time.

See gh-28624
2022-06-27 19:08:27 +02:00
Sébastien Deleuze 798dd4fec0 Add missing build time class initialization
As gh-28624 supports only static boolean fields, we still
need a few classes to be initialized at build time.

Such explicit configuration should be in theory avoidable,
so we will work with the GraalVM team to see if this can be
fixed, see for example
https://github.com/oracle/graal/issues/4673
for HttpStatus.

See gh-28624
2022-06-27 19:08:20 +02:00
Sam Brannen af16e49334 Merge branch '5.3.x'
# Conflicts:
#	spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java
#	spring-context/src/test/java/org/springframework/context/support/GenericApplicationContextTests.java
2022-06-27 18:14:00 +02:00
Sam Brannen 9868c28c73 Honor ProtocolResolvers in GenericApplicationContext
When the ProtocolResolver SPI was introduced in Spring Framework 4.3,
support for protocol resolvers was added in DefaultResourceLoader's
getResource() implementation; however, GenericApplicationContext's
overridden getResource() implementation was not updated accordingly.

Prior to this commit, if a GenericApplicationContext was configured
with a custom ResourceLoader, registered protocol resolvers were
ignored.

This commit ensures that protocol resolvers are honored in
GenericApplicationContext even if a custom ResourceLoader is used.

Closes gh-28703
2022-06-27 18:00:29 +02:00
Sam Brannen 5e5e95aff7 Polish RuntimeHintsUtils 2022-06-27 16:29:34 +02:00
Sébastien Deleuze 58aeab3ab6 Refactor BindingReflectionHintsRegistrar
This commit splits registerReflectionHints in multiple
methods.

See gh-28683
2022-06-27 12:20:29 +02:00
Sébastien Deleuze fb1aa4f5d5 Fix BindingReflectionHintsRegistrar enum support
This commit prevents a StackOverflowError in
BindingReflectionHintsRegistrar when processing enum types
and refine related generated hints.

See gh-28683
2022-06-27 12:18:43 +02:00
Sam Brannen 730d6c95fc Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java
2022-06-25 20:14:27 +02:00
Sam Brannen d6768ccc18 Ensure meta-annotations are not unnecessarily synthesized
Prior to this commit, meta-annotations were unnecessarily synthesized
when attempting to synthesize a MergedAnnotation retrieved via the
MergedAnnotations.from(AnnotatedElement, ...).get(<annotationType>) API.

This is a regression in our merged annotation support that was
introduced when the MergedAnnotations API replaced our previous support.

This commit fixes this by revising the logic in TypeMappedAnnotation's
createSynthesizedAnnotation() method so that a meta-annotation is
returned unmodified if it is not synthesizable.

This commit also updates BootstrapUtilsTests, since @BootstrapWith
should never have been synthesized, and Class#getCanonicalName() is
only used in the toString() implementation of an annotation synthesized
by Spring or normal annotations on Java 19+ (see
https://bugs.openjdk.org/browse/JDK-8281462).

Closes gh-28704
2022-06-25 20:02:04 +02:00
Sam Brannen faf20b7a5a Polish MergedAnnotations Javadoc and internals 2022-06-25 19:50:03 +02:00
Sébastien Deleuze 1aaa44bbfe Refine BindingReflectionHintsRegistrar
This commit refines BindingReflectionHintsRegistrar to handle
correctly a use case with multiple levels of nested generics.

Closes gh-28683
2022-06-24 15:43:03 +02:00
Sébastien Deleuze 22a750f378 Replace build-time initialization by constant fields
This commit leverages a subset of @philwebb initial experimentation
to compute at build time the value of specific boolean static fields
in native images. This enhancement is implemented for now as a
GraalVM feature.

The goal here is to keep an optimized footprint via build time code
removal without leveraging build-time class initialization which is known
for the blocking compatibility issues it introduces due to its viral nature.

For now, the static fields initialized at build time with native are:
 - NativeDetector#imageCode
 - Fields with a name ending by "Present" in "org.springframework" package
   typically used for classpath check with ClassUtils#isPresent

Closes gh-28624
2022-06-24 13:54:20 +02:00
Stephane Nicoll 6199835d6e Harmonize generated class name conventions
This commit moves the responsibility of naming classes to the
GenerationContext. This was already largely the case before, except that
the concept of a "mainTarget" and "featureNamePrefix" was specific
to bean factory initialization contributors.

ClassNameGenerator should now be instantiated with a default target
and an optional feature name prefix. As a result, it does no longer
generate class names in the "__" package.

GeneratedClasses can now provide a new, unique, GeneratedClass or
offer a container for retrieving the same GeneratedClass based on an
identifier. This lets all contributors use this facility rather than
creating JavaFile manually. This also means that ClassNameGenerator
is no longer exposed.

Because the naming conventions are now part of the GenerationContext, it
is required to be able to retrieve a specialized version of it if a
code generation round needs to use different naming conventions. A new
withName method has been added to that effect.

Closes gh-28585
2022-06-23 16:05:23 +02:00
Sébastien Deleuze b121eed753 Refine BindingReflectionHintsRegistrar
This commit refines BindingReflectionHintsRegistrar to skip
registration of hints for Object.class, primitive types and
skip members for array types.

Closes gh-28683
2022-06-23 15:42:09 +02:00
Sébastien Deleuze 61e9aa9f42 Fix StackOverflowError in BindingReflectionHintsRegistrar
This commit fixes the cycle detection in
BindingReflectionHintsRegistrar.

See gh-28683
2022-06-23 15:40:19 +02:00
Stephane Nicoll 0f4205adbf Polish assertions 2022-06-21 08:03:26 +02:00
Sébastien Deleuze 93b340e563 Add reflection hints for HttpEntity
For those used in Web controllers.

Closes gh-28622
2022-06-20 18:15:43 +02:00
Sam Brannen 789329fa3b Revise signature of SpringFactoriesLoader.forResourceLocation(...)
When an overloaded method accepts additional "optional" arguments, we
typically declare the optional arguments after the required arguments.
For example, see the constructors for ClassPathResource.

This commit therefore revises the signature of the overloaded
forResourceLocation() method so that the optional ClassLoader argument
follows the required `String resourceLocation` argument.
2022-06-20 17:39:01 +02:00
Sam Brannen b611157108 Polish SpringFactoriesLoader 2022-06-20 17:12:21 +02:00
Sam Brannen 1bbc5648f9 Polishing 2022-06-20 17:03:57 +02:00
Stephane Nicoll 08f4b7a0f1 Polish "Fix enclosing class in TypeReference for inner type arrays"
See gh-28664
2022-06-20 15:57:33 +02:00
Moritz Halbritter c34de54d8a Fix enclosing class in TypeReference for inner type arrays
See gh-28664
2022-06-20 15:53:09 +02:00
Stephane Nicoll 63fae8c5a7 Clarify the scope of target in ClassNameGenerator
Closes gh-28517
2022-06-20 11:11:26 +02:00
Sébastien Deleuze 16d6dc3611 Add Kotlinx Serialization support to BindingReflectionHintsRegistrar
Closes gh-28635
2022-06-15 17:52:17 +02:00
Stephane Nicoll ff9535ef15 Add file pattern resource hints registrar
This commit adds a utility method to register resources on the classpath
based on a location, name, and extension.

Closes gh-28626
2022-06-14 18:16:18 +02:00
Brian Clozel 7f7f458a59 Polish ResourceHintsPredicates
As of #28620, `ResourcePatternHint` exposes its `toRegex` method.
The predicates should use it directly and mirror the exact matching
behavior.

See gh-28555
2022-06-14 15:38:41 +02:00
Juergen Hoeller aa48dec697 Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java
2022-06-14 15:14:10 +02:00
Juergen Hoeller d7be1e0dab Polishing 2022-06-14 15:09:39 +02:00
Juergen Hoeller f8b41c1ad2 Consistent support for setContextClass in CGLIB beans package
Closes gh-28530
2022-06-14 15:08:44 +02:00
Sébastien Deleuze c235ad0b35 Introduce ResourcePatternHint#toRegex
This change is done for several reasons:
 - Move the logic where it is documented.
 - Test it with ResourcePatternHintTests.
 - Allow RuntimeHintsPredicates to leverage this logic.

Closes gh-28620
2022-06-14 15:07:12 +02:00
Stephane Nicoll 77ad4a1428 Polish 2022-06-14 14:15:29 +02:00
Stephane Nicoll d6d4b98780 Add ifPresent utility methods on RuntimeHints
This commit adds a utility method to register a type for reflection if
it is available on the classpath. It also adds a method to register a
resource pattern if a given location is available.

Closes gh-28617
2022-06-14 14:15:29 +02:00
Juergen Hoeller c4e8ffece1 Remove outdated NativeDetector check for Kotlin reflection
See gh-25179
2022-06-14 14:02:41 +02:00
Juergen Hoeller 4e1b9f1492 Replace deep exception message nesting with custom inclusion of cause messages
Includes deprecation of NestedServletException, whereas NestedCheckedException and NestedRuntimeException remain as base classes with several convenience methods.

Closes gh-25162
2022-06-14 14:00:28 +02:00
Arjen Poutsma bf9f261b95 Revert "Support recursive annotations in merged annotations"
This reverts commit 3ec612aaf8.
2022-06-14 13:03:29 +02:00
Arjen Poutsma df37e33105 Revert "Ensure fix for gh-28012 is actually tested"
This reverts commit 3188c0f7db.
2022-06-14 13:03:05 +02:00
Brian Clozel 7e8b1ed401 Polish
Move hints registration to spring-beans, where the actual behavior is
implemented. We chose not to move this to
`AutowiredAnnotationBeanPostProcessor` for now, as this would require it
to implement another AOT-related interface and add too much noise for
this.

See gh-28614
2022-06-14 10:08:06 +02:00
Brian Clozel bb952cb95e Register native hints for jakarta.inject annotations
Prior to this commit, native images would dynamically check for the
presence of `jakarta.inject.*` annotations and might fail at runtime or
miss them entirely.

This change ensures that if such classes are present during the AOT
build, relevant runtime hints are registered so that these annotations
can be read at runtime.

Closes gh-28614
2022-06-13 18:50:33 +02:00
Brian Clozel 15b69a3ede Polish RuntimeHintsPredicates
This commit adds a method variant checking that all `MemberCategory` are
supported by the `RuntimeHints` for a given type hint.

See gh-28555
2022-06-13 18:40:46 +02:00
Sam Brannen dc3ec5b665 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java
2022-06-13 18:06:08 +02:00
Sam Brannen 97854d9fec Refactor ObjectToObjectConverter to use Executable instead of Member 2022-06-13 18:01:54 +02:00
Sam Brannen 73f3860bb7 Polish Javadoc for ObjectToObjectConverter 2022-06-13 18:01:05 +02:00
Sam Brannen f722dbe5a8 Polishing 2022-06-13 17:35:50 +02:00
Sam Brannen c3b29960ed Merge branch '5.3.x' 2022-06-13 17:23:14 +02:00
Sam Brannen 452f1b877c Consider return type of static methods in ObjectToObjectConverter
Prior to this commit, ObjectToObjectConverter considered the return
type of non-static `to[targetType.simpleName]()` methods but did not
consider the return type of static `valueOf(sourceType)`,
`of(sourceType)`, and `from(sourceType)` methods.

This led to scenarios in which `canConvert()` returned `true`, but a
subsequent `convert()` invocation resulted in a
ConverterNotFoundException, which violates the contract of the
converter.

This commit addresses this issue by taking into account the return type
of a static valueOf/of/from factory method when determining if the
ObjectToObjectConverter supports a particular conversion. Whereas the
existing check in `determineToMethod()` ensures that the method return
type is assignable to the `targetType`, the new check in
`determineFactoryMethod()` leniently ensures that the method return
type and `targetType` are "related" (i.e., reside in the same type
hierarchy).

Closes gh-28609
2022-06-13 17:20:18 +02:00
Sébastien Deleuze a57dead4be Add support for serialization in RequestMappingReflectiveProcessor
Support reflection-based serialization of parameters annotated
with @RequestBody and return values annotated with @ResponseBody.

It leverages a new BindingReflectionHintsRegistrar class that
is designed to register transitively the types usually needed
for binding and reflection-based serialization on fields,
constructors and properties. Generics are taken in account
as well.

Closes gh-28518
2022-06-13 15:25:44 +02:00
Sébastien Deleuze 2b76a12b86 Refine build time init configuration
For Spring MVC and RestTemplate.

See gh-28518
2022-06-13 14:54:57 +02:00
Brian Clozel 9c9b2356ce Add RuntimeHints predicates generator
The `RuntimeHints` API allows to describe hints for the reflection,
proxies and resources behavior at runtime. The need for a particular
behavior can be covered by several types of hints, at different levels.
This knowledge can be important in several cases:

* before contributing additional hints, infrastructure can check if an
  existing hint already covers the behavior
* this can be used in test suites and test infrastructure

This commit adds a new RuntimeHintsPredicates that generates `Predicate`
instances for testing `RuntimeHints` against a desired runtime behavior
for reflection, resources or proxies.

Closes gh-28555
2022-06-10 18:55:14 +02:00
Stephane Nicoll 100ce9642a Use TypeReference consistently in hints writer
Closes gh-28606
2022-06-10 15:28:24 +02:00
Stephane Nicoll 1e5f4f8b44 Polish 2022-06-09 15:12:38 +02:00
Sébastien Deleuze b9f85627a1 Improve ResourcePatternHint documentation
Closes gh-28598
2022-06-09 14:50:43 +02:00
Sébastien Deleuze 99ffd97a72 Fix ResourceHintsWriter for leading/trailing wildcards
Closes gh-28597
2022-06-09 14:50:43 +02:00
Stephane Nicoll 16eff68357 Fix package tangle between o.s.core and o.s.aot
Closes gh-28496
2022-06-08 11:53:51 +02:00
rstoyanchev 875ee546e5 Merge branch '5.3.x' 2022-06-08 10:43:36 +01:00
rstoyanchev 8fcc7ab9d1 CompositeLog respects log level changes at runtime
Closes gh-28477
2022-06-08 10:07:52 +01:00
Phillip Webb 4bd33cb6e0 Allow ApplicationContextAotGenerator to generated better class names
Update `ApplicationContextAotGenerator` so that it can generate class
names based on a `target` class and using the ID of the application
context. Prior to this commit, the generated class name was always
`__.BeanFactoryRegistrations`.

Closes gh-28565
2022-06-03 18:15:37 -07:00
Sébastien Deleuze 74c49c510a Use a single --initialize-at-build-time parameter per file
Closes gh-28563
2022-06-03 17:39:47 +02:00
Sam Brannen 92f8ab774f Stop initializing DataSize at build time for GraalVM
In light of gh-28560, this commit reverts the change made in gh-28328.

Closes gh-28562
2022-06-03 16:41:36 +02:00
Sam Brannen 73acab7635 Merge branch '5.3.x'
# Conflicts:
#	spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContextUtils.java
2022-06-03 13:35:22 +02:00
Sam Brannen e2767371b5 Lazily initialize DataSize.PATTERN
To avoid unnecessary eager initialization of DataSize.PATTERN, this
commit initializes it lazily in the first invocation of DataSize.parse
by moving PATTERN to a private static nested class.

Closes gh-28560
2022-06-03 13:30:45 +02:00
Stephane Nicoll da8c4de263 Add AotDetector to reliably opt-in for optimizations
This commit adds a central utility to figure out if the application
must run with Ahead-Of-Time optimizations. This is mandatory for running
in a native image but can be selected on the JVM using the
"spring.aot.enabled" property.

This commit also introduces a utility that can be used to initialize a
context with generated artifacts. This represents the runtime
counterpart of ApplicationContextAotGenerator.

Closes gh-28474
2022-06-02 14:52:11 +02:00
Brian Clozel 8af1496b37 Expand hints conditions support in RuntimeHints
Prior to this commit, the hints conditions were only supported for the
`TypeHint` case. GraalVM generally expanded this concept to all hints
and we should do the same.

Right now, only the `typeReachable` condition is available but we should
design for possible future additions.

This commit introduces a new `ConditionalHint` contract implemented by
all hints compatible with this approach. The condition information is
also used in all configuration writers as a result.

Closes gh-28126
2022-06-02 11:35:03 +02:00
Arjen Poutsma d9d45cc0b1 Treat Reactive Publishers the same as Kotlin Flows
This commit makes sure that CoroutinesUtils::invokeSuspendingFunction
treats Reactive Publisher instances the same as Kotlin Flows, i.e.
it flatmaps them.

Closes gh-27011
2022-06-01 14:30:40 +02:00
Sam Brannen ee209de9cf Merge branch '5.3.x'
# Conflicts:
#	spring-beans/src/test/java/org/springframework/beans/factory/support/security/CallbacksSecurityTests.java
#	spring-context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java
#	spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java
#	spring-web/src/test/java/org/springframework/remoting/jaxws/JaxWsSupportTests.java
#	spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java
2022-05-31 14:15:36 +02:00
Sam Brannen 1beb7068f6 Use new AssertJ exception assertions 2022-05-31 14:08:28 +02:00
Sam Brannen b79f981510 Document Checkstyle issue regarding instanceof pattern variables
See https://github.com/checkstyle/checkstyle/issues/10969
2022-05-30 19:58:21 +02:00
Sam Brannen 16f65e59b4 Polish contribution
See gh-28188
2022-05-30 19:35:28 +02:00
Sam Brannen 43dd813ee6 Temporary workaround for Checkstyle bug
Attempting to name a variable in an "instanceof pattern" the same as
a field results in a Checkstyle violation similar to the following if
the "instanceof pattern matching" is located within a constructor.

Reference to instance variable 'document' needs "this.". [RequireThis]

See gh-28188
2022-05-30 19:35:28 +02:00
diguage bbaf7578b2 Apply "instanceof pattern matching" in spring-core
Closes gh-28188
2022-05-30 19:29:48 +02:00
Sam Brannen 720261db26 Use List.of() and Set.of() where feasible 2022-05-30 18:42:48 +02:00
Sam Brannen ad46f0295c Apply "instanceof pattern matching" 2022-05-30 18:41:25 +02:00
Phillip Webb 718ef42d68 Exclude @Reflective from @AliasFor collection
Update `RuntimeHintsUtils` to skip `@Reflective` annotations when
checking for `@AliasFor`. Since the `@Reflective` annotation is only
used at AOT processing time, we shouldn't need a hint for it.

See gh-28528
2022-05-26 20:56:06 -07:00
Stephane Nicoll 86a85f558c Fix introspection of annotations that use local aliased attributes
Closes gh-28528
2022-05-26 15:50:41 +02:00
Stephane Nicoll 059b66bf26 Register annotation based on its type
This commit improves registerAnnotation to use the annotation type
rather than a `MergedAnnotation` attribute.

See gh-28497
2022-05-25 10:30:43 +02:00
Sam Brannen 291f784196 Suppress warning in test 2022-05-24 17:12:16 +02:00
Sam Brannen 19b436c6aa Support module path scanning for "classpath*:" resource prefix
Prior to this commit, searching for classpath resources using the
"classpath*:" resource prefix did not find all applicable resources for
applications deployed as modules -- for example, when test classes and
resources are patched into the application module automatically by
Maven Surefire.

This affected component scanning -- for example, via [@]ComponentScan --
and PathMatchingResourcePatternResolver.getResources(String) in
general.

This commit addresses this by introducing first-class support for
scanning the module path when PathMatchingResourcePatternResolver's
getResources(String) method is invoked with a location pattern using
the "classpath*:" resource prefix. Specifically, getResources(String)
first searches all modules in the boot layer, excluding system modules.
It then searches the classpath using the existing Classloader-based
algorithm and returns the combined results.

Closes gh-28506
2022-05-24 12:09:36 +02:00
Stephane Nicoll 6bd25f60dd Polish 2022-05-24 11:57:14 +02:00
Sam Brannen 29a9016809 Merge branch '5.3.x' 2022-05-23 20:36:47 +02:00
Sam Brannen 7b95c928d1 Fix Javadoc for ResourcePatternResolver 2022-05-23 20:32:01 +02:00
Sam Brannen 53f88d455f Fix Javadoc for AbstractFileResolvingResource.isFile(URI) 2022-05-23 20:32:01 +02:00
Sam Brannen 53a506f6bb Polishing 2022-05-23 20:22:37 +02:00
Sam Brannen f07e7ab39d Create UrlResource factory methods that throw unchecked exceptions
UrlResource constructors throw checked exceptions which makes it
difficult to use them in java.util.Stream and java.util.Optional APIs
or other scenarios when a checked IOException is undesirable.

To support such use cases, this commit introduces `from(URI)` and
`from(String)` factory methods in UrlResource that throw
UncheckedIOExceptions.

Closes gh-28501
2022-05-23 14:22:52 +02:00
Sam Brannen 4515180195 Polish PathMatchingResourcePatternResolver 2022-05-23 14:22:43 +02:00
Stephane Nicoll 2f94713078 Make sure that annotation hierarchy is registered
This commit improves registerAnnotation to also registers the meta
annotation sources, if any. Without them, the annotation could not
be fully resolved.

See gh-28497
2022-05-23 08:57:02 +02:00
Stephane Nicoll 4cca190aad Add support of declarative use of reflection
This commit adds a `@Reflective` annotation that can be used to declare
that the annotated element requires reflection at runtime. By default,
the annotated element is exposed but this can be customized by
specifying a dedicated `ReflectiveProcessor`.

Closes gh-28469
2022-05-20 15:02:46 +02:00
Stephane Nicoll 2517c72f7d Add a common utility to register hints for an annotation
This commit adds a utility that takes care of registering the necessary
hints to make an annotation visible at runtime. The core framework may
create a JDK proxy if necessary, which requires specific handling.

Closes gh-28497
2022-05-20 14:54:27 +02:00
Sam Brannen 70415b1781 Merge branch '5.3.x' 2022-05-17 15:41:08 +02:00
Sam Brannen 59c7bb1f86 Use Arrays.toString instead of Arrays.asList when generating Strings 2022-05-17 15:36:31 +02:00
Sam Brannen fe7c6f075b Polishing 2022-05-16 10:53:35 +02:00
izeye 0fb0335aa0 Add level guards for trace logging in SpringFactoriesLoaderRuntimeHintsRegistrar
Closes gh-28465
2022-05-16 09:07:25 +02:00
Sam Brannen 6a67b4a2aa Polish SpringFactoriesLoaderRuntimeHintsRegistrar
See gh-27955
2022-05-11 16:18:06 +02:00
Brian Clozel e6c0152916 Force AOT resolution of Spring Factories constructors
This commit forces the resolution of all declared constructors when
registering `RuntimeHints` for Spring factories. Resolving constructors
can throw additional `NoClassDefFoundError` at runtime and during native
image compilation, if a type exposed by the constructor is missing from
the current classloader.

See gh-27955
2022-05-11 12:11:14 +02:00
Phillip Webb 2961426d8a Fix checkstyle issues and test failures
See gh-27955
See gh-28442
2022-05-10 18:33:15 -07:00
Brian Clozel 267b91486e Add native hints for SpringFactoriesLoader file content
Add `SpringFactoriesLoaderRuntimeHintsRegistrar` which provides
native hints for `spring.factories` content.

Closes gh-27955

Co-authored-by: Phillip Webb <pwebb@vmware.com>
2022-05-10 17:08:49 -07:00
Phillip Webb e7e60f7cb9 Add native hints for core annotations
Add `CoreAnnotationsRuntimeHintsRegistrar` to provide native hints
for `@Order` and `@AliasFor`.

Closes gh-28442
2022-05-10 16:11:36 -07:00
Phillip Webb 4cebd9d392 Fix SpringFactoriesLoader cache key when using default classloader
Update `SpringFactoriesLoader` so that `null` is never used for the
cache key. Prior to this commit, calling `forDefaultResourceLocation`
with `null` and `ClassUtils.getDefaultClassLoader()` would provide
different `SpringFactoriesLoader` instances rather than making use
of a single shared cached instance.

See gh-28416
2022-05-10 16:07:50 -07:00
Sam Brannen 5f8a4bcdc5 Merge branch '5.3.x'
# Conflicts:
#	spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java
#	spring-context/src/main/java/org/springframework/scripting/support/StandardScriptFactory.java
2022-05-09 20:08:37 +02:00
Sam Brannen e26d8839b3 Stop referring to features as Java 6/7 features where unnecessary 2022-05-09 19:09:06 +02:00
Juergen Hoeller 2b65f274dc Use Set.of instead of HashSet with Arrays.asList 2022-05-06 16:19:27 +02:00
Sam Brannen 8627bef8d9 Polishing 2022-05-06 16:02:42 +02:00
Phillip Webb 16e7f1f212 Complete refactor of AOT concepts
Remove the AOT code that now has an alternative API.

Closes gh-28414
2022-05-05 13:34:52 -07:00
Phillip Webb c5c68a4662 Add MethodReference support
Add a `MethodReference` class which can be used to refer to a
static or instance method.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb 1816c77c51 Add generation context interface
Add `GenerationContext` interface and `DefaultGenerationContext`
implementation as the central entry point for AOT processing.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb d5374550e5 Add support for generating classes
Add `ClassGenerator` and `GeneratedClass` which can be used to
generated classes that will ultimately be written to a `JavaFile`.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb 55d7f7a014 Add support for generating methods
Add `GeneratedMethods` and `GeneratedMethod` support classes which
can be used during code generation to generation additional methods
that will ultimately be included in a `JavaFile`.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb 16456342f5 Add support for generating method names
Add `MethodNameGenerator` to support generation of method names.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb ca2b5e068b Add support for generating class names
Add `ClassNameGenerator` to support generation of class names.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb a605d3f6ed Add AccessVisibility detection support
Add `AccessVisibility` enum which can be used to determine the
access visibility of `Member` or `ResolvableType`.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb 99173fbd4f Add GeneratedFiles interface and support classes
Add a `GeneratedFiles` interface that can be used to add generated
source, class and resource files. An in-memory implementation is
provided for testing and a filesystem implementation is provided
to actually save the files to disk.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb b3efdf3c2b Add Throwable functional interfaces
Add 'Throwable' variants of the `Consumer`, `Function`, `BiFunction` and
`Supplier` interfaces that wrap checked exceptions or allow calls to be
made that throw them.

Closes gh-28417
2022-05-05 12:35:21 -07:00
Phillip Webb 58c441f961 Support multiple SpringFactoriesLoader files
Update `SpringFactoriesLoader` so that it can load files from
arbitrary locations. An instance of the loader class itself is now
returned from static factory methods that accept different
locations.

The recent `ArgumentResolver` and `FailureHandler` `loadFactories`
variants are now no longer available as static methods. They are
still available as instance methods.

The `loadFactories` static method remains to provide
back-compatibility with Spring Framework 5.x

See gh-28416
2022-05-05 12:35:21 -07:00
Phillip Webb f17372ebea Add position variant of ObjectUtils.addObjectToArray
Add an overloaded version of `ObjectUtils.addObjectToArray` that allows
inserts at a specific position.

Closes gh-28415
2022-05-05 12:35:21 -07:00
Juergen Hoeller bf4e3975fb Merge branch '5.3.x'
# Conflicts:
#	build.gradle
2022-05-05 18:07:39 +02:00
Juergen Hoeller f771603789 Polishing 2022-05-05 18:04:54 +02:00
Juergen Hoeller b55eee1b0d Upgrade to ASM 9.3
Closes gh-28390
2022-05-05 18:01:53 +02:00
Juergen Hoeller 122ca4dd98 Assert with isEqualToNormalizingNewlines for Windows compatibility 2022-05-05 17:26:33 +02:00
Sam Brannen 62fcf5e60d Merge branch '5.3.x' 2022-05-05 16:23:19 +02:00
Sam Brannen ab71ff93bb Polish package-info for org.springframework.util
See gh-28411
2022-05-05 16:22:52 +02:00
neals cf30327740 Remove Log4J configurer from package-info.java in spring-core
Closes gh-28411
2022-05-05 16:16:49 +02:00
Stephane Nicoll 5378572b00 Clarify lambda code block methods 2022-04-26 15:13:43 +02:00
Stephane Nicoll 26054fd3d4 AOT contribution for @PersistenceContext and @PersistenceUnit
Closes gh-28364
2022-04-25 11:01:09 +02:00
Stephane Nicoll 10d254983f Refine MultiStatement#toClodeBlock
Closes gh-28363
2022-04-25 09:13:50 +02:00
Stephane Nicoll ccb66247ce Merge branch '5.3.x' 2022-04-24 10:05:35 +02:00
izeye fcf64798b5 Add Javadoc since for GraphQL constants
See gh-28369
2022-04-24 09:58:50 +02:00
Stephane Nicoll f40a391916 Fix handling of reflection target name in TypeReference
This commit adds a `getName` to `TypeReference` that provides a way to
generate the reflection target name of a type. This typically handle
primitives (omitting the `java.lang` packages) and arrays.

Closes gh-28347
2022-04-15 11:47:25 +02:00
Brian Clozel 38019d2249 Allow static registration of RuntimeHints
Prior to this commit, we could only contribute `RuntimeHints` through
two mechanisms:
* `AotContributingBeanFactoryPostProcessor`, consdering the entire
  `BeanFactory` and designed for contributing both code and hints.
* `AotContributingBeanPostProcessor`, consdering beans one by one, but
  also designed for contributing both code and hints.

There are cases where libraries and applications want to contribute
`RuntimeHints` only, in a more static fashion: a dependency being
present, or a piece of infrastructure being considered by the
application context are good enough signals to contribute hints about
resources or reflection.

This commit adds the `RuntimeHintsRegistrar` contract for these cases.
Implementations can be declared as `spring.factories` and they will be
processed as soon as they're detected on the classpath. They can also be
declared with `@ImportRuntimeHints` and they will be processed if the
annotated bean definition is considered in the application context.
This annotation should be mainly used on configuration classes and on
bean methods.

```
@Configuration
@ImportRuntimeHints(CustomRuntimeHintsRegistrar.class)
public class MyConfiguration {

  @Bean
  @ImportRuntimeHints(OtherRuntimeHintsRegistrar.class)
  public MyBean myBean() {
    //...
  }
}
```

Closes gh-28160
2022-04-14 13:06:43 +02:00
Stephane Nicoll 5be6b3d2a7 Add shortcut method to register multiple types hints
Closes gh-28339
2022-04-14 10:22:07 +02:00
Stephane Nicoll 780d07217b Hide builder implementations in RuntimeHints API 2022-04-14 10:05:38 +02:00
Stephane Nicoll ab7213c823 Merge branch '5.3.x' 2022-04-12 16:14:05 +02:00
Stephane Nicoll 8b39698553 Upgrade to Reactor 2020.0.18
Closes gh-28329
2022-04-12 15:53:10 +02:00
Stephane Nicoll 64570a85b3 Allow DataSize to be initialized at build time
Previously, Graal failed to build a native image as DataSize was
unintentionally initialized at build time. This commit workarounds the
faulty assumption by flagging it as safe to initialize at build-time.

Closes gh-28328
2022-04-12 11:33:45 +02:00
Stephane Nicoll 3c37fa2edf Polish 2022-04-12 08:01:55 +02:00
Stephane Nicoll 069aab37cd Use proper format for TypeReference
This commit updates BasicJsonWriter to handle TypeReferences and
generate an appropriate format for a class name. Specifically, an
inner class should be separated by a dollar sign, not a dot.

Closes gh-28312
2022-04-11 16:57:22 +02:00
Stephane Nicoll 10dc10dbf9 Make JSON assertions more strict 2022-04-11 16:36:04 +02:00
Stephane Nicoll f65136dd68 Harmonize the use of Writer rather than Generator 2022-04-11 16:18:42 +02:00
Stephane Nicoll 4e9306fa1b Adapt to BasicJsonWriter 2022-04-11 15:46:57 +02:00
Stephane Nicoll f24369b49c Introduce basic json writer for native configuration processing 2022-04-11 15:43:26 +02:00
Stephane Nicoll 1cf112bfa4 Harmonize json format in tests 2022-04-11 15:42:35 +02:00
Sam Brannen c9e7816762 Merge branch '5.3.x' 2022-04-09 10:43:02 +02:00
Sam Brannen 5f6d8df34b Introduce isLambdaClass() as a public utility in ClassUtils
This commit extracts isLambda() from AopProxyUtils and makes it
publicly available as ClassUtils.isLambdaClass().

This is a prerequisite for gh-28209.
2022-04-09 09:57:43 +02:00
Juergen Hoeller 7e1782ea22 Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-core/src/main/java/org/springframework/core/convert/Property.java
2022-04-08 13:10:34 +02:00
Juergen Hoeller 4143b445d6 Polishing 2022-04-08 13:04:14 +02:00
Brian Clozel 705bf78104 Consistently handle match with '*' and trailing slash
Prior to this commit, the `AntPathMatcher` would inconsistently match
pattern with trailing slashes if they contain `"**"` within their
pattern.

For example `"/en/test/"` would match `"/**/test"`, but it would not
match `"/*/test"` (as it should).

This commit fixes this behavior for better consistency.

Fixes gh-27506
2022-04-04 18:51:03 +02:00
Brian Clozel fd1346bf66 Merge branch '5.3.x' 2022-04-01 19:25:11 +02:00
Brian Clozel 17f7a24118 Add application/graphql+json mime and media types
Closes gh-28271
2022-04-01 19:24:55 +02:00
Sam Brannen 02d3e00d33 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/main/java/org/springframework/util/SerializationUtils.java
2022-03-29 15:28:19 +02:00
Sam Brannen 3811cd4c0a Introduce warnings in documentation of SerializationUtils
Closes gh-28246
2022-03-29 15:22:30 +02:00
Sam Brannen c8d0146bcc Polish contribution
See gh-28075
2022-03-29 13:39:40 +02:00
Loïc Ledoyen 7f7fb58dd0 Deprecate SerializationUtils#deserialize
Since SerializationUtils#deserialize is based on Java's serialization
mechanism, it can be the source of Remote Code Execution (RCE)
vulnerabilities.

Closes gh-28075
2022-03-29 13:07:36 +02:00
Sébastien Deleuze e681e713d4 Initialize NativeDetector at build time
Closes gh-28244
2022-03-29 08:50:41 +02:00
Sébastien Deleuze 77a8cbcbec Remove outdated comment in NativeDetector
`-H:+InlineBeforeAnalysis` is enabled by default as of
GraalVM 21.3.
2022-03-29 08:32:02 +02:00
Juergen Hoeller 12d8010395 Merge branch '5.3.x' 2022-03-25 18:08:55 +01:00
Juergen Hoeller cb36ca31f6 Upgrade to ASM master 2022-03-25 18:07:12 +01:00
Sam Brannen 42a61b966b Remove TYPE_HIERARCHY_AND_ENCLOSING_CLASSES strategy for MergedAnnotations
This commit removes the deprecated TYPE_HIERARCHY_AND_ENCLOSING_CLASSES
search strategy from the MergedAnnotations model.

As a direct replacement for the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES
search strategy, users can use the new fluent search API as follows.

MergedAnnotations mergedAnnotations =
   MergedAnnotations.search(TYPE_HIERARCHY)
      .withEnclosingClasses(clazz -> true) // always search enclosing classes
      .from(MyClass.class);

Note, however, that users are highly encouraged to use
ClassUtils::isInnerClass, ClassUtils::isStaticClass, or a custom
predicate other than `clazz -> true`.

Closes gh-28080
2022-03-24 16:31:12 +01:00
Sam Brannen 1fe394f11d Introduce predicate for searching enclosing classes in MergedAnnotations
Due to the deprecation of the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES
search strategy (see gh-28079), this commit introduces a way for users
to provide a Predicate<Class<?>> that is used to decide when the
enclosing class for the class supplied to the predicate should be
searched.

This gives the user complete control over the "enclosing classes"
aspect of the search algorithm in MergedAnnotations.

- To achieve the same behavior as TYPE_HIERARCHY_AND_ENCLOSING_CLASSES,
  a user can provide `clazz -> true` as the predicate.

- To limit the enclosing class search to inner classes, a user can
  provide `ClassUtils::isInnerClass` as the predicate.

- To limit the enclosing class search to static nested classes, a user
  can provide `ClassUtils::isStaticClass` as the predicate.

- For more advanced use cases, the user can provide a custom predicate.

For example, the following performs a search on MyInnerClass within the
entire type hierarchy and enclosing class hierarchy of that class.

MergedAnnotations mergedAnnotations =
   MergedAnnotations.search(TYPE_HIERARCHY)
      .withEnclosingClasses(ClassUtils::isInnerClass)
      .from(MyInnerClass.class);

In addition, TestContextAnnotationUtils in spring-test has been
revised to use this new feature where feasible.

Closes gh-28207
2022-03-24 15:40:44 +01:00
Brian Clozel 7161940b53 Merge branch '5.3.x' 2022-03-24 13:44:38 +01:00
Yanming Zhou acf2955b96 Ban jetbrains annotations imports
Closes gh-28226
2022-03-24 13:31:36 +01:00
Sam Brannen c23edf7da6 Introduce fluent API for searches in MergedAnnotations
Prior to this commit, searching for merged annotations on an
AnnotatedElement in the MergedAnnotations model was only supported via
various overloaded from(...) factory methods. In addition, it was not
possible to provide a custom AnnotationFilter without providing an
instance of RepeatableContainers.

This commit introduces a fluent API for searches in MergedAnnotations
to address these issues and improve the programming model for users of
MergedAnnotations.

To begin a search, invoke MergedAnnotations.search(SearchStrategy) with
the desired search strategy. Optional configuration can then be
provided via one of the with(...) methods. To perform a search, invoke
from(AnnotatedElement), supplying the element from which to begin the
search -- for example, a Class or a Method.

For example, the following performs a search on MyClass within the
entire type hierarchy of that class while ignoring repeatable
annotations.

MergedAnnotations mergedAnnotations =
    MergedAnnotations.search(SearchStrategy.TYPE_HIERARCHY)
        .withRepeatableContainers(RepeatableContainers.none())
        .from(MyClass.class);

To reuse search configuration to perform the same type of search on
multiple elements, you can save the Search instance as demonstrated in
the following example.

Search search = MergedAnnotations.search(SearchStrategy.TYPE_HIERARCHY)
                    .withRepeatableContainers(RepeatableContainers.none());

MergedAnnotations mergedAnnotations = search.from(MyClass.class);
// do something with the MergedAnnotations for MyClass
mergedAnnotations = search.from(AnotherClass.class);
// do something with the MergedAnnotations for AnotherClass

In addition, this fluent search API paves the way for introducing
support for a predicate that controls the search on enclosing classes
(gh-28207) and subsequently for completely removing the
TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy (gh-28080).

Closes gh-28208
2022-03-22 20:01:24 +01:00
Sam Brannen 23d0240dc7 Introduce ClassUtils.isStaticClass() utility method
The impetus for this is to be able to use ClassUtils::isStaticClass
or the existing ClassUtils::isInnerClass as a method reference for
class-based predicates that need to differentiate between static
nested types and inner classes.

See gh-28207
2022-03-22 16:18:14 +01:00
Stephane Nicoll 52d5452381 Validate class name input in SimpleTypeReference
Closes gh-28213
2022-03-22 13:30:55 +01:00
Sébastien Deleuze e7e843cae2 Fix formatting errors
See gh-28212
2022-03-22 10:56:37 +01:00
Sébastien Deleuze 1ffc96be8c Fix queriedMethods handling in ReflectionHintsSerializer
Closes gh-28212
2022-03-22 09:59:55 +01:00
Sam Brannen 5c540e5390 Apply "instanceof pattern matching" in core annotation support 2022-03-18 17:24:01 +01:00
Sam Brannen 2fb1dd177b Remove obsolete org.springframework.core.NestedIOException
This commit removes Spring's custom NestedIOException and replaces its
usage with the standard IOException which has supported a root cause
since Java 6.

Closes gh-28198
2022-03-18 16:56:56 +01:00
Sam Brannen b570f60560 Merge branch '5.3.x'
# Conflicts:
#	spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java
#	spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java
#	spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java
#	spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java
#	spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java
#	spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java
#	spring-context/src/main/java/org/springframework/jmx/export/annotation/ManagedNotification.java
#	spring-context/src/main/java/org/springframework/jmx/export/annotation/ManagedOperationParameter.java
#	spring-core/src/main/java/org/springframework/javapoet/support/package-info.java
#	spring-core/src/main/java/org/springframework/util/TypeUtils.java
#	spring-web/src/main/java/org/springframework/http/HttpMethod.java
2022-03-18 16:47:12 +01:00
Sam Brannen 64b64d9ba0 Stop referring to features as "Java 5" features
With a Java 8 baseline in place for quite some time now, it no longer
makes sense to refer to features such as annotations as "Java 5
annotations".

This commit also removes old `Tiger*Tests` classes, thereby avoiding
duplicate execution of various tests.
2022-03-18 16:32:30 +01:00
Sam Brannen fc8f31ccfb Deprecate "enclosing classes" search strategy for MergedAnnotations
This commit deprecates the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search
strategy for MergedAnnotations in 6.0 M3, allowing consumers of 6.0
milestones and release candidates to provide feedback before
potentially completely removing the search strategy or providing an
alternate mechanism for achieving the same goal prior to 6.0 GA.

Closes gh-28079
See gh-28080
2022-03-16 19:34:38 +01:00
Sam Brannen fd34533a3e Merge branch '5.3.x' 2022-03-16 19:24:37 +01:00
Sam Brannen 29d98285be Add warning to "enclosing classes" search strategy for MergedAnnotations
This commit adds a warning to the Javadoc for the
TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy in
MergedAnnotations with regard to the scope of the search
algorithm.

See gh-28079
2022-03-16 19:23:27 +01:00
Sam Brannen ad708780ed Polish Javadoc for MergedAnnotations 2022-03-16 19:23:27 +01:00
Sébastien Deleuze 77e0100f42 Implement GraalVM native JSON configuration generation
This commit implements 4 package private Json serializers
for JavaSerializationHints, ProxyHints, ReflectionHints
and ResourceHints to serialize GraalVM native JSON configuration
as documented in
https://www.graalvm.org/22.0/reference-manual/native-image/BuildConfiguration/.

It exposes the related functionality via
NativeConfigurationGenerator which allows to generate the
relevant files on the filesystem via the
FileNativeConfigurationGenerator implementation.

The generated *-config.json files have been validated working
with GraalVM 22.0.

Closes gh-27991
2022-03-16 16:15:58 +01:00
Sam Brannen bb9cf7cce1 Merge branch '5.3.x' 2022-03-16 15:29:22 +01:00
Sam Brannen c9cd53f469 Revert "Deprecate "enclosing classes" search strategy for MergedAnnotations"
This reverts commit 5689395678.

See gh-28079
2022-03-16 15:27:52 +01:00
Sam Brannen ae51ca9bca Revert "Remove deprecated "enclosing classes" search strategy for MergedAnnotations"
This reverts commit 819d4256b7.

See gh-28080
2022-03-16 15:18:34 +01:00
Sam Brannen 9764f0e59b Merge branch '5.3.x'
# Conflicts:
#	spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpRequestTests.java
#	spring-web/src/test/java/org/springframework/http/server/reactive/HeadersAdaptersTests.java
#	spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java
#	spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java
#	spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java
#	spring-webmvc/src/test/java/org/springframework/web/servlet/handler/MappedInterceptorTests.java
#	spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java
#	spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java
2022-03-16 15:07:53 +01:00
Sam Brannen c462fe30ed Use Named arguments in parameterized tests 2022-03-16 14:45:47 +01:00
Juergen Hoeller c3aed75b92 Merge branch '5.3.x'
# Conflicts:
#	build.gradle
2022-03-16 11:24:24 +01:00
Juergen Hoeller c1261f2860 Fix accidental exclusion of BeanMapEmitter class
Closes gh-28110
2022-03-16 11:20:49 +01:00
rstoyanchev e7b97f5be7 Merge branch '5.3.x' into main 2022-03-16 09:27:43 +00:00
rstoyanchev cb39b07088 Polishing Jackson encoder tests 2022-03-16 05:55:23 +00:00
Stephane Nicoll da45bd2dfd Polish contribution
See gh-28057
2022-03-15 20:19:46 +01:00
Phillip Webb 12244b2e51 Provide more control over factory failure handling
Add an additional `FactoryInstantiationFailureHandler` strategy
interface to `SpringFactoriesLoader` to allows instantiation
failures to be handled on a per-factory bases.

For example, to log trace messages for only factories that can't
be created the following can be used:

	FactoryInstantiationFailureHandler.logging(logger);

If no `FactoryInstantiationFailureHandler` instance is supplied
then `FactoryInstantiationFailureHandler.throwing()` is used
which provides back-compatible behavior by throwing an
`IllegalArgumentException`.

See gh-28057

Co-authored-by: Madhura Bhave <bhavem@vmware.com>
Co-authored-by: Andy Wilkinson <wilkinsona@vmware.com>
2022-03-15 20:19:46 +01:00
Phillip Webb 0b716c4f90 Allow flexible constructor arguments in factory implementations
Update `SpringFactoriesLoader` so that factory implementation classes
can have a constructor with arguments that are resolved dynamically.

Arguments are resolved using a `ArgumentResolver` interface that is
passed to the `loadFactories` method. This strategy interface is
intentionally simple and only allows resolution based on the argument
type. A number of convenience methods are provided to allow resolvers
to be built. For example:

	ArgumentResolver.of(String.class, "tests")
			.and(Integer.class, 123);

Factory implementation classes must have a non-ambiguous constructor
in order to be instantiated. The `SpringFactoriesLoader` uses the same
algorithm as `BeanUtils.getResolvableConstructor`.

See gh-28057

Co-authored-by: Madhura Bhave <bhavem@vmware.com>
Co-authored-by: Andy Wilkinson <wilkinsona@vmware.com>
2022-03-15 20:19:46 +01:00
Sam Brannen 1392b0f557 Merge branch '5.3.x' 2022-03-15 17:13:10 +01:00
Sam Brannen 9fbf5dc945 Use String#lastIndexOf(int) where possible 2022-03-15 17:03:20 +01:00
Sam Brannen 92d9aee3a2 Polish TestSocketUtils 2022-03-14 15:11:04 +01:00
Sam Brannen 389747f91c Make TestSocketUtils abstract 2022-03-13 15:58:53 +01:00
Sam Brannen 542b6427c3 Revise documentation for TestSocketUtils 2022-03-13 15:54:23 +01:00
Sam Brannen 2858c1efb5 Merge branch '5.3.x' 2022-03-12 14:04:29 +01:00
Lee, Kyutae 8a510db00d Polish Javadoc for Environment
Closes gh-28170
2022-03-12 14:02:26 +01:00
Stephane Nicoll e873715737 Fix detection of protected generic parameter
This commit fixes the algorithm used to analyze a generic parameter. If
a type in the generic signature is protected, the type is return rather
than the full signature. This makes sure that the appropriate package
is used. Previously, it would have incorrectly used the type of the
raw class.

Using a generic type for such a use case is wrong, and ProtectedElement
has been updated to expose a `Class` rather than a `ResolvableType`.

See gh-28030
2022-03-09 11:17:21 +01:00
Stephane Nicoll fd191d165b Add GeneratedType infrastructure
This commit adds an infrastructure for code that generate types with the
need to write to another package if privileged access is required. An
abstraction around types where methods can be easily added is also
available as part of this commit.

Closes gh-28149
2022-03-09 11:17:21 +01:00
Stephane Nicoll 14b147ce70 Add TypeReference implementation for generated code
This commit adds a TypeReference implementation that is suitable for
creating a reference to generated code.

Closes gh-28148
2022-03-09 11:17:21 +01:00
Sam Brannen e85001f332 Clean up warnings in test fixture 2022-02-19 17:32:15 +01:00
Sam Brannen 819d4256b7 Remove deprecated "enclosing classes" search strategy for MergedAnnotations
Closes gh-28080
2022-02-19 17:25:50 +01:00
Sam Brannen ad3095f197 Merge branch '5.3.x' 2022-02-19 17:02:02 +01:00
Sam Brannen 5689395678 Deprecate "enclosing classes" search strategy for MergedAnnotations
The TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy for
MergedAnnotations was originally introduced to support @Nested test
classes in JUnit Jupiter (see #23378).

However, while implementing #19930, we determined that the
TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy unfortunately
could not be used since it does not allow the user to control when to
recurse up the enclosing class hierarchy. For example, this search
strategy will automatically search on enclosing classes for static
nested classes as well as for inner classes, when the user probably
only wants one such category of "enclosing class" to be searched.
Consequently, TestContextAnnotationUtils was introduced in the Spring
TestContext Framework to address the shortcomings of the
TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy.

Since this search strategy is unlikely to be useful to general users,
the team has decided to deprecate this search strategy in Spring
Framework 5.3.x and remove it in 6.0.

Closes gh-28079
2022-02-19 16:51:00 +01:00
Sam Brannen 8c6d59aaaf Polish contribution
See gh-28014
2022-02-19 14:43:26 +01:00
a.yazychyan c5c926726d Use enhanced switch expressions where feasible
Closes gh-28014
2022-02-19 14:34:05 +01:00
Sam Brannen 2cee63491d Remove deprecated SocketUtils
Closes gh-28052
2022-02-15 16:19:11 +01:00
Stephane Nicoll 5fbd01f28f Polish 2022-02-15 15:25:45 +01:00
Sam Brannen 7412625929 Merge branch '5.3.x'
# Conflicts:
#	spring-web/src/test/java/org/springframework/remoting/caucho/CauchoRemotingTests.java
#	spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java
2022-02-15 14:35:25 +01:00
Sam Brannen 685a195ba1 Deprecate SocketUtils
SocketUtils was introduced in Spring Framework 4.0, primarily to assist
in writing integration tests which start an external server on an
available random port. However, these utilities make no guarantee about
the subsequent availability of a given port and are therefore
unreliable. Instead of using SocketUtils to find an available local
port for a server, it is recommended that users rely on a server's
ability to start on a random port that it selects or is assigned by the
operating system. To interact with that server, the user should query
the server for the port it is currently using.

SocketUtils is now deprecated in 5.3.16 and will be removed in 6.0.

Closes gh-28052
2022-02-15 14:28:58 +01:00
Sam Brannen 11de64d609 Merge branch '5.3.x' 2022-02-15 13:48:22 +01:00
Sam Brannen 3188c0f7db Ensure fix for gh-28012 is actually tested
In 3ec612aaf8, I accidentally removed tests that verified support for
non-synthesizable merged annotations for recursive annotations in
Kotlin.

This commit reinstates those non-synthesizable tests while retaining
the synthesizable tests.
2022-02-15 13:47:03 +01:00
Stephane Nicoll 5bbc7dbce2 Polish ProtectedAccess options
This commit improves how protected access analysis operates. Rather than
providing a static boolean, a function callback for the member to
analyse is used. This permits to change the decision whether reflection
can be used, or if the return type is assigned.

Both of those are already applicable, with InjectionGenerator relying
on reflection for private fields, and DefaultBeanInstanceGenerator
assigning the bean instance if additional contributors are present.

This commit also moves the logic of computing the options where the code
is actually generated.

See gh-28030
2022-02-15 13:16:39 +01:00
Stephane Nicoll c5e1a774a5 Add bean instance generator infrastructure
This commit provides the necessary infrastructure to let components
contribute statements that are used to fully instantiate a bean
instance.

To ease code generation, a dedicated infrastructure to register bean
definition is provided in the o.s.beans.factory.generator package.
BeanDefinitionRegistrar offers a builder style API that provides a way
to hide how injected elements are resolved at runtime and let
contributors provide code that may throw a checked exception.

BeanInstanceContributor is the interface that components can implement
to contribute to a bean instance setup. DefaultBeanInstanceGenerator
generates, for a particular bean definition, the necessary statements
to instantiate a bean.

Closes gh-28047
2022-02-14 17:01:32 +01:00
Sébastien Deleuze 5e64081ed1 Merge branch '5.3.x' 2022-02-14 10:51:46 +01:00
Sébastien Deleuze 8eb618b480 Make Kotlin functions accessible in CoroutinesUtils
In order to allow using private classes like in Java
for example.

Closes gh-23840
2022-02-14 10:43:31 +01:00
Sam Brannen e6ce328be4 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/annotation/AnnotationTypeMappingsTests.java
2022-02-13 00:00:11 +01:00
Sam Brannen 3ec612aaf8 Support recursive annotations in merged annotations
Although Java does not allow the definition of recursive annotations,
Kotlin does, and prior to this commit an attempt to synthesize a
merged annotation using the MergedAnnotation API resulted in a
StackOverflowError if there was a recursive cycle in the annotation
definitions.

This commit addresses this issue by tracking which annotations have
already been visited and short circuits the recursive algorithm if a
cycle is detected.

Closes gh-28012
2022-02-12 23:42:57 +01:00
Sam Brannen 7b0443333d Merge branch '5.3.x'
# Conflicts:
#	build.gradle
2022-02-11 20:44:42 +01:00
Sam Brannen 4eaee1e738 Short circuit if-conditions in AttributeMethods 2022-02-11 20:41:23 +01:00
Sam Brannen a4e192e33d Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java
2022-02-11 15:38:54 +01:00
Sam Brannen b60340b102 Simplify tests for synthesized annotation toString()
See gh-28015
2022-02-11 15:33:14 +01:00
Sam Brannen 5ae9217271 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java
#	src/eclipse/org.eclipse.jdt.ui.prefs
2022-02-11 15:01:47 +01:00
Brian Clozel 6c42bcfaec Upgrade to Kotlin 1.6.20-M1
This commit upgrades the Kotlin dependencies to 1.6.20-M1 and configures
the build to generate Java 17 bytecode for Kotlin classes.

Closes gh-27814
2022-02-11 11:39:32 +01:00
Sam Brannen 2fd39839f8 Improve toString() for synthesized annotations
Although the initial report in gh-28015 only covered inconsistencies
for arrays and strings in the toString() implementations for
annotations between the JDK (after Java 9) and Spring, it has since
come to our attention that there was further room for improvement.

This commit therefore addresses the following in toString() output for
synthesized annotations.

- characters are now wrapped in single quotes.

- bytes are now properly formatted as "(byte) 0x##".

- long, float, and double values are now appended with "L", "f", and
  "d", respectively. The use of lowercase for "f" and "d" is solely to
  align with the choice made by the JDK team.

However, this commit does not address the following issues which we may
choose to address at a later point in time.

- non-ASCII, non-visible, and non-printable characters within a
  character or String literal are not escaped.

- formatting for float and double values does not take into account
  whether a value is not a number (NaN) or infinite.

Closes gh-28015
2022-02-10 17:14:37 +01:00
Sam Brannen ce87285be5 Use canonical names for types in synthesized annotation toString
My proposal for the same change in the JDK is currently targeted for
JDK 19.

- https://bugs.openjdk.java.net/browse/JDK-8281462
- https://bugs.openjdk.java.net/browse/JDK-8281568
- https://github.com/openjdk/jdk/pull/7418

See gh-28015
2022-02-10 16:59:00 +01:00
Stephane Nicoll 1a4573641d Add code contribution infrastructure
This commit adds an API that lets individual components contribute code,
runtime hints, and protected access information. This ease the cases
where code need to be written in a privileged package if necessary and
let contributors provide hints for the code they generate.

Closes gh-28030
2022-02-10 15:54:43 +01:00
Stephane Nicoll b3ceb0f625 Add core JavaPoet utilities
This commit adds utilities that facilitate code generation patterns
used by the AOT engine.

Closes gh-28028
2022-02-10 14:58:04 +01:00
Stephane Nicoll dfae8effa8 Repackage Javapoet in org.springframework.javapoet
This commit repackages the Javapoet library into spring-core so that it
can be used by the AOT engine without requiring a specific version.

Closes gh-27828
2022-02-10 14:56:36 +01:00
Sam Brannen 1deb6b04b8 Apply "instanceof pattern matching" in SynthesizedMergedAnnotationInvocationHandler 2022-02-08 14:30:26 +01:00
Sam Brannen 839cc5f7f8 Remove unnecessary JDK 9+ check in MergedAnnotationsTests 2022-02-08 14:19:32 +01:00
Sam Brannen bf40033e86 Merge branch '5.3.x' 2022-02-08 14:15:25 +01:00
Sam Brannen 7139a877f4 Ensure toString() for synthesized annotations is source code compatible
Since the introduction of synthesized annotation support in Spring
Framework 4.2 (a.k.a., merged annotations), the toString()
implementation attempted to align with the formatting used by the JDK
itself. However, Class annotation attributes were formatted using
Class#getName in Spring; whereas, the JDK used Class#toString up until
JDK 9.

In addition, JDK 9 introduced new formatting for toString() for
annotations, apparently intended to align with the syntax used in the
source code declaration of the annotation. However, JDK 9+ formats enum
annotation attributes using Enum#toString instead of Enum#name, which
can lead to issues if toString() is overridden in an enum.

This commit updates the formatting used for synthesized annotations by
ensuring that toString() generates a string that is compatible with the
syntax of the originating source code, going beyond the changes made in
JDK 9 by using Enum#name instead of Enum#toString.

Closes gh-28015
2022-02-08 14:10:36 +01:00
Stephane Nicoll a0c97e4c36 Polish
See gh-27829
2022-02-07 12:51:53 +01:00
Stephane Nicoll 6936f7e0cb Relocate runtime hints to aot package
See gh-27829
2022-02-07 12:51:43 +01:00
Juergen Hoeller b0bca7f5ae Merge branch '5.3.x'
# Conflicts:
#	build.gradle
2022-02-04 23:55:18 +01:00
Juergen Hoeller a22feac803 Update license header for https (nohttp rule)
See gh-27802
2022-02-04 23:51:05 +01:00
Juergen Hoeller 3eb9886724 Merge branch '5.3.x'
# Conflicts:
#	spring-context-support/src/main/java/org/springframework/scheduling/commonj/WorkManagerTaskExecutor.java
#	spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java
#	spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java
#	spring-tx/src/main/java/org/springframework/jca/work/SimpleTaskWorkManager.java
#	spring-tx/src/main/java/org/springframework/jca/work/WorkManagerTaskExecutor.java
2022-02-04 23:24:21 +01:00
Juergen Hoeller bc9cd9a687 Find interface method even for late-bound interface declaration in subclass
Closes gh-27995
2022-02-04 23:21:27 +01:00
Juergen Hoeller a71a45e719 Deprecate AsyncTaskExecutor.execute(Runnable task, long startTimeout)
Closes gh-27959
2022-02-04 23:21:00 +01:00
Juergen Hoeller 132d8c7f45 Support for CGLIB BeanMap utility on JDK 17
Closes gh-27802
2022-02-04 23:19:06 +01:00
Sam Brannen b3f786728e Use modern language features in tests 2022-02-03 15:35:32 +01:00
Sam Brannen 54565e95b5 Merge branch '5.3.x' 2022-02-03 14:58:36 +01:00
Sam Brannen f8a5a8d7be Use modern language features in tests 2022-02-03 14:50:10 +01:00
Stephane Nicoll 48ce714d15 Provide an API to record various runtime hints
This commit provides an API to record the need for reflection,
resources, serialization, and proxies so that the runtime can be
optimized accordingly.

`RuntimeHints` provides an entry point to register the following:

* Reflection hints: individual elements of a type can be defined, as
well as a predefined categories (identified by the `MemberCategory`
enum). A method or constructor hint can refine whether the executable
should only be introspected or also invoked.
* Resource hints: patterns using includes/excludes identify the
resources to include at runtime. Resource bundles are also supported.
* Java Serialization hints: types that use java serialization can be
registered.
* Proxy hints: both interfaces-based (JDK) proxy and class-based proxy
can be defined.

This commit also introduces a `TypeReference` abstraction that permits
to record hints for types that are not available on the classpath, or
not compiled yet (generated code).

Closes gh-27829
2022-01-25 15:45:40 +01:00
Sam Brannen 72fc706c22 Merge branch '5.3.x' 2022-01-25 10:03:51 +01:00
Sam Brannen 652c13a6ea Enable ReflectionUtilsTests.findMethodWithVarArgs()
See gh-13286
2022-01-25 09:58:57 +01:00
Sam Brannen cb3fa89946 Polish ReflectionUtilsTests 2022-01-25 09:57:36 +01:00
Sam Brannen 08daacfc1b Merge branch '5.3.x' 2022-01-24 20:33:51 +01:00
Sam Brannen d01dca14e9 Filter methods in Object in ReflectionUtils.USER_DECLARED_METHODS
Prior to this commit, the USER_DECLARED_METHODS MethodFilter in
ReflectionUtils did not actually filter methods declared in
java.lang.Object as stated in its Javadoc.

Consequently, if ReflectionUtils.doWithMethods was invoked with
USER_DECLARED_METHODS and Object.class as the class to introspect, all
non-bridge non-synthetic methods declared in java.lang.Object were
passed to the supplied MethodCallback, which breaks the contract of
USER_DECLARED_METHODS.

In addition, if USER_DECLARED_METHODS was composed with a custom
MethodFilter using `USER_DECLARED_METHODS.and(<custom MethodFilter>)`,
that composed method filter allowed all non-bridge non-synthetic
methods declared in java.lang.Object to be passed to the supplied
MethodCallback, which also breaks the contract of
USER_DECLARED_METHODS. This behavior resulted in regressions in code
that had previously used USER_DECLARED_METHODS by itself and then began
using USER_DECLARED_METHODS in a composed filter. For example, since
commit c419ea7ba7 ReflectiveAspectJAdvisorFactory has incorrectly
processed methods in java.lang.Object as candidates for advice methods.

This commit fixes this bug and associated regressions by ensuring that
USER_DECLARED_METHODS actually filters methods declared in
java.lang.Object. In addition, ReflectionUtils.doWithMethods now aborts
its search algorithm early if invoked with the USER_DECLARED_METHODS
filter and Object.class as the class to introspect.

Closes gh-27970
2022-01-24 20:09:22 +01:00
Sam Brannen d698446f7c Polish ReflectionUtils[Tests] 2022-01-24 19:46:40 +01:00
Juergen Hoeller 66732afc10 Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-jms/src/main/java/org/springframework/jms/listener/AbstractPollingMessageListenerContainer.java
2022-01-19 13:56:37 +01:00
Juergen Hoeller 86be03945b Polishing 2022-01-19 13:54:03 +01:00
Sam Brannen 198576dbc5 Merge branch '5.3.x' 2022-01-13 16:21:16 +01:00
Sam Brannen 4b1b25496b Improve comment parsing in DTD/XSD detection algorithm
Prior to this commit, XmlValidationModeDetector did not properly parse
all categories of comments (described below). When such categories of
comments were encountered XmlValidationModeDetector may have
incorrectly detected that an XML file used a DTD when it used an XSD,
or vice versa.

This commit revises the parsing algorithm in XmlValidationModeDetector
so that multi-line comments and multiple comments on a single line are
properly recognized.

Specifically, with this commit the following categories of comments are
now handled properly.

- Multiple comments on a single line
- Multi-line comment: beginning on one line and then ending on another
  line with an additional comment following on that same line.
- Multi-line comment: beginning at the end of XML content on one line
  and then spanning multiple lines.

Closes gh-27915
2022-01-13 16:11:15 +01:00
Sam Brannen 9e8b6feb54 Polishing 2022-01-13 14:56:14 +01:00
Sam Brannen 5aefcd2fdb Re-enable BlockHound integration tests
Prior to this commit, our BlockHound integration tests were disabled
after the migration to a JDK 17 baseline since the build now always
runs on JDK 14 or higher.

To re-enable the tests we now supply the deprecated
-XX:+AllowRedefinitionToAddDeleteMethods command-line argument to the JVM
for tests in the Gradle build. Users can also configure this manually
within an IDE to run SpringCoreBlockHoundIntegrationTests.

If that command-line argument is removed from the JVM at some point in
the future, we will need to investigate an alternative solution.

See https://github.com/reactor/BlockHound/issues/33 for details.
2022-01-11 14:54:59 +01:00
Sam Brannen f2fe8a87fa Polish contribution
See gh-27862
2022-01-11 14:11:07 +01:00
v_vyqyxiong 6ecb488327 Remove unnecessary check in isBridgedCandidateFor()
In BridgeMethodResolver#isBridgedCandidateFor, candidateMethod is never
not bridged, so it's unnecessary to judge whether candidateMethod and
bridgeMethod are the same.

Closes gh-27862
2022-01-11 14:03:57 +01:00
Sam Brannen d57bc176f2 Merge branch '5.3.x' 2022-01-10 14:21:25 +01:00
Sam Brannen df263d01b9 Use idiomatic AssertJ assertions for true, false, and null 2022-01-10 14:15:55 +01:00
Sam Brannen 4ebc53a424 Merge branch '5.3.x' 2022-01-10 13:28:31 +01:00
kuanghc1 2a80b64d40 Add tests for StringUtils matchesCharacter() method
Closes gh-27909
2022-01-10 13:27:15 +01:00
Sam Brannen 519fa60c25 Merge branch '5.3.x' 2022-01-09 17:12:49 +01:00
Sam Brannen 8087eb69bf Improve error message in ResolvableType.forClassWithGenerics()
Prior to this commit, the error message generated for a mismatched
number of generics did not include the information about the class in
question.

This commit improves the error message by providing more context,
specifically the result of invoking toGenericString() on the class.

For example, instead of throwing an IllegalArgumentException with the
error message "Mismatched number of generics specified", the error
message would now be "Mismatched number of generics specified for
public abstract interface java.util.Map<K,V>".

Closes gh-27847
2022-01-09 17:05:07 +01:00
Sam Brannen e41d865193 Polishing 2022-01-09 17:05:07 +01:00