2

まず、長くなってすみません。おそらくすべてのコードは必要ありませんが、確認したかったのです。

第二に、私の実際の質問は、何か間違ったことをしているのですか、それとも joda-time ライブラリのバグですか?

joda-time (1.6.1) を使用して計算し、期間をフォーマットしようとしています。

私は現在 を使用してPeriodいますが、これは間違った選択かもしれません。もしそうなら教えてください。しかし、たとえそれが間違った選択であったとしても、私はこれが起こるべきではないと確信しています.

ミリ秒を使用して初期化していPeriodます(秒単位の期間に1000を掛けることにより)。を使用しているPeriodので、フォーマットして印刷できます。

long durationLong = durationSec * 1000;
Period duration = new Period(durationLong);

PeriodFormatter daysHoursMinutes = new PeriodFormatterBuilder()
    .appendHours()
    .appendSeparator(":")
    .appendMinutes()
    .appendSeparator(":")
    .appendSeconds()
    .toFormatter();

String formattedString = daysHoursMinutes.print(callDuration.normalizedStandard());

以下の例外が発生し、ソースを調べてループを確認しました。

Caused by: java.lang.StackOverflowError
    at java.util.Hashtable.get(Hashtable.java:274)
    at java.util.Properties.getProperty(Properties.java:177)
    at java.lang.System.getProperty(System.java:440)
    at java.lang.System.getProperty(System.java:412)
    at org.joda.time.DateTimeZone.getDefault(DateTimeZone.java:132)
    at org.joda.time.DateTimeZone.forID(DateTimeZone.java:190)
    at org.joda.time.DateTimeZone.getDefault(DateTimeZone.java:132)
    at org.joda.time.DateTimeZone.forID(DateTimeZone.java:190)

...snip (all the same)...

    at org.joda.time.DateTimeZone.getDefault(DateTimeZone.java:132)
    at org.joda.time.DateTimeZone.forID(DateTimeZone.java:190)
    at org.joda.time.DateTimeZone.getDefault(DateTimeZone.java:132)
    at org.joda.time.DateTimeZone.forID(Dat

期間(長期):

public Period(long duration) {
    super(duration, null, null);
}

スーパー (長い、PeriodType、年表):

protected BasePeriod(long duration, PeriodType type, Chronology chrono) {
    super();
    type = checkPeriodType(type);
    chrono = DateTimeUtils.getChronology(chrono);
    iType = type;
    iValues = chrono.get(this, duration);
}

DateTimeUtils.getChronology(クロノ):

public static final Chronology getChronology(Chronology chrono) {
    if (chrono == null) {
        return ISOChronology.getInstance();
    }
    return chrono;
}

ISOChronology.getInstance():

public static ISOChronology getInstance() {
    return getInstance(DateTimeZone.getDefault());
}

DateTimeZone.getDefault():

public static DateTimeZone getDefault() {
    DateTimeZone zone = cDefault;
    if (zone == null) {
        synchronized(DateTimeZone.class) {
            zone = cDefault;
            if (zone == null) {
                DateTimeZone temp = null;
                try {
                    try {
                        temp = forID(System.getProperty("user.timezone"));
                    } catch (RuntimeException ex) {
                        // ignored
                    }
                    if (temp == null) {
                        temp = forTimeZone(TimeZone.getDefault());
                    }
                } catch (IllegalArgumentException ex) {
                    // ignored
                }
                if (temp == null) {
                    temp = UTC;
                }
                cDefault = zone = temp;
            }
        }
    }
    return zone;
}

forID(String) は、ループを作成する getDefault() を呼び出します。

 public static DateTimeZone forID(String id) {
    if (id == null) {
        return getDefault();
    }
    if (id.equals("UTC")) {
        return DateTimeZone.UTC;
    }
    DateTimeZone zone = cProvider.getZone(id);
    if (zone != null) {
        return zone;
    }
    if (id.startsWith("+") || id.startsWith("-")) {
        int offset = parseOffset(id);
        if (offset == 0L) {
            return DateTimeZone.UTC;
        } else {
            id = printOffset(offset);
            return fixedOffsetZone(id, offset);
        }
    }
    throw new IllegalArgumentException("The datetime zone id is not recognised: " + id);
}
4

2 に答える 2

5

ループ部分は joda コードだけにあるので、これはバグだと思います。


トランクで修正され、V2.0 で使用できるようになります。


資力 :

于 2010-09-11T13:29:31.840 に答える
3

user.timezoneプロパティが設定されていると想定しているという点で、バグのようです。

この場合、それを回避する方法です - user.timezone が適切に設定されていることを確認してください。あなたがしなければならないのは残念です。

Joda Time は多くの場所で「null はデフォルトを意味する」を使用していますが、残念ながら私の見解ではそうです。私は通常、「null is invalid」を好みます。Noda Time (Joda Time の .NET への移植版) では、この種の多くのものを取り除こうとしています。また、そもそもデフォルトのタイム ゾーンが普及するのを防ごうとしています。

于 2010-09-11T13:30:02.997 に答える