From 5b9ca2933f1accd3232ee3b10fe20f018b4fe1e1 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Thu, 21 Apr 2022 09:53:06 +1200 Subject: [PATCH] Fix: CompareTo when discriminatorString is null - Fix for regression introduced by #2646 in version 13.3.1 - Replaces PR #2664 --- .../deploy/parse/DeployInheritInfo.java | 10 +++------ .../deploy/parse/DeployInheritInfoTest.java | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 ebean-core/src/test/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfoTest.java diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java index ef92648fb..3df70b406 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java @@ -259,15 +259,11 @@ public final class DeployInheritInfo implements Comparable { } @Override - public int compareTo(DeployInheritInfo o) { - if (o == this || o.discriminatorStringValue == null && discriminatorStringValue == null) { + public int compareTo(DeployInheritInfo other) { + if (other == this) { return 0; - } else if (o.discriminatorStringValue == null) { - return 1; - } else if (discriminatorStringValue == null) { - return -1; } else { - return discriminatorStringValue.compareTo(o.discriminatorStringValue); + return type.getName().compareTo(other.type.getName()); } } diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfoTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfoTest.java new file mode 100644 index 000000000..d42825ea9 --- /dev/null +++ b/ebean-core/src/test/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfoTest.java @@ -0,0 +1,21 @@ +package io.ebeaninternal.server.deploy.parse; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class DeployInheritInfoTest { + + @Test + void addChild_when_DiscriminatorValueIsNull() { + DeployInheritInfo root = new DeployInheritInfo(Object.class); + root.addChild(new DeployInheritInfo(Integer.class)); // DiscriminatorValue is null + root.addChild(new DeployInheritInfo(Short.class)); // DiscriminatorValue is null + + DeployInheritInfo c2 = new DeployInheritInfo(Long.class); + c2.setDiscriminatorValue("c2"); + root.addChild(c2); + + assertThat(root.children()).hasSize(3); + } +}