1

I've heard performance concerns in the past about using Joda Time on Android. One specific example was an issue with the way that timezone data was loaded, which was causing a considerable amount of memory to remain allocated when it was no longer needed, for the life of the application. However, I believe some of those issues have also been addressed by this point.

Aside from general "I don't trust it" sentiment, :) are there any current issues that continue make Joda Time a poor choice for dealing with dates on Android?

spaaarky21
  • 6,524
  • 7
  • 52
  • 65
  • There is an [Android port](https://github.com/dlew/joda-time-android) of JodaTime. Don't know if it is really necessary, though. – OneCricketeer Aug 09 '16 at 18:34

1 Answers1

1

The problem still exists. The issue was the library's usage of ClassLoader.getResourceAsStream. This issue has NOT been fixed as of Android 6.0.1_r11 - see here for details.

As of this writing, the default ZoneInfoProvider still uses this mechanism - from the the current tip of master:

private InputStream openResource(String name) throws IOException {
    InputStream in;
    if (iFileDir != null) {
        in = new FileInputStream(new File(iFileDir, name));
    } else {
        final String path = iResourcePath.concat(name);
        in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
            public InputStream run() {
                if (iLoader != null) {
                    return iLoader.getResourceAsStream(path);
                } else {
                    return ClassLoader.getSystemResourceAsStream(path);
                }
            }
        });
        if (in == null) {
            StringBuilder buf = new StringBuilder(40)
                .append("Resource not found: \"")
                .append(path)
                .append("\" ClassLoader: ")
                .append(iLoader != null ? iLoader.toString() : "system");
            throw new IOException(buf.toString());
        }
    }
    return in;
}

In a few jumps, you can trace the usage of this problem method back to DateTimeZone.getProvider here:

public static Provider getProvider() {
    Provider provider = cProvider.get();
    if (provider == null) {
        provider = getDefaultProvider();
        if (!cProvider.compareAndSet(null, provider)) {
            provider = cProvider.get();
        }
    }
    return provider;
}

getDefaultProvider() will create the problematic ZoneInfoProvider class; so, if you use JodaTime with the default Provider, you will still have the same performance issues.

kenny_k
  • 3,831
  • 5
  • 30
  • 41