Commit Graph

24828 Commits

Author SHA1 Message Date
Johnny Lim 2885177f5b Add @since tag for new CannotGetJdbcConnectionException constructor
See gh-28669
Closes gh-28738
2022-07-01 10:39:35 +02:00
Sébastien Deleuze 8c063a0e2a Add runtime hints for MethodValidationPostProcessor
Closes gh-28689
2022-07-01 10:18:08 +02:00
rstoyanchev 058ce36402 Improve ExtendedWebExchangeDataBinder implementation
Close gh-28646
2022-07-01 03:23:32 +01:00
Vikey Chen 2afe560e41 Replace forEach with putAll
See gh-28646
2022-07-01 03:01:12 +01:00
rstoyanchev b95362a3fd Avoid request params access for form data in logRequest
Close gh-28587
2022-07-01 02:55:16 +01: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
Brian Clozel 772d801e48 Test the ApplicationContextAotGenerator with the agent
This commit adds new tests for the `ApplicationContextAotGenerator`,
this time leveraging the `RuntimeHintsAgent` that checks the need for
runtime hints at runtime.

See gh-27981
2022-06-30 18:20:32 +02:00
Brian Clozel 52ec031025 Improve RuntimeHintsAgent test coverage
In order to write proper integration tests for the `RuntimeHintsAgent`,
we need to load the java agent on the JVM and instrument test code to
check that invocations are properly recorded.

This commit adds the relevant build configuration to the
integration-tests module and adds reflection tests for the agent.

Closes gh-27981
2022-06-30 18:20:28 +02:00
Brian Clozel fc1408f827 Configure RuntimeHintsAgent in test suite
This commit configures the `RuntimeHintsAgent` in the Spring Framework
test suite.
Instead of applying the agent to the entire test suite, and possibly
interfering with other tests, this commit adds a new custom Gradle
plugin that does the following:

* create a new test task named `"runtimeHintsTest"`
* run this task with the runtime hints java agent
* only execute tests tagged with `"RuntimeHintsTests"`

See gh-27981
2022-06-30 18:20:25 +02:00
Brian Clozel 444a9bd011 Add testing infrastructure for RuntimeHintsAgent
This commit adds the supporting testing infrastructure using the
`RuntimeHintsAgent`. Given that the agent is loaded by the JVM running
the test suite, we can then use it to record method invocations at
runtime and check whether the prepared `RuntimeHints` match the expected
behavior.

This commit contributes the `RuntimeHintsRecorder`. With this, we can
record relevant method invocations for a given lambda, focusing on a
specific part of the code behavior. This returns a
`RuntimeHintsInvocations` instance, which is an AssertJ assert provider.
From there, we can perform assertions on the recorded invocations and
check that a given collection of hints cover the reflection, resources
and proxies needs at runtime.

This also ships the `@EnabledIfRuntimeHintsAgent` opinionated
annotation: this applies the `RuntimeHintsAgentCondition` JUnit
extension that detects whether the `RuntimeHintsAgent` is loaded by the
current JVM. Tests annotated with this will be skipped if the agent is
not present. This annotation is also tagged with a JUnit `@Tag` to
gather such tests in a specific `"RuntimeHintsTests"` test suite.

In the Spring Framework build, we have chosen to isolate such tests and
not load the agent for the main test suite ("RuntimeHintsTests" tests
are excluded from the main suite). While the agent's intent is to be as
transparent as possible, there are security and access considerations
that could interefere with other tests.
With this approach, we can then create a separate test suite and run
agent tests in a dedicated JVM.

Note that projects using this infrastructure can choose to use the
condition by itself in a custom annotation.

Here is an example of this testing infrastructure:

```
@EnabledIfRuntimeHintsAgent
class MyTestCases {

  @Test
  void hintsForMethodsReflectionShouldMatch() {
      RuntimeHints hints = new RuntimeHints();
      hints.reflection().registerType(String.class,
          hint -> hint.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));

      RuntimeHintsInvocations invocations = RuntimeHintsRecorder.record(() -> {
          Method[] methods = String.class.getMethods();
      });
      assertThat(invocations).match(hints);
  }

}
```

See gh-27981
2022-06-30 18:20:22 +02:00
Brian Clozel c86e678788 Add RuntimeHintsAgent Java agent
With the introduction of `RuntimeHints`, we can now contribute
reflection, resources and proxies hints that describe the expected
runtime behavior of the application. While this can be verified at
runtime with smoke tests, managing such tests and compiling to native
there is not very efficient.

This commit introduces the new `RuntimeHintsAgent`, a Java agent that
instruments JDK methods related to `RuntimeHints`.
It is different from the GraalVM agent, which aims at collecting all the
required hints for the runtime behavior of an application and dump those
in the expected format.
Here, the `RuntimeHintsAgent` can collect the related invocations only
for a delimited scope (typically, a lambda within a test) and later
check those against a `RuntimeHints` instance. In the case of testing
`RuntimeHintsRegistrar` implementations, the process is reversed:
instead of manually checking for registered hints in a `RuntimeHints`
instance, tests should exercise the use cases and then check that the
recorded behavior is in line with the prepared hints.

This first commit adds the agent infrastructure that collects the
invocations for all relevant JDK methods.

See gh-27981
2022-06-30 18:20:16 +02:00
Sam Brannen 033d9d09e4 Merge branch '5.3.x' 2022-06-30 16:56:43 +02:00
Sam Brannen 9ea45697ac Support cookie comments in MockHttpServletResponse and MockCookie
Prior to this commit, if a cookie was added to MockHttpServletResponse,
the comment attribute was not included in the generated Set-Cookie
header. In addition, MockCookie.parse(String) did not support the
Comment attribute.

This commit addresses both of these issues.

Closes gh-28730
2022-06-30 16:51:43 +02:00
Sébastien Deleuze ecdd934658 Add runtime hints for AbstractHandshakeHandler
Closes gh-28697
2022-06-30 16:50:43 +02:00
Sébastien Deleuze e94f2a8e3f Add Jackson well-known module runtime hints
Closes gh-28709
2022-06-30 15:26:44 +02:00
Sam Brannen c48352b9c9 Merge branch '5.3.x' 2022-06-30 15:01:14 +02:00
Johnny Lim fe2b8580a0 Upgrade to Gradle Enterprise Conventions 0.0.10 2022-06-30 14:59:55 +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 4ec3e1042a Add runtime hints for WebFlux
Closes gh-28701
2022-06-30 10:02:34 +02:00
rstoyanchev b312eca391 Deprecate and set trailingSlash option to false
Closes gh-28552
2022-06-29 16:09:10 +01:00
Juergen Hoeller d2e27ad754 Support by-type constructor references via RuntimeBeanReference
Closes gh-28728
2022-06-29 17:02:33 +02:00
Juergen Hoeller a21b27e6d9 Use isAssignableValue instead of isInstanceOf for argument resolution
Includes related nullability refinements.

Closes gh-28727
2022-06-29 17:01:04 +02:00
rstoyanchev 14fd2605a3 Deprecate UrlPathHelper shortcuts on AbstractHandlerMapping
Given the availability of two alternatives mechanisms for URL path
matching, PathPatternParser and AntPathMatcher, and now that
parsed patterns are enabled by default, it makes sense to reduce the
proliferation of options on AbstractHandlerMapping by deprecating
shortcuts related to String path matching. Most applications rely
on Boot and on the MVC config to do all this.

See gh-28607
2022-06-29 13:04:22 +01:00
Sébastien Deleuze 8d08b1d323 Make *_PRESENT fields constant at build time
See gh-28624
2022-06-29 12:31:46 +02:00
rstoyanchev 92cf1e13e8 Enable use of parsed patterns by default in Spring MVC
Closes gh-28607
2022-06-29 10:17:27 +01:00
rstoyanchev 8a9b082d8a Improve MappingMatch determination in mock request
MockHttpServletRequest now checks the requestURI and servletPath to
check whether they imply a Servlet path mapping, which is the case
when the requestURI is longer than the contextPath + servletPath.

This is essential when parsed patterns are in use in which case the
request path is parsed taking into account only the requestURI and
the contextPath. However, if the MappingMatch indicates a match by
Servlet path, then the servletPath is also taken into account.

See gh-28607
2022-06-29 10:17:07 +01:00
rstoyanchev 9c2ad4a1b1 Improve forwarded URL support in HtmlUnit integration
Closes gh-28722
2022-06-29 10:16:45 +01: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 a970516080 Polish GenericApplicationContextTests 2022-06-27 17:05:02 +02:00
Sam Brannen 5e5e95aff7 Polish RuntimeHintsUtils 2022-06-27 16:29:34 +02:00
Sam Brannen 897e47d76d Revert changes specific to 5.3.x 2022-06-27 15:08:20 +02:00
Sam Brannen 10285ade66 Merge branch '5.3.x' 2022-06-27 15:07:27 +02:00
Sam Brannen 0c9def89de Ignore build artifacts from the main branch for nohttp 2022-06-27 15:05:05 +02:00
Sam Brannen 98dd5dbeb1 Clean up .gitignore file 2022-06-27 14:50:27 +02:00
Sam Brannen 65ebaa8a84 Merge branch '5.3.x' 2022-06-27 14:43:46 +02:00
Sam Brannen 8892a05868 Ignore /spring-core/graalvm/build artifacts from the main branch
This commit eases switching between the `main` and `5.3.x` branches.
2022-06-27 14:43:06 +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