[java-firestore] UserDataConverter encodes a pre-epoch Date with negative nanos, so the write is refused
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
Hướng nghiên cứu
Bắt đầu tại java-firestore/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java, ở phần chuyển đổi encodeValue được liên kết trong issue, và so sánh với com.google.cloud.Timestamp.of(Date). Thêm hoặc tìm một kiểm thử hồi quy cho các ngày trước Unix epoch, chẳng hạn new Date(-1500), rồi xác minh rằng timestamp được mã hóa có nanos không âm. Hoàn tất khi có thể ghi ngày mà không gặp lỗi timestamp không hợp lệ của emulator; issue không nêu tên tệp kiểm thử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Issue Details
UserDataConverter.encodeValue converts a java.util.Date into a Timestamp proto by truncating the milliseconds toward zero for seconds and putting the remainder in nanos:
For a date before the epoch that is not a whole second, the remainder is negative, so the proto carries a negative nanos, which google.protobuf.Timestamp does not allow (nanos must be in [0, 999999999]). new Date(-1500) is sent as seconds: -1, nanos: -500000000, and new Date(-1) as nanos: -1000000. The emulator refuses the write with INVALID_ARGUMENT: Timestamp nanos exceeds limit for field., so a valid Date cannot be written. The same conversion serves every value the library encodes, so a Date field of a POJO and a query filter or cursor on a Date should be affected the same way (not tried).
com.google.cloud.Timestamp.of(Date) already does this conversion correctly (it borrows a second when the remainder is negative), so encodeValue could use it, or Math.floorDiv and Math.floorMod.
Found while building an Apache Flink sink 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
- Firestore emulator:
gcr.io/google.com/cloudsdktool/google-cloud-cli:588.0.0-emulators(Native mode, Standard edition); 587.0.0 answers the same
The refusal was measured on the emulator only, not against a production database.
Dependencies
- Libraries-Bom: 26.90.0
- google-cloud-firestore 3.49.0
- Gax: 2.87.0
- Auth: 1.54.0
The affected code is identical in 3.49.0 and on main.
Reproducer
Run with FIRESTORE_EMULATOR_HOST set.
package repro;
import com.google.cloud.firestore.DocumentReference;
import com.google.cloud.firestore.Firestore;
import com.google.cloud.firestore.FirestoreOptions;
import java.util.Date;
import java.util.Map;
public class PreEpochDate {
public static void main(String[] args) throws Exception {
Firestore db = FirestoreOptions.newBuilder().setProjectId("demo").build().getService();
for (long millis : new long[] {-1000, -1500, -1}) {
DocumentReference doc = db.collection("dates").document("d" + millis);
try {
doc.set(Map.of("t", new Date(millis))).get();
System.out.println(millis + " ms: written, read back as " + doc.get().get().getTimestamp("t"));
} catch (Exception e) {
System.out.println(millis + " ms: " + e.getCause());
}
}
System.exit(0);
}
}
Logs and Stack Trace
-1000 ms: written, read back as 1969-12-31T23:59:59Z
-1500 ms: com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Timestamp nanos exceeds limit for field.
-1 ms: com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Timestamp nanos exceeds limit for field.
Behavior
Deterministic: any Date before the epoch whose millisecond value is not a multiple of 1000.
- Ngôn ngữ chính
- Java
- Star
- 2.1k
- Fork
- 1.2k
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 126
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của googleapis/google-cloud-java
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
googleapis/google-cloud-java#14636 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[java-firestore] UserDataConverter throws IndexOutOfBoundsException on an empty __binary__ valueĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
googleapis/google-cloud-java#14634 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
googleapis/google-cloud-java#14579 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[java-firestore] CustomClassMapper.convertBigDecimal calls .abs() on Double, unintentionally flipping negative values to positiveCó thể đã có người làm @wu-hui đã nhận 14 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
googleapis/google-cloud-java#14533 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Github CI failing when trying to install xmllintCó thể đã có người làm @blakeli0 đã nhận 50 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
googleapis/google-cloud-java#14132 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của googleapis/google-cloud-java
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
wildfly/wildfly-launcher#99 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
traccar/traccar#6076 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Flight SQL JDBC parses boolean properties case-sensitively, silently disabling TLS for useEncryption=TRUECó thể đã có người làm @Arawoof06 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
apache/arrow-java#1357 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Demo alert imports accept empty and oversized rule documentsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
apache/rocketmq-dashboard#6610 ·
Maintainer thường phản hồi trong vòng 3 ngày