Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion firebase-firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Unreleased
* [feature] Add support for disjunctions in queries (`OR` queries).
* [fixed] Fixed stack overflow caused by deeply nested server timestamps (#4702).

# 24.4.4
* [changed] Relaxed certain query validations performed by the SDK (#4231).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ public static Value valueOf(Timestamp localWriteTime, @Nullable Value previousVa
.putFields(TYPE_KEY, encodedType)
.putFields(LOCAL_WRITE_TIME_KEY, encodeWriteTime);

Value actualPreviousValue = previousValue == null ? null : getPreviousValue(previousValue);
if (actualPreviousValue != null) {
mapRepresentation.putFields(PREVIOUS_VALUE_KEY, actualPreviousValue);
if (previousValue != null) {
mapRepresentation.putFields(PREVIOUS_VALUE_KEY, previousValue);
}

return Value.newBuilder().setMapValue(mapRepresentation).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,12 @@
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

import com.google.firebase.Timestamp;
import com.google.firebase.firestore.FieldValue;
import com.google.firebase.firestore.core.Query;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.FieldIndex;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.ObjectValue;
import com.google.firebase.firestore.model.ServerTimestamps;
import com.google.firebase.firestore.model.mutation.FieldMask;
import com.google.firebase.firestore.model.mutation.FieldTransform;
import com.google.firebase.firestore.model.mutation.PatchMutation;
import com.google.firebase.firestore.model.mutation.Precondition;
import com.google.firebase.firestore.model.mutation.ServerTimestampOperation;
import com.google.firestore.v1.Value;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
Expand Down Expand Up @@ -307,60 +290,4 @@ public void testIndexesServerTimestamps() {
assertOverlayTypes(keyMap("coll/a", CountingQueryEngine.OverlayType.Set));
assertQueryReturned("coll/a");
}

@Test
public void testDeeplyNestedServerTimestamps() {
Timestamp timestamp = Timestamp.now();
Value initialServerTimestamp = ServerTimestamps.valueOf(timestamp, null);
Map<String, Value> fields =
new HashMap<String, Value>() {
{
put("timestamp", ServerTimestamps.valueOf(timestamp, initialServerTimestamp));
}
};
FieldPath path = FieldPath.fromSingleSegment("timestamp");
FieldMask mask =
FieldMask.fromSet(
new HashSet<FieldPath>() {
{
add(path);
}
});
FieldTransform fieldTransform =
new FieldTransform(path, ServerTimestampOperation.getInstance());
List<FieldTransform> fieldTransforms =
new ArrayList<FieldTransform>() {
{
add(fieldTransform);
}
};
AtomicReference<Throwable> error = new AtomicReference<>();
Thread thread =
new Thread(
Thread.currentThread().getThreadGroup(),
() -> {
try {
for (int i = 0; i < 1000; ++i) {
writeMutation(
new PatchMutation(
DocumentKey.fromPathString("some/object/for/test"),
ObjectValue.fromMap(fields),
mask,
Precondition.NONE,
fieldTransforms));
}
} catch (Throwable e) {
error.set(e);
}
},
"test",
1024 * 1024);
try {
thread.start();
thread.join();
} catch (InterruptedException e) {
throw new AssertionError(e);
}
assertThat(error.get()).isNull();
}
}