[antlr-interest] How to report bugs ?
Randall R Schulz
rschulz at sonic.net
Sat Mar 24 07:55:30 PDT 2007
Martin,
On Saturday 24 March 2007 03:12, Martin Probst wrote:
> Hi,
>
> > The use of File.separator I think this is a constant depending on
> > the platform. So if you compile this on a Windows box, it won't
> > work on a *nix box.
> >
> > The only evidence I have is that the released jar with Antlrworks
> > didn't work on my Mac. I recompiled the antlr jar and it worked
> > fine.
>
> File.separator is a constant in the File class, but Java is a late-
> binding language so this constant won't be inlined until runtime. So
> this should not be an issue on UNIX or Windows systems. And
> ANTLRWorks works for me on my Mac :-) Did you download the .app
> package?
Actually, this is not true for fields that are declared "static final".
In this case, the compiler inlines the value it finds when compiling.
There's a passage in the language specification (see sec. 13.4.9 of "The
Java Language Specification, 3rd Edition", pg. 349) suggesting that
for "constants" of the sort represented by these fields of class File
that a static accessor method be used.
Presumably the authors of File hadn't considered these subtleties way
back when they originally implemented it and established the API for
that class. The really should add the static methods.
Also, if you look at the description of those methods, you'll see
they're initialized from system properties, so code that needs to use
the constants specific to the platform on which they're running can
access those system properties. To wit (from
<http://java.sun.com/j2se/1.5.0/docs/api/>):
separatorChar
public static final char separatorChar
The system-dependent default name-separator character. This field is
initialized to contain the first character of the value of the system
property file.separator. On UNIX systems the value of this field
is '/'; on Microsoft Windows systems it is '\\'.
See Also:
System.getProperty(java.lang.String)
separator
public static final String separator
The system-dependent default name-separator character, represented
as a string for convenience. This string contains a single character,
namely separatorChar.
Lastly, the Macintosh (at least Mac OS X) is a Unix system and uses the
same file and path separator characters as does Linux, Solaris and
other POSIX-compliant systems. So I'm not sure why the OP had problems
there.
> Regards,
> Martin
Randall Schulz
More information about the antlr-interest
mailing list