整数オーバーフローを引き起こすバグがあり、間違った (負の) タイムスタンプがデータベースに書き込まれました。コードは修正済みですが、間違ったデータも修正したいです。
間違った結果を取得して Integer.MAX_VALUE を追加することもできると思いましたが、うまくいかないようで、高い値が残っていました。以下のコード スニペットにoffset
値がありますが、入力値は保存されません。
次のコードはバグを再現します。
@Test
public void testArexxConversion()
{
// The input values represent seconds since midnight, Jan 1, 2000 UTC
final int sample = 361450072; // A sample input value drawn from production
// I use the offset from the UNIX epoch to convert the vakue to UNIX seconds
final int offset = 946684800; // midnight, Jan 01 2000 UTC in UNIX seconds
// This was the buggy line in my code, the assertion will fail
long result = (sample + offset) * 1000;
// Prints 'Result is negative: -1830153280'
Assert.assertTrue(result > 0, String.format("Result is negative: %d", result));
// This is for comparison
Date dt = new Date(offset * 1000);
Assert.assertEquals(dt.getTime() + sample * 1000, result);
}