Commit Graph

4433 Commits

Author SHA1 Message Date
Sam Brannen 4fdf40e39e Fix Checkstyle configuration for nullability annotations
While assessing #35195, I noticed the following issues with our
Checkstyle configuration regarding nullability annotations.

- "^(?!org\.jspecify|\.annotations).*(NonNull|Nullable)$" contains a "|".

- "^(?!org\.jspecify|\.annotations).*(NonNull|Nullable)$" matches against
  NonNull but not against Nonnull, and therefore incorrectly permits
  usage of javax.annotation.Nonnull.

- Some of the Checkstyle suppressions no longer apply.

This commit addresses all of the above issues and updates several tests
to use example annotations other than javax.annotation.Nonnull where
feasible.

See gh-35195
Closes gh-35205
2025-07-15 16:50:21 +02:00
Sébastien Deleuze 19086835a7 Upgrade tests to OkHttp 5.x
See https://square.github.io/okhttp/changelogs/changelog/#version-500.

Closes gh-35183
2025-07-15 16:20:07 +02:00
Juergen Hoeller 1145054971 Introduce ConfigurationBeanNameGenerator for @Bean-annotated methods
Includes FullyQualifiedConfigurationBeanNameGenerator implementation.

Closes gh-33448
2025-07-13 16:08:05 +02:00
Juergen Hoeller 64de254b58 Merge branch '6.2.x'
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Waiting to run Details
Build and Deploy Snapshot / Verify (push) Blocked by required conditions Details
Deploy Docs / Dispatch docs deployment (push) Waiting to run Details
2025-07-11 22:50:47 +02:00
Juergen Hoeller 4277682a5c Catch InaccessibleObjectException next to IllegalAccessException
Backport Bot / build (push) Waiting to run Details
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Waiting to run Details
Build and Deploy Snapshot / Verify (push) Blocked by required conditions Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:false version:17], map[id:ubuntu-latest name:Linux]) (push) Waiting to run Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:21], map[id:ubuntu-latest name:Linux]) (push) Waiting to run Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:23], map[id:ubuntu-latest name:Linux]) (push) Waiting to run Details
Deploy Docs / Dispatch docs deployment (push) Waiting to run Details
Closes gh-35190
2025-07-11 22:44:11 +02:00
Juergen Hoeller ba6166a02d Prefer most abstract method in getPubliclyAccessibleMethodIfPossible
Closes gh-35189
2025-07-11 22:42:36 +02:00
Juergen Hoeller c754bfe7e6 Fall back to getPubliclyAccessibleMethodIfPossible on IllegalAccessException
Closes gh-34028
2025-07-11 22:41:50 +02:00
Sam Brannen 7ea619aefb Merge branch '6.2.x' 2025-07-09 12:56:33 +02:00
Sam Brannen 3dc22379a0 Register runtime hints for Instant-to-Timestamp conversion
If an application depends on automatic type conversion from
java.time.Instant to java.sql.Timestamp, the ObjectToObjectConverter
performs the conversion based on convention, by using reflection to
invoke Timestamp.from(Instant).

However, when running in a native image a user needs to explicitly
register runtime hints for that particular use of reflection.

To assist users who are running their applications in a native image,
this commit automatically registers the necessary runtime hints for
Timestamp.from(Instant) so that users do not have to.

See gh-35175
Closes gh-35156
2025-07-09 12:35:10 +02:00
Sam Brannen 7900315f23 Introduce Date-to-Instant and Instant-to-Date converters
In order to avoid unnecessary use of reflection and to simplify native
image deployments, this commit introduces explicit support for
automatic conversions from java.util.Date to java.time.Instant and vice
versa.

To achieve that, this commit introduces an InstantToDateConverter and a
DateToInstantConverter and registers them automatically in
DefaultConversionService.

See gh-35156
Closes gh-35175
2025-07-09 12:31:44 +02:00
Sébastien Deleuze a61b297967 Specify flexible generics nullness in spring-jdbc
This commit leverages flexible generics nullness at method and
type level when relevant in spring-jdbc.

Due to https://github.com/uber/NullAway/issues/1075, some related
`@SuppressWarnings("NullAway")` have been added.

JdbcOperations Kotlin extensions have been refined accordingly.

Closes gh-34911
2025-07-07 16:35:25 +02:00
Sam Brannen 32b56a35c6 Short-circuit matching algorithm in InstanceFilter
In commit 97522cfa36, I implemented a
short-circuiting matching algorithm in DefaultRetryPolicy for includes
and excludes, which was later copied to MethodRetrySpec.

After we switched to using ExceptionTypeFilter, I realized that the
matching algorithm in InstanceFilter (the superclass of
ExceptionTypeFilter) does not exhibit the same short-circuiting
characteristics.

In light of that, this commit revises the matching algorithm in
InstanceFilter to mirror the original short-circuiting algorithm in
DefaultRetryPolicy.

See gh-35058
See gh-35109
See gh-35160
Closes gh-35161
2025-07-05 13:13:52 +02:00
Sam Brannen 17df4b4c38 Support direct matching against exceptions in ExceptionTypeFilter
Prior to this commit, ExceptionTypeFilter only supported matching
against an exception type. However, most use cases involve matching
against an exception instance. Moreover, every use case within the core
Spring Framework uses ExceptionTypeFilter to match against concrete
exception instances.

This commit therefore introduces an overloaded match(Throwable) method
in ExceptionTypeFilter in order to provide support for the most common
use cases.

See gh-35109
Closes gh-35160
2025-07-05 13:13:47 +02:00
Sam Brannen 33f51b183d Add missing tests for ExceptionTypeFilter 2025-07-05 12:15:14 +02:00
Sam Brannen d510b738f4 Match if empty by default in InstanceFilter and ExceptionTypeFilter
Prior to this commit, the constructors for InstanceFilter and
ExceptionTypeFilter required one to supply the matchIfEmpty flag.
However, users will typically want that to be true. Moreover, we always
supply true for the matchIfEmpty flag within the Spring Framework.

This commit therefore makes the matchIfEmpty flag optional by
introducing overloaded constructors for InstanceFilter and
ExceptionTypeFilter that only accept the includes and excludes
collections.

In addition, this commit overhauls the Javadoc for InstanceFilter and
ExceptionTypeFilter, fixing several issues in the documentation.

Furthermore, this commit applies consistent @⁠Nullable declarations
in ExceptionTypeFilter.

Closes gh-35158
2025-07-04 18:16:52 +02:00
Sam Brannen 46c40e7b96 Require explicit constraints in @⁠Contract
Prior to this commit, the value attribute in @⁠Contract was declared as
follows.

    String value() default "";

That allowed empty declarations such as @⁠Contract or @⁠Contract();
however, a contract is not useful without declared constraints.

To address that, this commit removes the `default ""` declaration in
order to force users to provide explicit constraints.

Although one could technically still declare the annotation without
constraints via @⁠Contract(""), it's unlikely that anyone would
intentionally do that.

Closes gh-35157
2025-07-04 18:16:52 +02:00
Sam Brannen c6a8df4a9d Use Duration.ZERO whenever possible 2025-07-03 16:55:09 +02:00
Sam Brannen 58061ae295 Polish contribution
See gh-35109
2025-07-03 16:49:40 +02:00
Mengqi Xu 489ebd2438 Use ExceptionTypeFilter to filter includes & excludes for retry policies
This commit reduces code duplication by reusing the logic already
available in ExceptionTypeFilter.

Closes gh-35109

Signed-off-by: Mengqi Xu <2663479778@qq.com>
2025-07-03 16:49:40 +02:00
Sam Brannen 0f495d3b64 Remove obsolete Javadoc reference
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Waiting to run Details
Build and Deploy Snapshot / Verify (push) Blocked by required conditions Details
Deploy Docs / Dispatch docs deployment (push) Waiting to run Details
See gh-35144
2025-07-02 11:47:12 +02:00
Sam Brannen 5cae769c2d Remove maxDuration/maxElapsedTime support from RetryPolicy
When the core retry functionality was introduced, it had a built-in
MaxRetryDurationPolicy. In #35058, that was migrated to a
withMaxDuration() factory method, and in #35110 that was renamed to
withMaxElapsedTime() (with a corresponding maxElapsedTime() method on
the builder) in order to align with the maxElapsedTime feature of
ExponentialBackOff. The latter also changed the semantics of the
feature in the context of the RetryPolicy.

However, @⁠Retryable does not provide maxElapsedTime support.

In addition, the maxElapsedTime feature is a bit misleading, since it
does not actually track CPU time or wall-clock time but rather only the
sum of individual, accumulated back-off intervals/delays, which is
likely not very useful. Furthermore, the maxElapsedTime will never
apply to a zero-valued delay/interval.

In light of the above, this commit removes the maxElapsedTime support
from the built-in RetryPolicy.

Users can still implement a custom BackOff strategy if they find they
need some form of "max elapsed time" or "max duration".

See gh-34716
See gh-35058
See gh-34529
See gh-35110
Closes gh-35144
2025-07-02 10:18:36 +02:00
Sam Brannen cc31bf3c33 Accept zero for RetryPolicy.Builder.delay()
This aligns the programmatic RetryPolicy configuration option with the
delay support in @⁠Retryable.

See gh-35110
2025-07-01 17:40:15 +02:00
Sébastien Deleuze fb214bb74a Merge branch '6.2.x' 2025-07-01 11:02:54 +02:00
Phillip Webb 89b8b1a468 Prevent cache pollution by storing only the factories
Update `SpringFactoriesLoader` so that the cache stores only the
factories and not the complete loader.

Prior to this commit, if a cache entry was added with the thread
context classloader, the loader instance would be added and the
classloader stored. If the thread context classloader subsequently
changes, and a call is made to `forDefaultResourceLocation` with
`null` for the classloader, the cached entry would be used which
contains the older classloader.

Closes gh-34732
2025-07-01 11:01:48 +02:00
Sam Brannen 769ba9e23b Merge branch '6.2.x'
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Waiting to run Details
Build and Deploy Snapshot / Verify (push) Blocked by required conditions Details
Deploy Docs / Dispatch docs deployment (push) Waiting to run Details
2025-06-29 17:42:35 +02:00
Sam Brannen 1ad05db877 Simplify dependency management for JUnit artifacts
Backport Bot / build (push) Waiting to run Details
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Waiting to run Details
Build and Deploy Snapshot / Verify (push) Blocked by required conditions Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:false version:17], map[id:ubuntu-latest name:Linux]) (push) Waiting to run Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:21], map[id:ubuntu-latest name:Linux]) (push) Waiting to run Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:23], map[id:ubuntu-latest name:Linux]) (push) Waiting to run Details
Deploy Docs / Dispatch docs deployment (push) Waiting to run Details
This commit simplifies our dependency management for JUnit artifacts by
making use of the junit-jupiter and junit-platform-suite aggregator
artifacts.

Closes gh-35127
2025-06-29 17:42:22 +02:00
Sam Brannen b211ac1f4a Resolve warning in CachingMetadataReaderFactoryTests 2025-06-29 16:28:09 +02:00
Sam Brannen ad278cd52e Fix ExponentialBackOffTests 2025-06-28 19:29:49 +02:00
Sam Brannen 4cdfd90882 Polish backoff and retry support
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Waiting to run Details
Build and Deploy Snapshot / Verify (push) Blocked by required conditions Details
Deploy Docs / Dispatch docs deployment (push) Waiting to run Details
This revises commit 15dd320b95.

See gh-34529
See gh-35110
2025-06-28 19:14:45 +02:00
Juergen Hoeller 96f0399072 Reintroduce FixedBackOff(long) constructor
Effectively removing FixedBackOff(Duration) only.

See gh-35028
See gh-35110
2025-06-28 12:11:02 +02:00
Juergen Hoeller 15dd320b95 Consistent maxAttempts (long) and delay/maxDelay (Duration) declarations
Includes timeUnit attribute in @Retryable (aligned with @Scheduled).

See gh-34529
See gh-35110
2025-06-28 11:40:00 +02:00
Sam Brannen bcdf26d492 Redesign RetryPolicy to directly incorporate BackOff
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Waiting to run Details
Build and Deploy Snapshot / Verify (push) Blocked by required conditions Details
Deploy Docs / Dispatch docs deployment (push) Waiting to run Details
After experimenting with our newly introduced core retry support
(RetryPolicy, RetryTemplate, etc.) and @⁠Retryable support, it
became apparent that there are overlapping concerns between the current
RetryPolicy and BackOff contracts.

- RetryPolicy and BackOff both have stateful executions: RetryExecution
  and BackOffExecution. However, only one stateful execution is
  necessary.

- FixedBackOff and ExponentialBackOff already incorporate "retry" logic
  in terms of max attempts, max elapsed time, etc. Thus, there is no
  need to duplicate such behavior in a RetryPolicy and its
  RetryExecution.

- RetryTemplate currently accepts both a RetryPolicy and a BackOff in
  order to instrument the retry algorithm. However, users would
  probably rather focus on configuring all "retry" logic via a single
  mechanism.

In light of the above, this commit directly incorporates BackOff
in RetryPolicy as follows.

- Remove the RetryExecution interface and move its shouldRetry() method
  to RetryPolicy, replacing the current RetryExecution start() method.

- Introduce a default getBackOff() method in the RetryPolicy interface.

- Introduce RetryPolicy.withDefaults() factory method.

- Completely overhaul the RetryPolicy.Builder to provide support for
  configuring a BackOff strategy.

- Remove BackOff configuration from RetryTemplate.

- Revise the method signatures of callbacks in RetryListener.

The collective result of these changes can be witnessed in the
reworked implementation of AbstractRetryInterceptor.

RetryPolicy retryPolicy = RetryPolicy.builder()
		.includes(spec.includes())
		.excludes(spec.excludes())
		.predicate(spec.predicate().forMethod(method))
		.maxAttempts(spec.maxAttempts())
		.delay(Duration.ofMillis(spec.delay()))
		.maxDelay(Duration.ofMillis(spec.maxDelay()))
		.jitter(Duration.ofMillis(spec.jitter()))
		.multiplier(spec.multiplier())
		.build();

RetryTemplate retryTemplate = new RetryTemplate(retryPolicy);

See gh-34716
See gh-34529
See gh-35058
Closes gh-35110
2025-06-27 17:28:10 +02:00
Sam Brannen 98b29b5e37 Consistently implement toString() in BackOff strategies
Closes gh-35120
2025-06-27 16:10:55 +02:00
Sam Brannen d97288a74e Improve Javadoc and tests for BackOff strategies 2025-06-27 16:04:32 +02:00
Stefano Cordio f7fef93842 Refine nullability of MethodInvoker#setArguments
Closes gh-35089
Signed-off-by: Stefano Cordio <stefano.cordio@gmail.com>
2025-06-26 15:04:49 +02:00
Juergen Hoeller 841d9fb73b Add public method to get bean order on DefaultListableBeanFactory
Closes gh-34712
2025-06-26 14:48:07 +02:00
Tran Ngoc Nhan 1a046f9cec Fix Nullable import in ClassFileAnnotationMetadata
Closes gh-35114

Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
2025-06-25 20:43:09 +02:00
Brian Clozel 2fa25b50d9 Fix caching operations in CachingMetadataReaderFactory
gh-33616 refactored `CachingMetadataReaderFactory` and broke the
behavior as it bypassed the cache for `getMetadataReader(String
className)` operations.

This commit restores the original behavior.

Fixes gh-35112
2025-06-25 20:32:38 +02:00
Sam Brannen f3f05da39b Refer to Spring Retry project in Javadoc
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Waiting to run Details
Build and Deploy Snapshot / Verify (push) Blocked by required conditions Details
Deploy Docs / Dispatch docs deployment (push) Waiting to run Details
2025-06-25 16:38:48 +02:00
Juergen Hoeller e828bbbb0a Invert order of suppressed exceptions (for common exception rendering)
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Waiting to run Details
Build and Deploy Snapshot / Verify (push) Blocked by required conditions Details
Deploy Docs / Dispatch docs deployment (push) Waiting to run Details
See gh-35057
2025-06-24 22:22:45 +02:00
Sébastien Deleuze 839d3a7d44 Refine nullability of PropertyResolver.getProperty(key: String)
Closes gh-35104
2025-06-24 16:06:32 +02:00
Sébastien Deleuze 294406dae9 Remove `@Suppress("EXTENSION_SHADOWED_BY_MEMBER")`
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Waiting to run Details
Build and Deploy Snapshot / Verify (push) Blocked by required conditions Details
Deploy Docs / Dispatch docs deployment (push) Waiting to run Details
Fixed in Kotlin 2.2.0 and IntelliJ IDEA IDEA 2024.2 EAP, see
https://youtrack.jetbrains.com/issue/KT-75169 related issue.

See gh-34453
2025-06-24 11:40:23 +02:00
Juergen Hoeller 6927e39e6b Merge branch '6.2.x' 2025-06-18 12:23:07 +02:00
Juergen Hoeller aa525cc3cd Delegate to ReflectionUtils.accessibleConstructor
Backport Bot / build (push) Has been cancelled Details
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Has been cancelled Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:false version:17], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:21], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:23], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled Details
Deploy Docs / Dispatch docs deployment (push) Has been cancelled Details
Build and Deploy Snapshot / Verify (push) Has been cancelled Details
2025-06-18 12:20:30 +02:00
Sam Brannen c5fd57d92b Polish @⁠Retryable Javadoc and internals 2025-06-17 17:07:15 +02:00
Sébastien Deleuze f601bbb2ac Allow usage of `@CheckReturnValue` on types and ctors
Closes gh-34910
2025-06-17 16:53:12 +02:00
Sam Brannen 74ee1b991a Apply consistent copyright headers in Kotlin source code
See gh-35070
2025-06-17 16:24:15 +02:00
Spring Builds 16edf9867a Update copyright headers in source files
This commit updates Java, Kotlin, and Groovy source files to use the
"<year>-present" pattern in copyright headers.

Closes gh-35070
2025-06-17 16:23:50 +02:00
Sam Brannen 103a7e58bb Apply consistent copyright headers in Kotlin source code
See gh-35070
2025-06-17 15:54:58 +02:00
Spring Builds aee29b7f30 Update copyright headers in source files
This commit updates Java, Kotlin, and Groovy source files to use the
"<year>-present" pattern in copyright headers.

Closes gh-35070
2025-06-17 15:54:58 +02:00