Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

[java-core] Timestamp.of(java.sql.Timestamp) is one second late for a time less than a second before the epoch

Offen Anfängerfreundlich
#14,636 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
java
Bereich
backend

Rechercherichtung

Beginne in sdk-platform-java/java-core/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java bei der im Issue verlinkten Methode Timestamp.of(java.sql.Timestamp). Vergleiche ihre Sekundenberechnung mit Timestamp.of(Date) und den Reproduzierwerten rund um die Epoche. Fertig ist die Arbeit, wenn die Konvertierung für die negativen Fälle mit Sekundenbruchteilen korrekt ist und mit Timestamp.of(Date) übereinstimmt; das Issue nennt keine Testdatei.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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:

https://github.com/googleapis/google-cloud-java/blob/9de611fe5633e9f43c6081754c834cabcd0317bb/sdk-platform-java/java-core/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java#L123-L136

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.

Vorherrschende Sprache
Java
Sterne
2.1k
Forks
1.2k
Ø Merge
2 T. 21 Std.
Gemergte PRs (30 T.)
139

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus googleapis/google-cloud-java

Alle Issues in googleapis/google-cloud-java

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.