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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ The release run heads these entries with the version and opens a fresh

## Unreleased

- Java `Measure`, `DrawingPath` and `DrawingTransform` equality now agrees with
hashing for signed zero and is reflexive for NaN, following `Double` semantics.

- Java bindings release native handles on failed allocations, avoid pinned-array
leaks, and check array sizes before passing them to the JVM.

Expand Down
8 changes: 4 additions & 4 deletions jni/java/app/opendocument/core/DrawingPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public DrawingPath(String data, double x, double y, double width, double height)
public boolean equals(Object other) {
return other instanceof DrawingPath path
&& data.equals(path.data)
&& x == path.x
&& y == path.y
&& width == path.width
&& height == path.height;
&& Double.compare(x, path.x) == 0
&& Double.compare(y, path.y) == 0
&& Double.compare(width, path.width) == 0
&& Double.compare(height, path.height) == 0;
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions jni/java/app/opendocument/core/DrawingTransform.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public DrawingTransform(double a, double b, double c, double d, Measure e, Measu
@Override
public boolean equals(Object other) {
return other instanceof DrawingTransform transform
&& a == transform.a
&& b == transform.b
&& c == transform.c
&& d == transform.d
&& Double.compare(a, transform.a) == 0
&& Double.compare(b, transform.b) == 0
&& Double.compare(c, transform.c) == 0
&& Double.compare(d, transform.d) == 0
&& e.equals(transform.e)
&& f.equals(transform.f);
}
Expand Down
2 changes: 1 addition & 1 deletion jni/java/app/opendocument/core/Measure.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public Measure(double magnitude, String unit) {
@Override
public boolean equals(Object other) {
return other instanceof Measure measure
&& magnitude == measure.magnitude
&& Double.compare(magnitude, measure.magnitude) == 0
&& unit.equals(measure.unit);
}

Expand Down
22 changes: 22 additions & 0 deletions jni/tests/app/opendocument/core/MetaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.DoubleFunction;
import org.junit.jupiter.api.Test;

class MetaTest {
Expand Down Expand Up @@ -95,6 +96,27 @@ void capabilitiesByFileType() {
assertFalse(pdf.colorScheme);
}

@Test
void floatingValuesHaveConsistentEqualityAndHashes() {
List<DoubleFunction<Object>> values = List.of(
value -> new Measure(value, "pt"),
value -> new DrawingPath("M0 0", value, value, value, value),
value -> new DrawingTransform(value, value, value, value,
new Measure(0, "pt"), new Measure(0, "pt")));
for (DoubleFunction<Object> value : values) {
Object nan = value.apply(Double.NaN);
Object sameNan = value.apply(Double.NaN);
assertTrue(nan.equals(nan));
assertEquals(nan, sameNan);
assertEquals(nan.hashCode(), sameNan.hashCode());
Object positiveZero = value.apply(0.0);
Object negativeZero = value.apply(-0.0);
assertFalse(positiveZero.equals(negativeZero));
assertEquals(positiveZero, value.apply(0.0));
assertEquals(positiveZero.hashCode(), value.apply(0.0).hashCode());
}
}

@Test
void tablePosition() {
assertEquals(0, TablePosition.toColumnNum("A"));
Expand Down
Loading