core icon indicating copy to clipboard operation
core copied to clipboard

Wrong use of File.separator all over dotCMS

Open monzonj opened this issue 11 years ago • 7 comments

Hello,

I've noticed that in many places you guys use File.separator to build URIs and URL. For instance, here: https://github.com/dotCMS/core/blob/master-3.1/src/com/dotmarketing/util/OSGIUtil.java#L84

This is wrong because getRealPath and other URI related methods take a 'virtual path' which is supposed to be a URL fragment. This means forward slashes, no backslashes. Documentation: http://docs.oracle.com/javaee/1.3/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)

The concept of virtual paths in Java are not well defined, it is platform independent. In windows machines the File.separator is a backward slash.

Now, early versions of Tomcat had a loose implementation of the spec and accepted both slashes. Tomcat8 seems to be more strict and forward slash is mandatory. dotCMS breaks badly when run under Tomcat 8.

I believe you should get rid of those File.separator when using virtual paths in future versions. And document that dotCMS actually works with Tomcat7 and it breaks in newer versions.

Regards,

monzonj avatar Jan 13 '15 08:01 monzonj

Right and here is some more info http://stackoverflow.com/questions/25555541/getservletcontext-getrealpath-in-tomcat-8-returns-wrong-path and https://issues.apache.org/bugzilla/show_bug.cgi?id=55837

FWIW this is only an issue on Windows and the Java API is loose here.

We will address though in a later version. Tomcat 8 is pretty new.

jtesser avatar Jan 13 '15 12:01 jtesser

not sure but they indicate they changed something in 8.0.2+ https://issues.apache.org/bugzilla/show_bug.cgi?id=56085

jtesser avatar Jan 13 '15 12:01 jtesser

they made the api more strict and now only accepts forward slashes. the change in 8.0.2 won't make the call throw an exception if the path does not exist, but it returns null.

There's no other workaround but to change File.separator for forward slash. It is wrong as it is, anyways, even if it works for Tomcat 7-

monzonj avatar Jan 13 '15 13:01 monzonj

We try use File.separator where appropriate, for example, where we are constructing a path to a physical file on the Filesystem.

This code in the initializeFramework method actually looks like a bug to me and should be fixed.

https://github.com/dotCMS/core/blob/master-3.1/src/com/dotmarketing/util/OSGIUtil.java#L84

dotcmsCodeReview avatar Jan 13 '15 13:01 dotcmsCodeReview

@agreed it should be fixed there are a number of places. That is why I didn't close the issue.

jtesser avatar Jan 13 '15 13:01 jtesser

Related and fixed in #7253

jgambarios avatar Mar 03 '15 17:03 jgambarios

Fixed, the application is working without problems

bryanboza avatar Mar 18 '15 20:03 bryanboza