TimeZone
Mark Wielaard
mark@klomp.org
Fri Aug 27 22:02:00 GMT 2004
Hi,
On Tue, 2004-08-24 at 22:49, Bryce McKinlay wrote:
> Mark Wielaard wrote:
> >Note that although both /etc/timezone and /etc/localtime are not
> >official posix standards lots of platforms (GNU, Darwin, Solaris,
> >FreeBSB at least) support one or the other.
> >
> >
> Useful to know, thanks. This should probably be mentioned in a comment
> in the code? I presume there are no endian/64-bit issues with this file
> format?
The /etc/timezone file is used differently on different systems (even
different on some GNU/Linux systems). But if it exists then the first
line always contains the timezone as ascii string. The tzdate file
format format is described pretty strictly. Andreas has tested it on a
powerpc (darwin) system. The only problem on Darwin was that the file
was missing the 4 magic bytes at the start (the code can now handle
this). I have added this as comment to TimeZone now.
> >>- In the TimeZone initializer, we should set the user.timezone system
> >>property if the user didn't set it.
> >
> >Why should we set the user.timezone system property?
> >And why in the initializer?
> >
> >
> Sorry. Thinko. TimeZone.getDefault() should set user.timezone if it
> wasn't set when called. This is for compatibility with Sun's
> implementation. I think I remember reading about this somewhere, but
> you're right, its not mentioned in the spec. I think we should implement
> this for compatibility, though - and document it, of course.
Interesting. But I don't think we should add this unspecified behavior
unless there are real programs depending on it. And even then it is just
a bug in the program.
> >>- Its not good to silently ignore exceptions:
> >>
> >I have changed the comments to make clear that we don't just ignore
> >them, but that they signal specific unexpected conditions.
> >
> Thanks. readTimeZoneFile() looks good, could you add a similar comment
> to readtzFile()?
Added.
> Also:
>
> - readtzFile() needs a "return null" at the bottom, I think. Its
> probably a GCJ bug that this didn't get detected.
No, there is no fall through (beyond the finally) in the code.
All code paths end in proper returns.
> - readLocaltimeFile() would be a better name for readtzFile()?
It can be used generically to read any tzdata file (even though we don't
do that currently).
> >I think that is a bit general statement that you should really back up
> >with benchmarks. But don't forget that this code is shared with other
> >runtimes which might have other tradeoffs. In this case the extra
> >security checks and disk i/o probably negate any gain you think comes
> >from so called "defensive coding" and makes the code a lot harder to
> >read/write.
> >
> There are no extra security checks needed - if you open a file, a
> security check will performed, if a security manager is installed,
> regardless of what methods you use to access the file. Using a String
> constructor rather than a File constructor does not avoid this.
There is now an extra security check. One when doing File.exists() and
another one when doing new FileInputStream(File). Also there are now two
transitions from java source code to native code. For JNI based systems
this is much less efficient.
> >I added a File.exist() check.
> >
> >
> Thanks. "if (!file.exists()) return" might look better?
Yes, added that. It solves my deep nesting complaint.
> >@@ -1145,11 +1529,13 @@
> > */
> > public static TimeZone getDefault()
> > {
> >+ // Should we return a clone?
> > return defaultZone();
> > }
> >
> >
>
> Hmm, TimeZone state can be manipulated, so yes, I think we should
> clone() here.
Ah, good that I kept that comment in. I added the clone() call.
> > public static void setDefault(TimeZone zone)
> > {
> >+ // Hmmmm. No Security checks?
> > defaultZone0 = zone;
> > }
> >
> I don't see any java.security.Permission types relating to time zones,
> so I guess this is not considered a security risk. Presumably, an applet
> could only screw itself up by messing with this, not the rest of the system.
I think it is an oversight in the spec since changing the default time
zone can disrupt some programs I think. So I keep the comment here.
> Anyway, this patch is basically fine. Feel free to address the above
> comments and then commit.
Thanks. Committed as attached.
2004-08-26 Mark Wielaard <mark@klomp.org>
Fixes PR libgcj/17002:
* java/util/TimeZone.java (defaultZone): Try a couple of ways to get
a TimeZoneId string and then try to convert that to a TimeZone with
getDefaultSystemTimeZone(String).
(timezones0): Changed type from Hashtable to HashMap.
(timezones): Create HashMap, not Hashtable.
(getDefaultTimeZone): New method, rewritten from CNI version.
(readTimeZoneFile): New method.
(readtzFile): Likewise.
(skipFully): Likewise.
* java/util/natTimeZone.cc (getSystemTimeZone): Renamed to
getDefaultTimeZoneId and rewritten.
(getDefaultTimeZoneId): Rewritten in java.
Cheers,
Mark
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TimeZone.patch4
Type: text/x-patch
Size: 25100 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20040827/f251bbb8/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20040827/f251bbb8/attachment.sig>
More information about the Java-patches
mailing list