diff --git a/core/src/main/java/org/jboss/jandex/ClassInfo.java b/core/src/main/java/org/jboss/jandex/ClassInfo.java index 61c965d1..ac64cfa0 100644 --- a/core/src/main/java/org/jboss/jandex/ClassInfo.java +++ b/core/src/main/java/org/jboss/jandex/ClassInfo.java @@ -654,7 +654,7 @@ public final Map> annotationsMap() { } final void setAnnotations(Map> annotations) { - this.annotations = annotations; + this.annotations = Utils.minimize(annotations); } /** diff --git a/core/src/main/java/org/jboss/jandex/Utils.java b/core/src/main/java/org/jboss/jandex/Utils.java index 262e9280..4f5211d5 100644 --- a/core/src/main/java/org/jboss/jandex/Utils.java +++ b/core/src/main/java/org/jboss/jandex/Utils.java @@ -61,8 +61,19 @@ static Map unfold(Map> map, Class listElementType) return result; } + static Map minimize(Map map) { + if (map.isEmpty()) { + return Collections.emptyMap(); + } else if (map.size() == 1) { + Map.Entry entry = map.entrySet().iterator().next(); + return Collections.singletonMap(entry.getKey(), entry.getValue()); + } else { + return map; + } + } + static List listOfCapacity(int capacity) { - return capacity > 0 ? new ArrayList(capacity) : Collections. emptyList(); + return capacity > 0 ? new ArrayList<>(capacity) : Collections.emptyList(); } static final class ReusableBufferedDataInputStream extends DataInputStream {