Skip to content

Commit d522664

Browse files
committed
fix(core): new dev svc mode reflective equals for constants
Signed-off-by: Michal Vavřík <michal.vavrik@aol.com>
1 parent 4ec5553 commit d522664

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

core/runtime/src/main/java/io/quarkus/devservices/crossclassloader/runtime/ComparableDevServicesConfig.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ private static boolean reflectiveEquals(Object config, Object otherConfig) {
5252
}
5353

5454
try {
55+
boolean foundConfigInterface = false;
5556
while (clazz != null) {
5657
// Get all interfaces implemented by the class
5758
for (Class<?> iface : clazz.getInterfaces()) {
5859
// Check if the interface is a config one
5960

6061
if (isConfigInterface(iface)) {
62+
if (!foundConfigInterface) {
63+
foundConfigInterface = true;
64+
}
6165
// For each method in the interface
6266
// In the future, if we wanted some methods to be ignored, we could use a marker annotation in the config object
6367
for (Method method : iface.getMethods()) {
@@ -83,7 +87,10 @@ private static boolean reflectiveEquals(Object config, Object otherConfig) {
8387
otherClazz = otherClazz.getSuperclass();
8488

8589
}
86-
return true;
90+
if (foundConfigInterface) {
91+
return true;
92+
}
93+
return config.equals(otherConfig);
8794
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException ex) {
8895
throw new RuntimeException(ex);
8996
}

core/runtime/src/test/java/io/quarkus/devservices/crossclassloader/runtime/ComparableDevServicesConfigTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ public void nullUuidIsHandled() {
9696
new ComparableDevServicesConfig(null, null, null, config).hashCode());
9797
}
9898

99+
@Test
100+
public void sameConstantsAreEqual() {
101+
var a1 = new ComparableDevServicesConfig(uuid, null, null, "1");
102+
var a2 = new ComparableDevServicesConfig(uuid, null, null, "1");
103+
assertEquals(a1, a2);
104+
}
105+
106+
@Test
107+
public void differentConstantsAreNotEqual() {
108+
var a1 = new ComparableDevServicesConfig(uuid, null, null, "2");
109+
var a2 = new ComparableDevServicesConfig(uuid, null, null, "1");
110+
assertNotEquals(a1, a2);
111+
}
112+
99113
@ConfigGroup
100114
interface CI {
101115

0 commit comments

Comments
 (0)