Commit Graph

3242 Commits

Author SHA1 Message Date
Sam Brannen 354117da7f Merge branch '5.3.x' 2022-09-14 14:38:10 +02:00
Sam Brannen 529481c44c Polish contribution
See gh-29150
2022-09-14 14:35:43 +02:00
Jens Dietrich 35d379f9d3 Add missing @Nullable in SettableListenableFuture
Closes gh-29150
2022-09-14 14:32:37 +02:00
Juergen Hoeller 50d34366bc Polishing 2022-09-14 12:55:53 +02:00
Arjen Poutsma 71f9a84d22 Fix releasing bug in StringDecoder
This commit fixes an issue in StringDecoder, where, if the buffer did
not contain any delimiters, it was released before it was relayed to
any subscribers.

Closes gh-29119
2022-09-13 15:46:24 +02:00
Brian Clozel 5f62d1dc8e Add className variants in ReflectionHintsPredicates
This commit adds predicates variants that accept `String className`
instead of actual `Class<?>` when checking for fields and method hints.
This is useful when the type under test is not visible from the current
test class.

Closes gh-29143
2022-09-13 14:00:55 +02:00
Sam Brannen 349bcb4364 Suppress warnings 2022-09-12 17:46:03 +02:00
Sam Brannen e653ee60a0 Polish ClassPathResourceTests 2022-09-12 17:40:43 +02:00
Sam Brannen 138f9c64be Consistently return absolute path from ClassPathResource#getPath
Prior to this commit, the Javadoc for the getPath() method in
ClassPathResource stated the following.

> Return the path for this resource (as resource path within the class path).

That implied the returned path was an "absolute path" within the class
path; however, that was not always true.

If the resource was created using ClassPathResource(String) or
ClassPathResource(String, ClassLoader), the returned path was a cleaned
version of the ABSOLUTE PATH supplied to the constructor, WITHOUT a
leading slash.

If the resource was created using ClassPathResource(String, Class) with
an absolute path, the returned path was a cleaned version of the
ABSOLUTE PATH supplied to the constructor, WITH a leading slash.

If the resource was created using ClassPathResource(String, Class) with
a relative path, the returned path was a cleaned version of the
RELATIVE PATH supplied to the constructor.

In addition, ClassPathResource does not provide public access the Class
passed to the ClassPathResource(String, Class) constructor.

Consequently, the path returned by getPath() could not be reliably used
with ClassLoader.getResource(String) or with the recently introduced
registerResource(Resource) method in ResourceHints.

This commit addresses this issue by ensuring that getPath()
consistently returns the absolute path within the class path without a
leading slash.

See gh-29083
Reverts gh-29094
Closes gh-29099
2022-09-12 17:40:43 +02:00
Stephane Nicoll 58a2b79699 Harmonize hint registration
Previously, a shortcut method for the default ExecutableMode was
provided, but we found out that the shortcut makes it harder to
determine the intent.

This commit harmonizes hints registration for types, methods, and
fields. An ExecutableMode is now mandatory to register a method or
constructor. Previous methods that infer a mode or provided a
customizer of the builder are deprecated.

Closes gh-29135
2022-09-12 14:51:04 +02:00
Stephane Nicoll 042a4f3518 Polish "Adapt FieldHint to recent GraalVM versions"
See gh-29130
2022-09-12 14:50:28 +02:00
SreenathTM 1cb5f00723 Adapt FieldHint to recent GraalVM versions
In recent GraalVM versions, allowWrite and allowUnsafeAccess have been
deprecated and are no longer use. This commit updates FieldHint to
remove the irrelevant properties.

See gh-29130
2022-09-12 14:50:28 +02:00
유예본(Yebon You)/Platform Engineering팀/11ST fa1f7f6dc7 Use InputStream's contracts instead of StreamUtils
Since Spring Framework 6.0 requires Java 17, we can now use
`InputStream` new contracts when manipulating streams.

Closes gh-27702
2022-09-12 10:21:50 +02:00
Brian Clozel 0770d86936 Deprecate StreamUtils.emptyInput()
Closes gh-29125
2022-09-12 10:21:50 +02:00
Patrick Strawderman d4a74c8f9d Update StreamUtils drain and emptyInput to use JDK builtins
Update StreamUtils.drain to use InputStream.transferTo with a null
OutputStream. This avoids allocating buffers for cases where the
supplied InputStream has an optimized transferTo method (e.g.,
ByteArrayInputStream and FileInputStream).

Additionally, update StreamUtils.emptyInput to simply call
InputStream.nullInputStream.

Closes gh-28961
2022-09-12 10:21:50 +02:00
Stephane Nicoll 7642ac82f6 Apply @PropertySource in AOT-generated context
This commit records `@PropertySource` declarations defined on
configuration classes so that these are contributed to the environment
of a context that is initialized by generated code.

Closes gh-28976
2022-09-12 10:09:37 +02:00
Stephane Nicoll ae706f3954 Allow MethodReference to define a more flexible signature
This commit moves MethodReference to an interface with a default
implementation that relies on a MethodSpec. Such an arrangement avoid
the need of specifying attributes of the method such as whether it is
static or not.

The resolution of the invocation block now takes an
ArgumentCodeGenerator rather than the raw arguments. Doing so gives
the opportunity to create more flexible signatures.

See gh-29005
2022-09-12 10:07:31 +02:00
Stephane Nicoll 8a4a89b9d9 Allow a MethodReference to be produced from a GeneratedMethod
This commit updates GeneratedMethod and its underlying infrastructure
to be able to produce a MethodReference. This simplifies the need when
such a reference needs to be created manually and reuses more of what
MethodReference has to offer.

See gh-29005
2022-09-12 10:07:13 +02:00
Sam Brannen 649c2f56fd Accept only ClassPathResource in ResourceHints#registerResource()
This commit throws an exception in registerResource() if the supplied
resource is not a ClassPathResource.

See gh-29083
2022-09-11 23:33:39 +02:00
Sam Brannen 6d83a959fb Rename registerResourceIfNecessary to registerResource
This commit renames registerResourceIfNecessary() to registerResource()
and throws an exception if the class path resource does not exist.

Closes gh-29083
2022-09-10 19:49:56 +02:00
Patrick Strawderman cdb38e8482 Increase StreamUtils.BUFFER_SIZE to 8192
This aligns the buffer size used in StreamUtils with the buffer sizes
used throughout the JDK (see InputStream, BufferedInputStream, Files).

Closes gh-28965
2022-09-09 22:04:10 +02:00
Brian Clozel 2b5ca63339 Fix serialization compiler warnings with Java 18
As of Java 18, the serial lint warning in javac has been expanded to
check for class fields that are not marked as `Serializable`.
See https://www.oracle.com/java/technologies/javase/18all-relnotes.html#JDK-8202056

In the Spring Framework codebase, this can happen with `Map`, `Set` or
`List` attributes which are often assigned with an unmodifiable
implementation variant. Such implementations are `Serializable` but
cannot be used as field types.

This commit ensures that the following changes are applied:
* fields are marked as transient if they can't be serialized
* classes are marked as `Serializable` if this was missing
* `@SuppressWarnings("serial")` is applied where relevant
2022-09-09 20:24:26 +02:00
Brian Clozel 21612eba19 Disable BlockHound tests on Java 18+
BlockHound is not currently compatible with Java 18.
2022-09-09 20:22:16 +02:00
Phillip Webb 665deb4d82 Add examples to Javadoc for Throwing*.of factory methods
Closes gh-28969
2022-09-09 09:33:50 -07:00
Sam Brannen d46a816745 Remove deprecated SynthesizedAnnotation interface
The SynthesizedAnnotation interface is no longer used in the core
Spring Framework and should not be used by external parties either.

Closes gh-29092
2022-09-08 12:12:51 +02:00
Sam Brannen 8a0e1969b0 Revert "Introduce isSynthesizable in MergedAnnotation"
This reverts commit 32346b8382.

Closes gh-29093
2022-09-08 12:12:51 +02:00
Sam Brannen 75dfd47826 Delete unused code in ReflectionHintsPredicatesTests 2022-09-08 12:12:51 +02:00
Sébastien Deleuze e1c94d7e6b Remove obsolete RuntimeHintsUtils
Closes gh-29058
2022-09-08 09:25:09 +02:00
Sam Brannen ae861a2b3e Document leading slash semantics for ClassPathResource.getPath()
See gh-29094
2022-09-07 15:28:35 +02:00
Sébastien Deleuze 9cfe79186d Stop using RuntimeHintsUtils
Due to gh-29053, we can stop using RuntimeHintsUtils to
register SynthesizedAnnotation proxies.

Closes gh-29059
2022-09-07 10:10:07 +02:00
Brian Clozel 323d1907c1 Do not require full type reflection when listing methods/fields
Prior to this commit, the `RuntimeHintsAgent` and its testing
infrastructure would assume that calling `MyClass.class.getMethods()`
requires a reflection hint on the class for introspecting public/private
methods.

GraalVM does not require this, in fact this call only returns methods
that have reflection hints in the native image.

This commit refines the agent behavior for `Class.getMethods()`,
`Class.getDeclaredMethods()`, `Class.getFields()` and
`Class.getDeclaredFields()`. With this change, registering at least one
method/field for reflection is enough to match.

During the execution of Java tests, all methods and fields will be
provided, regardless of hints being registered or not. This could cause
false negatives where we're missing reflection hints on methods or
fields.
This risk is mitigated thanks to additional instrumentation on
`Method.getAnnotations()`, `Method.getParameterTypes()` and
`Method.invoke()`. If a method is found reflectively, chances are it
will be used for further reflection.

Closes gh-29091
2022-09-06 22:14:10 +02:00
Sam Brannen 6cce47176a Further clarify the semantics of ClassPathResource.getPath()
See gh-29094
2022-09-06 20:34:12 +02:00
Sam Brannen 018122f684 Update Javadoc for ResourceHints.registerResourceIfNecessary()
See gh-29094
2022-09-06 20:18:24 +02:00
Sam Brannen d57e061d3f Introduce getAbsolutePath() in ClassPathResource
Since getPath() returns a relative path if the resource was created
using the ClassPathResource(String,Class) constructor, there was
previously no way to consistently obtain the absolute path to the
resource within the class path.

This commit addresses this shortcoming by introducing a new
getAbsolutePath() for consistently obtaining the absolute path to the
resource within the class path.

See gh-29083
Closes gh-29094
2022-09-06 20:09:24 +02:00
Sam Brannen 1052f48eb6 Clarify semantics of ClassPathResource.getPath()
This commit also improves the overall Javadoc in ClassPathResource.

See gh-29094
2022-09-06 20:08:21 +02:00
Sébastien Deleuze b8c1fc9202 Revert "Remove RuntimeHintsUtils"
This reverts commit 3e327f5641.
2022-09-06 18:21:34 +02:00
Sébastien Deleuze 3e327f5641 Remove RuntimeHintsUtils
Due to gh-29053, we can stop using RuntimeHintsUtils to
register SynthesizedAnnotation proxies.

Closes gh-29058
Closes gh-29059
2022-09-06 15:31:02 +02:00
Sam Brannen 8fbd2141b7 Move registerResourceIfNecessary() to ResourceHints
See gh-29083
2022-09-06 15:22:18 +02:00
Sam Brannen 5c2859ffa7 Make fields in ClassPathResource final 2022-09-06 14:47:19 +02:00
Sam Brannen 28c492cbdd Introduce RuntimeHintsUtils.registerResourceIfNecessary
This commit introduces a new registerResourceIfNecessary() method in
RuntimeHintsUtils that simplifies the registration of hints for
`classpath:` resources.

Closes gh-29083
2022-09-06 14:36:28 +02:00
Sam Brannen 10ade235e3 Prevent resource hint registration for pattern with leading slash
Prior to this commit, if a ResourcePatternHint was created with a
resource pattern with a leading slash, the hint was registered and
eventually converted to configuration for the GraalVM native image
compiler.

However, such a resource pattern is invalid for GraalVM. Consequently,
the registered resources were not available within the compiled native
image.

This commit ensures that registered patterns are applicable in a native
image by preventing creation of a ResourcePatternHint with a pattern
with a leading slash.

Closes gh-29088
2022-09-06 12:53:31 +02:00
Sam Brannen 04bb336b0b Polish ResourcePatternHints Javadoc 2022-09-06 12:53:31 +02:00
Sam Brannen 97b98c3378 Support default package for TypeReference in ResourceHintsPredicates
Prior to this commit, if the TypeReference supplied to
ResourceHintsPredicates.forResource(TypeReference,String) was for a
class declared in the default package (i.e., without a package), the
resolveAbsoluteResourceName() method incorrectly prepended two leading
slashes (//) to the absolute resource name, causing correct matches to
fail.

This commit fixes this by adding special handling for a TypeReference
without a package name. In addition, this commit introduces lenient
handling of resource names by consistently removing a leading slash in
ResourceHintsPredicates.forResource(*) methods. The latter aligns with
absolute resource path handling in other places in the framework, such
as ClassPathResource.

Closes gh-29086
2022-09-06 12:53:31 +02:00
Janne Valkealahti 135f9070c5 Add jni-config generation
This commit adds support generating graalvm `jni-config.json` file.

Configuration format for jni/reflection in graalvm is documented
to be exactly same so we can re-use facilities for reflection hints
which should be relatively clean for a user as also graalvm uses same
classes for both jni/reflection.

Closes gh-29007
2022-09-06 12:22:13 +02:00
Stephane Nicoll 58b0251af1 Relocate TestGenerationContext to spring-core-test
This commit moves the test implementation for GenerationContext in
spring-core-test. This also removes the copy we had in testfixtures

See gh-28877
2022-09-05 16:21:17 +02:00
Sébastien Deleuze f50c301387 Change BindingReflectionHintsRegistrar package
Move it to org.springframework.aot.hint.

See gh-28979
2022-09-02 19:31:26 +02:00
Brian Clozel 7ace1f9dc5 Align RuntimeHintsPredicates with new FieldMode
Closes gh-29063
2022-09-02 18:16:43 +02:00
Sébastien Deleuze 044f3728a3 Introduce @RegisterReflectionForBinding
This annotation and the related processor allows to
register reflection hints for data binding purpose
(class, fields, properties, record components for
the whole type hierarchy)

Closes gh-28979
2022-09-02 17:31:43 +02:00
Sébastien Deleuze aaffb8b27e Move BindingReflectionHintsRegistrar to spring-core
See gh-28979
2022-09-02 17:31:43 +02:00
Sébastien Deleuze cc555d2ff4 Avoid shipping AWT classes in native images
This commit provides an alternative
java.beans.Introspector#findCustomizerClass implementation
via a GraalVM substitution that avoids to include thousands
of unused AWT classes in the native image.

Closes gh-29060
2022-09-02 15:06:50 +02:00
Sam Brannen 69f23095b8 Deprecate SynthesizedAnnotation and related methods
Since Spring no longer adds the SynthesizedAnnotation interface to the
JDK dynamic proxy used to synthesize an annotation, this commit
officially deprecates SynthesizedAnnotation and related methods in
RuntimeHintsUtils.

See gh-29041, gh-29054
Closes gh-29053
2022-09-02 12:04:17 +02:00
Sam Brannen 0ec03a8dd6 Stop implementing SynthesizedAnnotation in annotation proxies
SynthesizedAnnotation was originally introduced as a convenience for
easily detecting if an annotation had been synthesized by Spring via a
simple `if (myAnnotation instanceof SynthesizedAnnotation)` check.

However, the introduction of SynthesizedAnnotation in the JDK dynamic
proxy for a synthesized annotation results in a separate proxy class
for each annotation synthesized by Spring, and this causes issues with
GraalVM native images since users and framework developers must always
ensure that the additional proxy classes are registered.

This commit completely removes the use of SynthesizedAnnotation in
synthesized annotation proxies. This change allows the proxy class for
an annotation to be reused for a synthesized annotation of the same
annotation type.

Consequently:

- Extra proxy classes are not generated on the JVM or in a native image.
- Extra proxy classes are not required to be registered for a native image.

Closes gh-29041
2022-09-02 11:27:00 +02:00
Brian Clozel fc47d25bc7 Polish
See gh-26320
2022-09-02 10:55:40 +02:00
Sam Brannen 73abd58202 Polishing 2022-09-02 10:23:53 +02:00
Phillip Webb 505da5c602 Migrate hint registration to shortcuts
Migrate code to make use of the `MemberCategory` and `FieldMode`
shortcuts.

See gh-29011
2022-09-01 17:26:06 -07:00
Phillip Webb bc0bf1fac3 Add additional shortcuts for hint registration
Add `MemberCategory` and `FieldMode` shortcuts for type registration.
Helper `builtWith` methods have also been extracted to the Hint types
to allow general reuse (for example with `registerTypes`).

See gh-29011
2022-09-01 17:25:46 -07:00
Phillip Webb da1005cd66 Add FieldMode for field hints and ensure that it cannot be downgraded
Add a `FieldMode` enum analogous to `ExecutableHint` and update
`FieldHint` to ensure that registration cannot downgrade `WRITE`
to `READ`.

Fixes gh-29055
2022-09-01 17:25:43 -07:00
Phillip Webb 0bd923b0a7 Polishing 2022-09-01 16:28:02 -07:00
Phillip Webb cea06e6a9e Polish ReflectionHints and TypeHint method order 2022-09-01 16:27:54 -07:00
Phillip Webb cfd37d948d Reduce visibility of hint factory methods
Reduce the visibility of hint factory methods that return a `Builder`.
Since the `build()` method of the `Builder` is package-private the
factory methods can also be package-private.
2022-09-01 13:37:08 -07:00
Sam Brannen a5584dcaa6 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java
2022-09-01 17:44:24 +02:00
Sam Brannen 6a68bd58f9 Introduce AnnotationUtils.isSynthesizedAnnotation(Annotation)
Since SynthesizedAnnotation will be deprecated (and potentially
completely removed) in Spring Framework 6.0, this commit introduces
AnnotationUtils.isSynthesizedAnnotation(Annotation) in 5.3.x to allow
people to migrate away from relying on SynthesizedAnnotation.

Closes gh-29054
2022-09-01 17:35:22 +02:00
Sam Brannen b1414bf15b Polishing 2022-09-01 17:23:04 +02:00
Brian Clozel c470262c8e Rewrite ConcurrentLruCache implementation
Prior to this commit, the `ConcurrentLruCache` implementation would not
perform well under certain conditions. As long as the cache capacity was
not reached, the cache would avoid maintaining an eviction queue
(reordering entries depending with least/most recently read). When the
cache capacity was reached, the LRU queue was updated for each
read/write operation. This decreased performance significantly under
contention when the capacity was reached.

This commit completely rewrites the internals of `ConcurrentLruCache`.
`ConcurrentLruCache` is now a specialized version of the
`ConcurrentLinkedHashMap` [1]. This change focuses on buferring read and
write operations, only processing them at certain times to avoid
contention.

When a cached entry is read, a read operation is queued and buffered
operations are drained if the buffer reached a fixed limit. When a new
cache entry is added or removed, a write operation is queued and
triggers a drain attempt. When the capacity is outgrown, the cache polls
items from the eviction queue, which maintains elements with the
least recently used ones first. Entries are removed until the capacity
is under control.

The behavior described here and the buffer sizes are optimized with the
number of available processors in mind. Work is localized as much as
possible on a per-thread basis to avoid contention on the eviction queue.

The new implementation has been tested with the JMH benchmark provided
here, comparing the former `COncurrentLruCache`, the new implementation
as well as the `ConcurrentLinkedHashMap` [1].

When testing with a cache reaching capacity, under contention, with a
10% cache miss, we're seeing a 40x improvement compared to the previous
implementation and performance on par with the reference.
See [2] for how to replicate the benchmark.

[1] https://github.com/ben-manes/concurrentlinkedhashmap
[2] https://github.com/spring-projects/spring-framework/wiki/Micro-Benchmarks

Closes gh-26320
2022-08-31 19:10:50 +02:00
Johnny Lim 706c1ec8dd Polish 2022-08-31 23:59:51 +09:00
Brian Clozel f877f81ae4 Move Netty 5 dependency to Framework platform 2022-08-30 21:58:41 +02:00
Sam Brannen b50415062b Clean up warnings and polish tests
This commit also modifies ResourceWebHandlerTests.getResourceFromFileSystem()
so that it passes in the IDE.
2022-08-26 15:20:16 +02:00
Sébastien Deleuze d16fa82888 Remove remaining native build-time class initializations
See oracle/graal#4673 related issue.

Closes gh-29018
2022-08-26 09:29:17 +02:00
Sébastien Deleuze 3e9b57106e Refine TypeHint.Builder#onReachableType Javadoc 2022-08-26 08:35:18 +02:00
Sébastien Deleuze 08f636b691 Introduce TypeHint.Builder#onReachableType(Class<?>)
Closes gh-29017
2022-08-26 08:34:54 +02:00
Arjen Poutsma 626739d93f Polishing 2022-08-25 11:31:47 +02:00
Arjen Poutsma 9c33d2707a Introduce support for Netty 5 Buffer
This commit introduces support for Netty 5's Buffer, in the form of
Netty5DataBuffer. Because of the new API offered by Buffer, several
changes have been made to the DataBuffer API:

- CloseableDataBuffer is a simpler alternative to PooledDataBuffer, and
  implemented by Netty5DataBuffer. DataBufferUtils::release can now
  handle CloseableDataBuffer as well as PooledDataBuffer.
- PooledDataBuffer::touch has been moved into a separate interface:
  TouchableDataBuffer, which is implemented by Netty5DataBuffer.
- The capacity of DataBuffers can no longer be reduced, they can only
  grow larger. As a consequence, DataBuffer::capacity(int) has been
  deprecated, but ensureWritable (formally ensureCapacity) still exists.
- DataBuffer::slice and retainedSlice have been deprecated in favor of
  split, a new method that ensures that memory regions do not overlap.
- DataBuffer::asByteBuffer has been deprecated in favor of toByteBuffer,
  a new method that returns a copy, instead of shared data.
- DataBufferFactory::allocateBuffer has been deprecated in favor of
  allocateBuffer(int).

Closes gh-28874
2022-08-25 11:00:22 +02:00
Stephane Nicoll 7ca57b7e80 Use consistent registration API in TypeHint.Builder
This commit adapts the registration of fields, constructors, and methods
to provide the same convenience than the reflection-based one available
in ReflectionHints.

See gh-29011
2022-08-24 19:32:02 +02:00
Stephane Nicoll 5aa8583159 Add shortcut to register an executable with a mode
See gh-29011
2022-08-24 19:32:02 +02:00
Stephane Nicoll c164b918c0 Apply consistent RuntimeHints defaults
This commit harmonizes the registration of an executable so that
the default method and the method that takes an empty customizer
produces the same hint. The same applies to the readable flag of
a field hint.

Rather than returning a list of executable modes, the "highest" mode
is retained.

See gh-29011
2022-08-24 19:32:01 +02:00
Sam Brannen e5f9bb76b1 Declare covariant return type in DefaultGenerationContext.withName()
Prior to this commit, if infrastructure code working directly with an
instance of DefaultGenerationContext invoked withName() on that
instance, the new GenerationContext had to be cast from
GenerationContext to DefaultGenerationContext in order for the
infrastructure to continue working with the DefaultGenerationContext
API -- for example, the writeGeneratedContent() method which is not
defined in the GenerationContext API.

This commit makes use of a covariant return type by declaring that
DefaultGenerationContext.withName() returns a DefaultGenerationContext.
2022-08-22 16:41:20 +02:00
Sam Brannen 9ab046bdbb Introduce complete DefaultGenerationContext constructor
Prior to this commit, it was possible to create a DefaultGenerationContext
based on a ClassNameGenerator and GeneratedFiles; however, there was no way
to create a DefaultGenerationContext that reused an existing RuntimeHints
instance which is necessary in certain use cases -- for example, in the
TestContext framework where multiple GenerationContexts are created
based on shared instances of GeneratedFiles and RuntimeHints.

This commit addresses this by introducing a public
DefaultGenerationContext(ClassNameGenerator,GeneratedFiles,RuntimeHints)
constructor.
2022-08-22 16:41:11 +02:00
Stephane Nicoll 40de029bf8 Polish 2022-08-22 16:32:53 +02:00
Stephane Nicoll eac616a83e Restore support for package private ReflectiveProcessor
See gh-28975
2022-08-18 14:27:59 +02:00
Stephane Nicoll d6afa8df2d Improve registration of the same hint for multiple classes
Based on the feedback in #28977 an easy way to create a list of
type references based on a vararg of classes is helpful when
registering the same hints for several types.
2022-08-18 06:52:34 +02:00
Stephane Nicoll 4556895e6e Expose registrar for @Reflective
This commit exposes the logic of processing `@Reflective` on beans so
that it can be reused in custom arrangements.

Closes gh-28975
2022-08-17 14:33:09 +02:00
Stephane Nicoll 9846d28ae6 Remove support for declaring class proxies hints
Closes gh-28972
2022-08-17 09:25:03 +02:00
Stephane Nicoll f4389c3114 Restore ANNOTATION_HINT in a deprecated form for the time being 2022-08-16 16:18:04 +02:00
Stephane Nicoll 4f0c879778 Rationalize hints required for annotations
This commit updates RuntimeHintsUtils to focus on registering a JDK
proxy only as annotations of annotated elements that have at least
an introspection hints are visible out-of-the-box.

This commit also removes unnecessary hints and adapt `@Reflective` to
detect if a hint is required using the introduced
MergedAnnotation#isSynthesizable.

See gh-28967
2022-08-16 15:42:52 +02:00
Stephane Nicoll 32346b8382 Introduce isSynthesizable in MergedAnnotation
This commit adds the ability to check if a the annotation managed by
a MergedAnnotation is synthesizable. This makes it easier to register
a JDK proxy hint if necessary

See gh-28967
2022-08-16 15:42:52 +02:00
Sam Brannen 653552aa6f Make DefaultGenerationContext(GeneratedClasses,...) package private
The DefaultGenerationContext constructor which accepts an instance of
GeneratedClasses is now package private since GeneratedClasses can only
be created within the `org.springframework.aot.generate` package.
2022-08-16 12:06:40 +02:00
Sam Brannen 36fa8bd26b Remove unused constructors in TestGenerationContext 2022-08-16 12:06:40 +02:00
Arjen Poutsma ef178d24ec Merge branch '5.3.x' 2022-08-16 11:24:01 +02:00
Arjen Poutsma 7e7d6b9c3a Propagate Context in DataBufferUtils::write(Path)
This commit makes sure that the Reactor context is propagated in
DataBufferUtils::write(Path).

Closes gh-28933
See gh-27517
2022-08-16 11:21:12 +02:00
Sam Brannen c58c827291 Polishing 2022-08-15 19:53:21 +02:00
Sam Brannen 40f9fe0874 Make eclipse task for spring-core depend on JavaPoet and Objenesis tasks 2022-08-13 16:18:34 +02:00
Sam Brannen d6d629a8eb Clean up warnings in CGLIB fork 2022-08-13 16:03:28 +02:00
Stephane Nicoll 7c2453c373 Integrate class proxy generation in AOT processing
This commit updates ApplicationContextAotGenerator to register a
handler that process Cglib generated classes. The handler registers
such classes to the GeneratedFiles and provide a hint so that it
can be instantiated using reflection.

Closes gh-28954
2022-08-12 12:17:13 +02:00
Juergen Hoeller d6f73994c2 Fix malformed HTML in CGLIB javadoc
See gh-28955
2022-08-12 12:14:18 +02:00
Juergen Hoeller 7fa5b8dcb5 Turn CGLIB patch into full CGLIB fork in spring-core
Closes gh-28955
2022-08-12 11:38:43 +02:00
Sam Brannen a052f9a34e Polishing 2022-08-11 20:43:35 +02:00
Sam Brannen 7631a09405 Do not register SynthesizedAnnotation proxy for @AliasFor
Closes gh-28953
2022-08-11 20:32:03 +02:00
Sam Brannen 0207f3a55f Polishing 2022-08-11 19:41:56 +02:00
Stephane Nicoll d1abdff89c Merge branch '5.3.x' 2022-08-11 10:44:33 +02:00
Stephane Nicoll 6806aaf162 Polish "Add missing TreeSet to CollectionFactory.createCollection()"
See gh-28949
2022-08-11 08:28:43 +02:00
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