From 89108b11bd4436751f6eaf3e02acc80fa9aae9bf Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 26 Nov 2024 20:42:17 +0100 Subject: [PATCH] Makes cache attempt unlabeled if labeled was not found --- .../instantiation/CachedValueProvider.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java index 6b1c53eab..55cae55d4 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java @@ -40,9 +40,13 @@ public boolean contains(Class type, String label) { @SuppressWarnings("unchecked") @Override public Optional> provide(TypeTag tag, Attributes attributes) { - Key key = Key.of(tag.getType(), attributes.label); - if (cache.containsKey(key)) { - return Optional.of((Tuple) cache.get(key)); + Key first = Key.of(tag.getType(), attributes.label); + if (cache.containsKey(first)) { + return Optional.of((Tuple) cache.get(first)); + } + Key second = first.removeLabel(); + if (cache.containsKey(second)) { + return Optional.of((Tuple) cache.get(second)); } return Optional.empty(); } @@ -61,6 +65,10 @@ public static Key of(Class type, String label) { return new Key(type, label); } + public Key removeLabel() { + return Key.of(type, null); + } + @Override public boolean equals(Object obj) { if (!(obj instanceof Key)) {