Dear Developer Community,
In an attempt to improve the code quality and platform independence, I would
like to point out a quite general source of problems, namely the handling of
files and paths. I do not want to criticize any of your work but rather make
developers sensible of pitfalls when dealing with files (what appears to be
an every day task in Maven world).
The point is simple: There are different operating systems. So what? Among
others, developers are quite naturally faced with different file systems
when programming for Java. And different file systems mean different rules
for denoting files. And here "different" not just means '/' becomes '\' or
vice versa. For example, the notation of an "absolute" path is
platform-dependent, too, and is not simply detected by a leading slash. The
different definitions of "equal" paths is another example (e.g.
case-sensitive vs. case-insensitive). Furthermore, file systems may impose
different restrictions on the allowed character set for path names or the
total path length.
So, I would put my take-home message like this:
Please avoid manual/direct manipulations of path strings.
Instead, one should use the java.io.File class whereever possible as it
already does a lot of work to properly handle paths. If the provided methods
do not suffice, org.apache.commons.io.FilenameUtils,
org.codehaus.plexus.util.FileUtils or any other well-tested/-used library
you know of that provides specially designed path handling methods should be
used.
Last but not least, let me state some related warnings. URLs/URIs or even
portions of them are in general not meaningful to a local file system, i.e.
should never be directly used as path strings (just consider URL-encoding).
Again, java.io.File can do the proper conversion using one of its
constructors. Finally, whenever paths are passed around externally using
command line or argument files or whatever, please think about spaces that
may cause premature token separation when not properly quoted/escaped.
Thanks for your attention and your ongoing efforts to bring the world a
better build environment.
Best regards,
Benjamin Bentmann
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email