Bug 57308 - Replace System.getProperty("file.separator") with File.separator throughout
Summary: Replace System.getProperty("file.separator") with File.separator throughout
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: trunk
Hardware: All All
: P2 trivial (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2014-12-04 13:04 UTC by Sebb
Modified: 2014-12-05 15:34 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Sebb 2014-12-04 13:04:24 UTC
Most of Tomcat uses File.separator, but there are a few instances of System.getProperty("file.separator")

The two can be different, but still allow the JVM to start up.
I found the following worked:

java -Dfile.separator=/xyz

for Unix or the equivalent \xyz on Windows.

Using a different first character does not work - the JVM usually throws an exception as it cannot find some required files if the sep. is incorrect.

It looks like only the first character of the property is used by the JVM. However, this is not done by the application code I have seen, which means that there could be a discrepancy between the two methods.

File.separator has the additional benefit that it is not subject to a privilege check.
Comment 1 Mark Thomas 2014-12-04 13:32:33 UTC
I have a patch for trunk [1] that I'll commit once svn writes are available again. Then I'll look at back-ports.

[1] https://github.com/markt-asf/tomcat/commit/0744a45a939311cc0ac0981a6922e4afd1e2e7d4
Comment 2 Sebb 2014-12-04 13:57:04 UTC
(In reply to Mark Thomas from comment #1)
> I have a patch for trunk [1] that I'll commit once svn writes are available
> again. Then I'll look at back-ports.
> [1]
> https://github.com/markt-asf/tomcat/commit/
> 0744a45a939311cc0ac0981a6922e4afd1e2e7d4

That would fix the instances I found.
Comment 3 Sebb 2014-12-04 14:14:17 UTC
It looks like the same applies to "path.separator" and File.pathSeparator.

i.e. changing the property causes issues for startup, and only the first char is used by Java.

If so, here are the instances I found in trunk:

java/org/apache/jasper/compiler/AntCompiler.java:        String sep = System.getProperty("path.separator");
java/org/apache/jasper/compiler/JspRuntimeContext.java:        String sep = System.getProperty("path.separator");
java/org/apache/tomcat/jni/Library.java:                String sep = System.getProperty("path.separator");
test/org/apache/juli/TestClassLoaderLogManager.java:                        + System.getProperty("path.separator")
test/org/apache/juli/TestClassLoaderLogManager.java:                        + System.getProperty("path.separator") + "baz",
test/org/apache/juli/TestClassLoaderLogManager.java:        Assert.assertEquals("${}" + System.getProperty("path.separator"),
Comment 4 Mark Thomas 2014-12-05 15:34:26 UTC
Fixed in trunk, 8.0.x (for 8.0.16 onwards) and 7.0.x (for 7.0.58 onwards).