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

InvalidPathException in log when running SpringBootTest with NIO Path property on Windows #26828

Closed
kascaks opened this issue Apr 20, 2021 · 0 comments
Assignees
Labels
in: test Issues in the test module status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@kascaks
Copy link

kascaks commented Apr 20, 2021

When running following test, an InvalidPathException is logged with warn level. Test completes successfully, however the exception in log is quite misleading.

@SpringBootTest
public class MockServletTest {
	@SpringBootApplication
	public static class TestContext {
		@Value("C:\\tmp")
		private Path path;
	}
	@Autowired
	private TestContext testContext;
	@Test
	public void testPath() {
		Assertions.assertEquals(Paths.get("C:\\tmp"), testContext.path);
	}
}
WARN 17328 --- [           main] o.s.b.t.m.w.SpringBootMockServletContext : Could not get URL for resource src/main/webapp/C:/tmp

java.nio.file.InvalidPathException: Illegal char <:> at index 17: src\main\webapp\C:\tmp
	at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182) ~[na:1.8.0_252]
	...
	at java.io.File.toPath(File.java:2234) ~[na:1.8.0_252]
	...
	at org.springframework.mock.web.MockServletContext.getResource(MockServletContext.java:332) ~[spring-test-5.3.6.jar:5.3.6]
	at org.springframework.boot.test.mock.web.SpringBootMockServletContext.getResource(SpringBootMockServletContext.java:90) [spring-boot-test-2.4.5.jar:2.4.5]
	at org.springframework.web.context.support.ServletContextResource.exists(ServletContextResource.java:104) [spring-web-5.3.6.jar:5.3.6]
	at org.springframework.beans.propertyeditors.PathEditor.setAsText(PathEditor.java:104) [spring-beans-5.3.6.jar:5.3.6]
	...

Test environment is spring boot 2.4.5 on Windows.
The exception does not appear when running the application itself (i.e. outside of test)

Seems like this was already reported in this issue and specifically this comment, but it is still there. As said above, it is not affecting test result (test passes), it's just unexpected to see the exception when checking test logs, so the fix would be a 'nice to have' feature.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 20, 2021
@jhoeller jhoeller self-assigned this Apr 20, 2021
@jhoeller jhoeller added in: test Issues in the test module type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 20, 2021
@jhoeller jhoeller added this to the 5.3.7 milestone Apr 20, 2021
@jhoeller jhoeller changed the title InvalidPathException in log when running SpringBootTest with nio Path property on windows InvalidPathException in log when running SpringBootTest with NIO Path property on Windows Apr 30, 2021
@jhoeller jhoeller added the for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x label May 5, 2021
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x labels May 5, 2021
Zoran0104 pushed a commit to Zoran0104/spring-framework that referenced this issue Aug 20, 2021
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants