TimeZone

Mark Wielaard mark@klomp.org
Wed Aug 25 15:10:00 GMT 2004


Hi,

On Mon, 2004-08-23 at 17:49, Bryce McKinlay wrote:
> - We are making very posix-y (or even glibc?) assumptions in the generic 
> java.util.TimeZone code, specifically the /etc/localtime and 
> /etc/timezone reading code. Perhaps this should be factored out into a 
> posix-specific file? Windows, for example, will probably have a saner 
> way to get the timezone and will want to implement this their own way. 
> At least, I think the file reader functions should be called from 
> getDefaultTimeZoneID, not getDefaultTimeZone(). This way, other 
> platforms can avoid them if they want.

Yes. I want to split it into a TimeZone and VMTimeZone class and do some
other small cleanups when I import it into GNU Classpath. Then the
specific "Posix/GNU assumptions" can also be factored out. I didn't want
to do all that immediately though since the patch is already fairly
large.

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.

> - 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?
And to what in that case since we don't have the default timezone when
we run the initializer? Or do you mean when getDefault() is called for
the first time? Either way it doesn't really make sense to me and I
cannot find this specified anywhere.

> - Its not good to silently ignore exceptions:
> 
> +    catch (IOException ioe)
> +      {
> +        return null;
> +      }
> +    finally
> +      {
> +        try
> +          {
> +            if (isr != null)
> +              isr.close();
> +          }
> +        catch (IOException ioe)
> +          {
> +            //ignored
> +          }
> +      }

I have changed the comments to make clear that we don't just ignore
them, but that they signal specific unexpected conditions.

> Instead we should "code defensively" to avoid throwing exceptions 
> wherever possible, especially in code that might run during 
> runtime/application startup. Aside from being somewhat slow at the best 
> of times, throwing an exception brings a lot of extra data (unwind 
> tables) into memory. That increases startup time and increases memory usage.

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. Also note that this code does not run during runtime
initialization/startup.

> Ideally IOExceptions should not be ignored unless absolutely necessary, 
> for example we should check file.exists() before trying to create a 
> stream on it and read from it.

I added a File.exist() check.

Also added a check in natTimeZone.cc for HAVE_LOCALTIME_R and fallback
to the non-thread safe localtime() otherwise.

2004-08-23  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.

OK to commit?

Mark
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TimeZone.patch3
Type: text/x-patch
Size: 24035 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20040825/bf73ca06/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/20040825/bf73ca06/attachment.sig>


More information about the Java-patches mailing list