// Calendar fails when turning negative to positive (zero), not // positive to negative with nextStamp. If a negative value was set to // nextStamp, it would fail even with the fix. So, there's no way to // reproduce the symptom in a short time -- at leaset it would take a // couple of hours even if we started with Integer.MAX_VALUE. So, this // test case just checks that set() calls don't cause any nextStamp // overflow.
publicclass StampOverflow { publicstaticvoid main(String[] args) throws IllegalAccessException { // Get a Field for "nextStamp".
Field nextstamp = null; try {
nextstamp = Calendar.class.getDeclaredField("nextStamp");
} catch (NoSuchFieldException e) { thrownew RuntimeException("implementation changed?", e);
}
nextstamp.setAccessible(true);
Calendar cal = new GregorianCalendar(); int initialValue = nextstamp.getInt(cal); // Set nextStamp to a very large number
nextstamp.setInt(cal, Integer.MAX_VALUE - 100);
for (int i = 0; i < 1000; i++) {
invoke(cal); int stampValue = nextstamp.getInt(cal); // nextStamp must not be less than initialValue. if (stampValue < initialValue) { thrownew RuntimeException("invalid nextStamp: " + stampValue);
}
}
}
staticvoid invoke(Calendar cal) {
cal.clear();
cal.set(2000, NOVEMBER, 2, 0, 0, 0); int y = cal.get(YEAR); int m = cal.get(MONTH); int d = cal.get(DAY_OF_MONTH); if (y != 2000 || m != NOVEMBER || d != 2) { thrownew RuntimeException("wrong date produced ("
+ y + "/" + (m+1) + "/" + d + ")");
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.