Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DefaultClassPathResourceLoader handle URLs with format jar:file:/{JAR_PATH}!/{PREFIX}!/{RESOURCE} gracefully #10092

Merged
merged 3 commits into from
Nov 10, 2023

Conversation

guillermocalvo
Copy link
Contributor

Context:

Some class loaders, such as Spring Boot's LaunchedURLClassLoader which is used by Grails, resolve resources located inside a JAR file as jar:file:/{JAR_PATH}!/{PREFIX}!/{RESOURCE}.

For example:

  • Resource application.yml
  • Resolves as URL: jar:file:/path/to/the/jar/file.war!/WEB-INF/classes!/application.yml

When Micronaut's resource loader tries to get application.yml as a stream from the file system, it fails with:

DefaultClassPathResourceLoader : Error establishing whether path is a directory: /application.yml

java.nio.file.NoSuchFileException: /application.yml
  at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.newByteChannel(ZipFileSystem.java:702)
  at jdk.zipfs/jdk.nio.zipfs.ZipPath.newByteChannel(ZipPath.java:815)
  at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.newByteChannel(ZipFileSystemProvider.java:252)
  at java.base/java.nio.file.Files.newByteChannel(Files.java:371)
  at java.base/java.nio.file.Files.newByteChannel(Files.java:422)
  at java.base/java.nio.file.Files.readAllBytes(Files.java:3206)
  at io.micronaut.core.io.scan.DefaultClassPathResourceLoader.getResourceAsStream(DefaultClassPathResourceLoader.java:126)
  ...

This PR makes sure these URLs hare handled gracefully if the resource is not found at the default location (ie. it will retrieve WEB-INF/classes/application.yml instead of application.yml).

Related issues:

@guillermocalvo guillermocalvo changed the base branch from 4.2.x to 3.10.x November 9, 2023 10:57
@sdelamo sdelamo requested a review from yawkat November 9, 2023 11:09
Copy link

sonarcloud bot commented Nov 9, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.21) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

@sdelamo sdelamo merged commit 105f81b into 3.10.x Nov 10, 2023
11 checks passed
@sdelamo sdelamo deleted the jar-resource-loader branch November 10, 2023 08:32
sdelamo pushed a commit that referenced this pull request Nov 10, 2023
…le:/{JAR_PATH}!/{PREFIX}!/{RESOURCE}` gracefully (#10092)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants