Skip to content

Commit 9d14481

Browse files
authored
Fix generating annotation metadata for enum constants (#11573)
1 parent 683c615 commit 9d14481

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

core-processor/src/main/java/io/micronaut/inject/beans/visitor/BeanIntrospectionWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ private ExpressionDef newEnumConstantRef(EnumConstantElement enumConstantElement
517517
// 2: push enum name
518518
ExpressionDef.constant(enumConstantElement.getName()),
519519
// 3: annotation metadata
520-
enumConstantElement.getAnnotationMetadata() == null ? (
520+
enumConstantElement.getAnnotationMetadata() == null || enumConstantElement.getAnnotationMetadata().isEmpty() ? (
521521
ClassTypeDef.of(AnnotationMetadata.class).getStaticField("EMPTY_METADATA", TypeDef.of(AnnotationMetadata.class))
522522
) : getAnnotationMetadataExpression(enumConstantElement.getAnnotationMetadata(), loadClassValueExpressionFn)
523523
);

inject-java-test/src/test/groovy/io/micronaut/inject/visitor/beans/BeanIntrospectionSpec.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4146,7 +4146,8 @@ public enum Test {
41464146
@JsonProperty("Y")
41474147
B(1),
41484148
@JsonProperty("Z")
4149-
C(2);
4149+
C(2),
4150+
D(3);
41504151
private final int number;
41514152
Test(int number) {
41524153
this.number = number;
@@ -4181,6 +4182,7 @@ public enum Test {
41814182
enumIntrospection.constants[0].stringValue(JsonProperty).get() == "X"
41824183
enumIntrospection.constants[1].stringValue(JsonProperty).get() == "Y"
41834184
enumIntrospection.constants[2].stringValue(JsonProperty).get() == "Z"
4185+
enumIntrospection.constants[3].stringValue(JsonProperty).isEmpty()
41844186
}
41854187

41864188
void "test enum bean properties with custom getter"() {

0 commit comments

Comments
 (0)