[java-firestore] UserDataConverter encodes a pre-epoch Date with negative nanos, so the write is refused
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 75/100
Línea de trabajo
Empieza en java-firestore/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java, en la conversión encodeValue enlazada en el issue, y compárala con com.google.cloud.Timestamp.of(Date). Añade o localiza una prueba de regresión para fechas anteriores a la época Unix, como new Date(-1500), y verifica que el timestamp codificado tenga nanos no negativos. El trabajo estará terminado cuando se pueda escribir la fecha sin el error del emulador por un timestamp no válido; el issue no indica ningún archivo de prueba.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Java
- Estrellas
- 2.1k
- Forks
- 1.2k
- Merge medio
- 2 d 21 h
- PR fusionados (30 d)
- 139
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de googleapis/google-cloud-java
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
googleapis/google-cloud-java#14636 ·
Los mantenedores suelen responder en 1 día
-
[java-firestore] UserDataConverter throws IndexOutOfBoundsException on an empty __binary__ valueAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
googleapis/google-cloud-java#14634 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
googleapis/google-cloud-java#14579 ·
Los mantenedores suelen responder en 1 día
-
[java-firestore] CustomClassMapper.convertBigDecimal calls .abs() on Double, unintentionally flipping negative values to positivePosiblemente ocupada @wu-hui la tomó hace 15 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
googleapis/google-cloud-java#14533 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Github CI failing when trying to install xmllintPosiblemente ocupada @blakeli0 la tomó hace 50 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
googleapis/google-cloud-java#14132 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de googleapis/google-cloud-java
Issues similares
-
RRateLimiter acquire methods accept negative permits and raise available permits above the rate.Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 4 días
-
README 中的代码语言数量与当前目录不一致Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
krahets/hello-algo#1993 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
NationalSecurityAgency/ghidra#9884 ·
Los mantenedores suelen responder en 2 días
-
Status: Pending Review Type: Feature Request
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
OpenRefine/OpenRefine#8019 ·
Los mantenedores suelen responder en 1 día
-
`timer` rule rejects dates the engine acceptsPosiblemente ocupada @MFA-G la tomó hoy. Abiertobug ready
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
camunda/bpmnlint-plugin-camunda-compat#281 · 3 comentarios ·
Los mantenedores suelen responder en 1 día