You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by Bernd Waibel <BW...@intarsys.de> on 2016/03/22 12:31:10 UTC
Bug: James-project trunk: FileSystemImplTest fails on windows
[unsigned]
Hello together,
My aim is to get James running on windows.
The test org.apache.james.core.filesystem.FileSystemImplTest fails on Windows machines.
This is an remark, that some things are not handled correctly on windows.
Stacktrace (extract, more failures):
[1] file System Test, .txt (createdFilesAsInputStreamShouldBeAvailableWhenAccessedWithTwoSlashes)(org.apache.james.core.filesystem.FileSystemImplTest) Time elapsed: 0.01 sec <<< ERROR!
java.io.FileNotFoundException: C:\Users\bwa.IS\AppData\Local\Temp\junit2684853548080753950\C:\Users\bwa.IS\AppData\Local\Temp\file System Test60514476392426099.txt (Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at org.apache.james.core.filesystem.FileSystemResource.getInputStream(FileSystemResource.java:41)
at org.apache.james.core.filesystem.FileSystemImpl.getResource(FileSystemImpl.java:51)
at org.apache.james.filesystem.api.AbstractFileSystemTest.createdFilesAsInputStreamShouldBeAvailableWhenAccessedWithTwoSlashes(AbstractFileSystemTest.java:271)
Reason:
Reason is the handling of file separator, and of absolute file names.
On Windows the "ABSOLUTE" filename does not start with "file:///".
It starts with "file://<driveletter>:/". This is syntactically correct, and even on Linux the correct syntax of absolute file is NOT "file:///".
According to the standard (http://tools.ietf.org/html/rfc1738#section-3.10) the Syntax is:
file://<host>/<path>
Recommendation:
1. Instead of " + "/" + " I would recommend to always use " + java.lang.File.separator + ":
class ResourceFactory
class AbstractFileSystemTest
class DefaultJamesResourceLoader
2. It may be better to use the java.lang.File class to extract paths, not string operations.
class ResourceFactory
class DefaultJamesResourceLoader
Thoughts about fixing:
Only 2. Needs to be fixed, I think.
The class org.apache.james.core.filesystem.ResourceFactory does define an enum
ABSOLUTE(FileSystem.FILE_PROTOCOL_ABSOLUTE)
The string is used for "substring", but the method has the name "match". That's strange.
Match is something known when using regex matchers, so the method name should maybe be substring, but that is not a problem.
So, it is a "substring" used together with "file:///".
The class org.apache.james.filesystem.api.FileSystem does define a string
FILE_PROTOCOL_ABSOLUTE = "file:///"
The usage of this string need to be changed.
Why not use File instead of string handling, the java implementation normally does take care of the file systems.
There is a class SimpleUrl which does seem to handle Windows Filesystem.
The implementation of DefaultJamesResourceLoader and ResourceFactory seems to do the same, maybe consolidate this.
Best regards
Bernd