Detect multiple classes with same fully qualified name

Viewed 128

My Java project with multiple subprojects is using the Immutables library for value objects.

package foo.bar;

import org.immutables.value.Value;

public class MyContainerClass {

    @Value.Immutable
    public interface Baz {
        String name();
    }

    // more interfaces here
}

This generates a class in the same package named foo.bar.ImmutableBaz implementing the Baz interface. Another subproject recently declared another interface of the same name in the same package foo.bar, but a different container class. This resulted in the generation of a second foo.bar.ImmutableBaz class. Both classes inadvertently ended up with the same fully qualified name which caused issues at runtime with the wrong class being loaded.

How would I best detect these naming clashes, for example in a test or as part of a CI pipeline?

I know I can specify the target package with Immutables, but I'm looking to detect and avoid unintentional clashes.

0 Answers
Related