This is an automated email from the ASF dual-hosted git repository.

jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git


The following commit(s) were added to refs/heads/master by this push:
     new 1d77feda37 [SEDONA-677] Fix kryo deserialization of null envelopes 
(#1687)
1d77feda37 is described below

commit 1d77feda37d4314fcdae9a9b199d1349f0855d5c
Author: Kristin Cowalcijk <[email protected]>
AuthorDate: Thu Nov 21 10:57:05 2024 +0800

    [SEDONA-677] Fix kryo deserialization of null envelopes (#1687)
---
 .../sedona/common/geometrySerde/GeometrySerde.java |  7 ++-
 .../common/geometrySerde/EnvelopeSerdeTest.java    | 55 ++++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git 
a/common/src/main/java/org/apache/sedona/common/geometrySerde/GeometrySerde.java
 
b/common/src/main/java/org/apache/sedona/common/geometrySerde/GeometrySerde.java
index 1df9164a66..7b7399cdb8 100644
--- 
a/common/src/main/java/org/apache/sedona/common/geometrySerde/GeometrySerde.java
+++ 
b/common/src/main/java/org/apache/sedona/common/geometrySerde/GeometrySerde.java
@@ -111,7 +111,12 @@ public class GeometrySerde extends Serializer implements 
Serializable {
           double xMax = input.readDouble();
           double yMin = input.readDouble();
           double yMax = input.readDouble();
-          return new Envelope(xMin, xMax, yMin, yMax);
+          if (xMin <= xMax) {
+            return new Envelope(xMin, xMax, yMin, yMax);
+          } else {
+            // Null envelope cannot be constructed using Envelope(xMin, xMax, 
yMin, yMax)
+            return new Envelope();
+          }
         }
       default:
         throw new UnsupportedOperationException(
diff --git 
a/common/src/test/java/org/apache/sedona/common/geometrySerde/EnvelopeSerdeTest.java
 
b/common/src/test/java/org/apache/sedona/common/geometrySerde/EnvelopeSerdeTest.java
new file mode 100644
index 0000000000..82a01f99c4
--- /dev/null
+++ 
b/common/src/test/java/org/apache/sedona/common/geometrySerde/EnvelopeSerdeTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sedona.common.geometrySerde;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+import org.junit.Assert;
+import org.junit.Test;
+import org.locationtech.jts.geom.Envelope;
+
+public class EnvelopeSerdeTest {
+  private final Kryo kryo = new Kryo();
+  private final GeometrySerde geometrySerde = new GeometrySerde();
+
+  private void testRoundTrip(Envelope env) {
+    Output out = new Output(1024);
+    geometrySerde.write(kryo, out, env);
+    try (Input in = new Input(out.toBytes())) {
+      Envelope env2 = (Envelope) geometrySerde.read(kryo, in, Envelope.class);
+      Assert.assertEquals(env, env2);
+    }
+  }
+
+  @Test
+  public void testEnvelope() {
+    testRoundTrip(new Envelope(10, 20, 30, 40));
+  }
+
+  @Test
+  public void testSinglePointEnvelope() {
+    testRoundTrip(new Envelope(10, 10, 10, 10));
+  }
+
+  @Test
+  public void testNullEnvelope() {
+    testRoundTrip(new Envelope());
+  }
+}

Reply via email to