diff --git a/api/src/main/java/jakarta/enterprise/util/AnnotationLiteral.java b/api/src/main/java/jakarta/enterprise/util/AnnotationLiteral.java index 78810a34c..56a549485 100644 --- a/api/src/main/java/jakarta/enterprise/util/AnnotationLiteral.java +++ b/api/src/main/java/jakarta/enterprise/util/AnnotationLiteral.java @@ -74,11 +74,6 @@ public abstract class AnnotationLiteral implements Annotat private transient Integer cachedHashCode; protected AnnotationLiteral() { - if (getMembers().length == 0) { - this.cachedHashCode = 0; - } else { - this.cachedHashCode = null; - } } private Method[] getMembers() { @@ -88,6 +83,11 @@ private Method[] getMembers() { throw new RuntimeException(getClass() + " does not implement the annotation type with members " + annotationType().getName()); } + if (members.length == 0) { + this.cachedHashCode = 0; + } else { + this.cachedHashCode = null; + } } return members; } @@ -183,7 +183,7 @@ public String toString() { } private void appendInBraces(StringBuilder buf, String s) { - buf.append('{').append(s.substring(1, s.length() - 1)).append('}'); + buf.append('{').append(s, 1, s.length() - 1).append('}'); } @Override @@ -240,11 +240,12 @@ public boolean equals(Object other) { @Override public int hashCode() { + Method[] members = getMembers(); // init cachedHashCode if (cachedHashCode != null) { return cachedHashCode; } else { int hashCode = 0; - for (Method member : getMembers()) { + for (Method member : members) { int memberNameHashCode = 127 * member.getName().hashCode(); Object value = getMemberValue(member, this); int memberValueHashCode;