-
Notifications
You must be signed in to change notification settings - Fork 38.1k
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
Root path resolution for java.nio.Path properties does not work on Linux anymore #26702
Comments
Thanks for the report. I don't recall any changes for |
Scratch that. There's no need for a sample as the problem's easier to reproduce than I had anticipated. This will do it: package com.example.demo;
import java.nio.file.Path;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
@EnableConfigurationProperties(TestProperties.class)
public class Gh25734Application {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(Gh25734Application.class, "--test.path=/some/root/path");
TestProperties testProperties = context.getBean(TestProperties.class);
System.out.println(testProperties.getPath());
context.close();
}
}
@ConfigurationProperties(prefix="test")
class TestProperties {
private Path path;
public Path getPath() {
return path;
}
public void setPath(Path path) {
this.path = path;
}
} With Spring Boot 2.4.3 it outputs the following:
Whereas Spring Boot 2.4.4 outputs the following:
With Spring Boot 2.4.4 and Spring Framework downgraded to 5.3.4 it outputs the following:
This looks like a regression in Spring Framework 5.3.5, I suspect due to this change. We'll transfer this issue to the Framework team so that they can take a look. |
Potential regression introduced in conjunction with #26575. |
This looks very much like a regression caused by that change indeed. I suspect it only happens for non-existing paths because that's what #26575 was trying to fix in Windows scenarios? Any suggestions for how to refine that check to work on Windows as well as Linux? On a side note, we need to backport this to 5.2.x as well. Fortunately 5.2.14 isn't released yet but the original change got backported to the branch. |
It seems to happen for paths that exist as well. For example, That happens because the |
Hmm, I guess I'm still missing something... If the path exists, wouldn't it always have gone into the So if we fail to resolve against root in such a Servlet resource scenario on Linux, do we have potentially an issue with the |
With 5.3.4, the call to Lines 100 to 102 in d9a9686
On 5.3.5 the call to Lines 100 to 111 in 7c2a72c
I think 5.3.4 would behave differently if the servlet context happened to contain a resource that matched the path. If this ambiguity is avoided by using |
Ah ok that clarifies things quite a bit, thanks for digging deeper there, @wilkinsona ... So now we need to figure out which part of the interaction is wrong there. Maybe we'll replace the |
Got struck by this issue as well on OSX, spring 5.3.5 behaves differently with IDEA run and gradleRun. |
To be honest, I'm not quite sure what the fix was trying to correct. The way I understand file uri scheme, you cannot have double slash after |
It turns out that the lenient resolution of Windows-style path separators after a "file:" prefix has been established by |
@wilkinsona @snicoll It'd be great if you could test the fix with Boot on Linux/MacOS before we release tomorrow. I can confirm that it (still) works fine on Windows; hopefully this fixes the regression for good. |
@jhoeller I confirm the sample above works for MacOS with the latest snapshot. I ran the app in a linux docker container and it worked as well. |
Under Spring Boot 2.4.4 having a configuration class with a java.nio.Path field does not map correctly for a root filesystem on Linux if the spring-boot-web-starter is included.
Example application.properties value:
my-config.workingPath=/my-working-path
When the above is run on linux with the web starter included, the path is set under the tomcat temp directory, or under the exploded WAR file directory if running on a different application server.
If the path is set to a value such as: c:\temp\my-working-path on a Windows machine, there is no issue with or without the web starter dependency.
Creating a ConfigurationPropertiesBinding converter seems to be picked up when running on Windows, but ignored on Linux.
Changing the properties class field from java.nio.Path to String and implementing a custom get method that returns Paths.get(s) works fine on windows and linxu both with and without the web starter included in the project.
Issue does not seem to exist prior to Spring Boot 2.4.4.
The text was updated successfully, but these errors were encountered: