Closed gavinbunney closed 9 months ago
Suggested enhancement: use the equalsverifier library to confirm the behavior of the equals method.
Add the library to build.gradle:
testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.+'
And add a unit test:
package com.netflix.archaius.api;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.Test;
public class EqualsVerificationTest {
@Test
public void verifyArchaiusType() {
verifyEquals(ArchaiusType.class);
}
private static void verifyEquals(Class<?> clazz) {
EqualsVerifier.forClass(clazz)
.usingGetClass()
.verify();
}
}
@sullis, I like that idea but I think I'd rather do it separately as a bigger change adding verifications to every class with an equals
method. I did test things out locally and the PR passes as it is now.
This PR adds equality methods for the
ArchaiusType
class to ensurekeyAndType
references are reused correctly within theDefaultPropertyFactory
.The
computeIfAbsent
check for existing property references uses thetype
equality withinkeyAndType
to see if a reference to a property already exists, otherwise it adds it to the property ref map.This can cause an explosion of allocations where the same property key and type are supplied, but as the type itself is constructed on every fetch (
new ArchaiusType
), the default java object equals methods always return false, so a new reference is added to the property factory.