Skip to content

Commit

Permalink
Make AnnotationLiteral lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher authored and Ladicek committed Aug 10, 2021
1 parent 483ad63 commit c43240d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions api/src/main/java/jakarta/enterprise/util/AnnotationLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ public abstract class AnnotationLiteral<T extends Annotation> implements Annotat
private transient Integer cachedHashCode;

protected AnnotationLiteral() {
if (getMembers().length == 0) {
this.cachedHashCode = 0;
} else {
this.cachedHashCode = null;
}
}

private Method[] getMembers() {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c43240d

Please sign in to comment.