[java-core] Timestamp.of(java.sql.Timestamp) is one second late for a time less than a second before the epoch
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
sdk-platform-java/java-core/google-cloud-core/src/main/java/com/google/cloud/Timestamp.javaで、issueにリンクされているTimestamp.of(java.sql.Timestamp)メソッドを確認します。秒の計算をTimestamp.of(Date)およびエポック前後の再現用の値と比較します。負の秒未満のケースで変換が正しく、Timestamp.of(Date)と一致すれば完了です。issueではテストファイルは指定されていません。
索引モデルが issue の本文から書いたものです。
説明
Issue Details
Timestamp.of(java.sql.Timestamp) returns a time one second late for a java.sql.Timestamp between one second before the epoch and the epoch:
The method takes the whole seconds as getTime() / 1000 and borrows a second only when that quotient is negative. For getTime() in (-1000, 0) the quotient is 0, so no second is borrowed, while getNanos() holds the positive fraction of the second before the epoch. new java.sql.Timestamp(-500) (1969-12-31T23:59:59.500Z) becomes 1970-01-01T00:00:00.500Z. The borrow was added for googleapis/java-core#159, whose example (-1001) has a nonzero quotient, so this range was left out. Math.floorDiv(getTime(), 1000) gives the right seconds for every value, as Timestamp.of(Date) already does through ofTimeMicroseconds.
Found while building an Apache Flink connector on google-cloud-firestore (flink-gcp/flink-connector-gcp).
Environment
- OS Type and Version: macOS 26 (arm64)
- Java Version and JDK Vendor: Eclipse Temurin 17.0.20
Dependencies
- Libraries-Bom: 26.90.0
- google-cloud-core 2.77.0
The affected code is identical in 2.77.0 and on main.
Reproducer
package repro;
import com.google.cloud.Timestamp;
public class SqlTimestampProbe {
public static void main(String[] args) {
for (long millis : new long[] {-1500, -500, -1, 0, 500}) {
java.sql.Timestamp sql = new java.sql.Timestamp(millis);
System.out.println(millis + " ms (" + sql.toInstant() + "): Timestamp.of(sql) = " + Timestamp.of(sql)
+ ", Timestamp.of(Date) = " + Timestamp.of(new java.util.Date(millis)));
}
}
}
Logs and Stack Trace
-1500 ms (1969-12-31T23:59:58.500Z): Timestamp.of(sql) = 1969-12-31T23:59:58.500000000Z, Timestamp.of(Date) = 1969-12-31T23:59:58.500000000Z
-500 ms (1969-12-31T23:59:59.500Z): Timestamp.of(sql) = 1970-01-01T00:00:00.500000000Z, Timestamp.of(Date) = 1969-12-31T23:59:59.500000000Z
-1 ms (1969-12-31T23:59:59.999Z): Timestamp.of(sql) = 1970-01-01T00:00:00.999000000Z, Timestamp.of(Date) = 1969-12-31T23:59:59.999000000Z
0 ms (1970-01-01T00:00:00Z): Timestamp.of(sql) = 1970-01-01T00:00:00Z, Timestamp.of(Date) = 1970-01-01T00:00:00Z
500 ms (1970-01-01T00:00:00.500Z): Timestamp.of(sql) = 1970-01-01T00:00:00.500000000Z, Timestamp.of(Date) = 1970-01-01T00:00:00.500000000Z
Behavior
Deterministic: any java.sql.Timestamp with -1000 < getTime() < 0.
- 主要言語
- Java
- スター
- 2.1k
- フォーク
- 1.2k
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 139
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
googleapis/google-cloud-java のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
googleapis/google-cloud-java#14635 ·
メンテナーはふだん 1 日以内に返信
-
[java-firestore] UserDataConverter throws IndexOutOfBoundsException on an empty __binary__ valueオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
googleapis/google-cloud-java#14634 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
googleapis/google-cloud-java#14579 ·
メンテナーはふだん 1 日以内に返信
-
[java-firestore] CustomClassMapper.convertBigDecimal calls .abs() on Double, unintentionally flipping negative values to positive対応中かも @wu-hui が 16 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
googleapis/google-cloud-java#14533 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Github CI failing when trying to install xmllint対応中かも @blakeli0 が 51 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
googleapis/google-cloud-java#14132 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
googleapis/google-cloud-java の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
MCModderAnchor/TACZ#758 ·
-
agent-java community triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
elastic/apm-agent-java#4594 ·
メンテナーはふだん 1 日以内に返信
-
area/plugin good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
kestra-io/plugin-soda#137 ·
-
area/plugin good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
kestra-io/plugin-aws#816 ·
メンテナーはふだん 2 日以内に返信
-
area/plugin good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
kestra-io/plugin-kestra#200 ·
メンテナーはふだん 1 日以内に返信