james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bernd Waibel <BWai...@intarsys.de>
Subject Bug: James-project trunk: FileSystemImplTest fails on windows [unsigned]
Date Tue, 22 Mar 2016 11:31:10 GMT
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



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message