Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add equality comparison for ArchaiusType #700

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

gavinbunney
Copy link
Contributor

This PR adds equality methods for the ArchaiusType class to ensure keyAndType references are reused correctly within the DefaultPropertyFactory.

The computeIfAbsent check for existing property references uses the type equality within keyAndType 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.

@sullis
Copy link

sullis commented Feb 5, 2024

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();
    }

}

@rgallardo-netflix
Copy link
Contributor

@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.

@rgallardo-netflix rgallardo-netflix merged commit 2446891 into 2.x Feb 5, 2024
5 checks passed
@gavinbunney gavinbunney deleted the gavin/archaiustype-equality branch February 6, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants