Treat InvalidPathException like an IOException in MockServletContext
Prior to this commit, if MockServletContext was configured with a
FileSystemResourceLoader, invocations of the following methods on a
Microsoft Windows operating system resulted in an InvalidPathException
if the supplied path contained a colon (such as "C:\\temp"). This is
inconsistent with the behavior on non-Windows operating systems. In
addition, for comparable errors resulting in an IOException, those
methods (except getRealPath()) return null instead of throwing the
exception.
- getResourcePaths()
- getResource()
- getResourceAsStream()
- getRealPath()
This commit makes handling of InvalidPathException and IOException
consistent for these methods: both exceptions now result in null be
returned by these methods.
Closes gh-23717
@ -294,8 +295,10 @@ public class MockServletContext implements ServletContext {
@@ -294,8 +295,10 @@ public class MockServletContext implements ServletContext {
@ -311,9 +314,10 @@ public class MockServletContext implements ServletContext {
@@ -311,9 +314,10 @@ public class MockServletContext implements ServletContext {
}
returnresourcePaths;
}
catch(IOExceptionex){
catch(InvalidPathException|IOExceptionex){
if(logger.isWarnEnabled()){
logger.warn("Could not get resource paths for "+resource,ex);
logger.warn("Could not get resource paths for "+
(resource!=null?resource:resourceLocation),ex);
}
returnnull;
}
@ -322,19 +326,22 @@ public class MockServletContext implements ServletContext {
@@ -322,19 +326,22 @@ public class MockServletContext implements ServletContext {
logger.warn("Could not get URL for "+resource,ex);
logger.warn("Could not get URL for resource "+
(resource!=null?resource:resourceLocation),ex);
}
returnnull;
}
@ -343,16 +350,19 @@ public class MockServletContext implements ServletContext {
@@ -343,16 +350,19 @@ public class MockServletContext implements ServletContext {
logger.warn("Could not open InputStream for "+resource,ex);
logger.warn("Could not open InputStream for resource "+
(resource!=null?resource:resourceLocation),ex);
}
returnnull;
}
@ -459,13 +469,16 @@ public class MockServletContext implements ServletContext {
@@ -459,13 +469,16 @@ public class MockServletContext implements ServletContext {
@ -294,8 +295,10 @@ public class MockServletContext implements ServletContext {
@@ -294,8 +295,10 @@ public class MockServletContext implements ServletContext {
@ -311,9 +314,10 @@ public class MockServletContext implements ServletContext {
@@ -311,9 +314,10 @@ public class MockServletContext implements ServletContext {
}
returnresourcePaths;
}
catch(IOExceptionex){
catch(InvalidPathException|IOExceptionex){
if(logger.isWarnEnabled()){
logger.warn("Could not get resource paths for "+resource,ex);
logger.warn("Could not get resource paths for "+
(resource!=null?resource:resourceLocation),ex);
}
returnnull;
}
@ -322,19 +326,22 @@ public class MockServletContext implements ServletContext {
@@ -322,19 +326,22 @@ public class MockServletContext implements ServletContext {
logger.warn("Could not get URL for "+resource,ex);
logger.warn("Could not get URL for resource "+
(resource!=null?resource:resourceLocation),ex);
}
returnnull;
}
@ -343,16 +350,19 @@ public class MockServletContext implements ServletContext {
@@ -343,16 +350,19 @@ public class MockServletContext implements ServletContext {
logger.warn("Could not open InputStream for "+resource,ex);
logger.warn("Could not open InputStream for resource "+
(resource!=null?resource:resourceLocation),ex);
}
returnnull;
}
@ -459,13 +469,16 @@ public class MockServletContext implements ServletContext {
@@ -459,13 +469,16 @@ public class MockServletContext implements ServletContext {