Commit Graph

3127 Commits

Author SHA1 Message Date
Sam Brannen 66989434b4 Introduce unit tests for gh-29275 2022-10-07 14:02:11 +02:00
Sam Brannen 23b3fc7f3c Polish FileSystemResource 2022-10-07 14:01:07 +02:00
Sam Brannen 7175c4ca9a Normalize URIs returned from FileSystemResource.getURI()
Prior to this commit, if a FileSystemResource was created from a
java.nio.file.Path or java.nio.file.FileSystem, the URI returned from
getURI() was based on the semantics of Path#toUri() which always
includes the "authority component" (i.e., "//") after the scheme (e.g.,
"file://..."). In contrast, if a FileSystemResource is created from a
java.io.File or String, the URI returned from getURI() never includes
the "authority component" due to the semantics of File#toURI().

Consequently, invoking myFileSystemResource.getURI().toString() could
result in "file:/my/path" or "file:///my/path", depending on how the
FileSystemResource was created.

This behavior is not new; however, recent changes in
PathMatchingResourcePatternResolver -- which result in a
FileSystemResource being created from a java.nio.file.Path instead of
from a java.io.File -- make this difference more noticeable to users
and may in fact surface as a breaking change.

To address that issue, this commit revises the implementation of
FileSystemResource.getURI() by normalizing any `file:` URIs that it
returns. Effectively, URIs like "file:///my/path" will now take the
form "file:/my/path".

See gh-29163
Closes gh-29275
2022-10-07 13:27:08 +02:00
Sam Brannen af617c7da9 Disable failing test until gh-29275 is addressed 2022-10-07 12:40:55 +02:00
Sam Brannen c405e742f4 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java
2022-10-07 12:39:24 +02:00
Sam Brannen 8caed88c14 Test status quo for URI/URL for scanned filesystem resources
See gh-29275
2022-10-07 12:17:27 +02:00
Stephane Nicoll 635534c1ad Describe naming conventions of GeneratedMethods#add
Closes gh-28997
2022-10-07 12:05:57 +02:00
Sam Brannen 3dc60f1627 Backport changes to PathMatchingResourcePatternResolverTests 2022-10-07 11:01:02 +02:00
Juergen Hoeller b45a48461f Polishing 2022-10-06 12:03:25 +02:00
Stephane Nicoll efaee61f31 Harmonize accessors of RuntimeHints API
Closes gh-29269
2022-10-06 09:36:17 +02:00
Sam Brannen 30f1eee4d0 Polish Javadoc and implementation of ClassPathResource 2022-10-05 20:24:17 +02:00
Sam Brannen 8869ca27b1 Ensure ClassPathResources with same path have same hash code
This commit aligns the hashCode() implementation in ClassPathResource
with the recent change to the logic in equals().

See gh-29263
2022-10-05 16:58:08 +02:00
Sam Brannen 1082119c50 Polishing 2022-10-05 16:49:38 +02:00
Sam Brannen a380ca2750 Ensure ClassPathResources with same path and ClassLoader are equal
Prior to this commit, if two ClassPathResource instances were
constructed differently (one from an absolute path and one from a path
relative to a Class) but had the same absolute path and the same
ClassLoader, they were effectively equal, but ClassPathResource#equals
returned false.

This commit addresses this by revising the logic in
ClassPathResource#equals accordingly.

Closes gh-29263
2022-10-05 16:27:02 +02:00
Sam Brannen 0aa9d9d535 Return URL-decoded file name from UrlResource#getFilename()
Prior to this commit, UrlResource#getFilename() returned the filename
of the resource URL-encoded which is in contrast to what
FileSystemResource#getFilename() returns for an equivalent resource.

In addition, users most likely expect that a filename returned from a
method defined in the Resource interface is unencoded.

This commit therefore revises UrlResource#getFilename() so that it
always returns the filename URL-decoded.

Closes gh-29261
2022-10-05 15:52:22 +02:00
Sam Brannen 084d7d1bdc Remove duplicate ClassPathResourceTests class 2022-10-05 15:52:22 +02:00
Sam Brannen 2e05137ff9 Polish PathResourceTests 2022-10-05 15:52:22 +02:00
Sam Brannen f0556b6004 Undeprecate PathResourceTests 2022-10-05 15:52:22 +02:00
Stephane Nicoll f2e9d112b1 Fix TypeReference#getName for CGLIB proxies
This commit makes sure that the double '$' sign typically used by
generated cglib proxies are not used as an inner class separator.

Closes gh-29252
2022-10-04 16:49:13 +02:00
Sam Brannen 5bff2c7341 Clean up warnings in tests 2022-10-04 16:19:37 +02:00
Sam Brannen 31d98bfd95 Ensure PathMatchingResourcePatternResolverTests run in native image
See inline comments in commit for details.

See gh-29243
2022-10-04 16:13:46 +02:00
Sam Brannen dd814b6d30 Test sub-paths in PathMatchingResourcePatternResolverTests
This commit introduces assertions that verify that the sub-path is
properly URL-decoded when a path contains `#`. The additional assertions
are necessary since the existing assertions use Resource#getFilename
which already implicitly decodes the path.

See gh-29243
2022-10-04 15:50:33 +02:00
Sébastien Deleuze 5c447bb7a4 Make ConstantFieldSubstitutionProcessor thread-safe
See gh-29250
2022-10-04 15:23:18 +02:00
Sam Brannen ddc7aef51b Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java
2022-10-04 14:31:43 +02:00
Sam Brannen fee38175b3 Revert "Test encoding and Unicode normalization for scanned resources"
This reverts commit eb2c1cbcd4.
2022-10-04 14:29:22 +02:00
Sam Brannen 2ce314d4dd Modify PathMatchingResourcePatternResolverTests so that it passes on main
See gh-29243
2022-10-04 13:22:44 +02:00
Sam Brannen 5b08bc29b1 Merge branch '5.3.x' 2022-10-04 13:21:30 +02:00
Sam Brannen eb2c1cbcd4 Test encoding and Unicode normalization for scanned resources
This commit introduces tests which serve as "regression tests" for the
behavior of PathMatchingResourcePatternResolver in Spring Framework
5.3.x with regard to URL-encoding and Unicode normalization of resource
paths.

Specifically, the new tests demonstrate that resource paths do NOT need
to be decoded or normalized in 5.3.x.

See gh-29243
2022-10-04 13:19:59 +02:00
Juergen Hoeller 4a2b058b0a Enforce static initialization of CGLIB method proxies on attemptLoad
This propagates current Enhancer settings (naming strategy etc) to the method proxies.

See gh-29107
2022-10-04 12:24:09 +02:00
Sam Brannen 01025c8551 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java
2022-10-04 12:08:16 +02:00
Sam Brannen 7241c30141 Backport changes to PathMatchingResourcePatternResolverTests 2022-10-04 11:48:29 +02:00
Sébastien Deleuze 619b7bff17 Add ConstantReadableJavaField caching in ConstantFieldSubstitutionProcessor
Closes gh-29250
2022-10-04 11:03:48 +02:00
Brian Clozel 3b91eea0b7 Support parsing locales without country, with variant
Prior to this commit, the parsing algorithm in
`StringUtils#parseLocaleString` would skip empty tokens, turning
`en__VARIANT` into `en_VARIANT` when parsed.

This commit ensures that such cases are now supported and that more
invalid formats are rejected by the parser.

Fixes gh-29248
2022-10-03 22:44:09 +02:00
Violeta Georgieva b5adae2086 Switch to Reactor Netty 2 snapshots
Update to Reactor BOM 2022.0.0-SNAPSHOT.
Process package changes.
Adapt to new `HttpHeaders` API.
Adapt to new cookies API.

See gh-29247
2022-10-03 18:20:52 +01:00
Juergen Hoeller 1b1682eacd Narrow early initialization of CGLIB method proxies (for AOT processing)
Do not trigger early initialization on Factory classes (e.g. AOP proxies)

See gh-29107
2022-10-03 18:00:57 +02:00
Stephane Nicoll 3b2b36d0b8 Allow AccessControl to determine visibility from a given type
This commit adapts AccessVisibility so that it can determine if the
member or type signature is accessible from a given package. This lets
implementers figure out if reflection is necessary without assuming that
package private visibility is OK.

Closes gh-29245
2022-10-03 17:56:19 +02:00
Sam Brannen df58c00bf5 Restore GraalVM native image resource scanning support
This commit restores support for the GraalVM native image file system
in PathMatchingResourcePatternResolver.

Closes gh-29226
2022-10-03 17:38:30 +02:00
Juergen Hoeller 51875cdf5f Defensive early initialization of CGLIB method proxies (for AOT processing)
Method proxies might not actually be used later on, so failure is not fatal.

See gh-29107
2022-10-03 16:43:43 +02:00
Juergen Hoeller 740d3d931a Restore Windows compatibility through streamlined Path API interaction
In addition to consistent use of cleaned file paths, this revision avoids FileSystem SPI interaction, resolving NIO Path instances from URI (and FileSystemResource from Path).

See gh-29226
2022-10-03 16:08:46 +02:00
Sam Brannen d79d2fc573 Ensure ClassPathResourceTests can pass on MS Windows 2022-10-03 15:34:45 +02:00
Juergen Hoeller d873f60fef Enforce early initialization of CGLIB method proxies (for AOT processing)
For non-required method proxies, prefer regular reflective invocation instead.

See gh-29107
2022-10-03 13:22:49 +02:00
Brian Clozel 43d39d4e8a Enforce need for type reflection in RuntimeHintsAgent
Prior to this commit, the AOT infrastructure would rely on the fact that
native runtime reflection on a type would only consider
methods/fields/constructors that had specific hints contributed. When
listing them through the reflection API on the type, the native image
would only return those for which we had hints contributed.
This behavior will soon change in GraalVM and will better align with the
JVM behavior: when asking for all declared methods on a type in a native
image, we should get all existing methods, not just the ones registered
previously in the native image.

This commit aligns the behavior of the `RuntimeHintsAgent` and removes
the now misleading predicates as a consequence.

Closes gh-29205
2022-10-03 11:31:24 +02:00
Brian Clozel 94da3609af Ignore Blockhound tests on Java 19 2022-10-02 16:23:42 +02:00
Johnny Lim 89db4efb67 Polish ReflectionHintsPredicates
See gh-29230
2022-09-30 15:23:35 +02:00
Sam Brannen 2606557483 Polishing 2022-09-30 13:32:33 +02:00
Sam Brannen d21eea7de4 Fix recent regression in PathMatchingResourcePatternResolver
Commit 0eb66789ed which introduced generic FileSystem support in
PathMatchingResourcePatternResolver also introduced a regression in that
a matching folder is now returned in the results.

This commit address this by additionally using Files#isRegularFile() in
the predicate used to filter candidates.

Closes gh-29163
2022-09-30 13:05:31 +02:00
Sébastien Deleuze 3eaf326997 Refine ConstantFieldSubstitutionProcessor error handling
The upgrade to SLF4J 2 via gh-29152 has broken
ConstantFieldSubstitutionProcessor when the class processed
has both a static boolean field to make constant at build
time and a static logger.

This issue is about catching and logging those errors,
skipping the processing of such fields which will be
then evaluated at runtime.

Closes gh-29219
2022-09-29 12:52:30 +02:00
Sam Brannen 6cb131ac76 Polishing 2022-09-28 14:27:36 +02:00
Sam Brannen ccff526454 Reintroduce logging and exception handling for file system resource scanning
See gh-29163
2022-09-28 13:47:55 +02:00
Sam Brannen 7cb54de985 Apply root dir cleanup only for GraalVM native image resource scheme
See gh-29163
2022-09-28 13:47:44 +02:00