Skip to content

Commit 8a293f5

Browse files
philwebbjhoeller
authored andcommitted
Don't expose RetentionPolicy.CLASS annotations
Update ASM based metadata readers so that only RetentionPolicy.RUNTIME annotations are exposed. This aligned behavior with the reflection based implementation. Closes gh-22886
1 parent 9d6cf57 commit 8a293f5

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

spring-context/src/test/java/example/scannable_scoped/MyScope.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,9 +16,13 @@
1616

1717
package example.scannable_scoped;
1818

19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
1922
import org.springframework.beans.factory.config.BeanDefinition;
2023
import org.springframework.context.annotation.ScopedProxyMode;
2124

25+
@Retention(RetentionPolicy.RUNTIME)
2226
public @interface MyScope {
2327
String value() default BeanDefinition.SCOPE_SINGLETON;
2428
ScopedProxyMode proxyMode() default ScopedProxyMode.DEFAULT;

spring-context/src/test/java/org/springframework/context/annotation/configuration/spr9031/Spr9031Tests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,9 @@
1616

1717
package org.springframework.context.annotation.configuration.spr9031;
1818

19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
1922
import org.junit.Test;
2023

2124
import org.springframework.beans.factory.annotation.Autowired;
@@ -75,5 +78,6 @@ static class LowLevelConfig {
7578
@Autowired Spr9031Component scanned;
7679
}
7780

81+
@Retention(RetentionPolicy.RUNTIME)
7882
public @interface MarkerAnnotation {}
7983
}

spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -85,6 +85,9 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
8585

8686
@Override
8787
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
88+
if (!visible) {
89+
return null;
90+
}
8891
String className = Type.getType(desc).getClassName();
8992
this.annotationSet.add(className);
9093
return new AnnotationAttributesReadingVisitor(

spring-core/src/main/java/org/springframework/core/type/classreading/MethodMetadataReadingVisitor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,6 +79,9 @@ public MethodMetadataReadingVisitor(String methodName, int access, String declar
7979

8080
@Override
8181
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
82+
if (!visible) {
83+
return null;
84+
}
8285
this.methodMetadataSet.add(this);
8386
String className = Type.getType(desc).getClassName();
8487
return new AnnotationAttributesReadingVisitor(

spring-core/src/test/java/org/springframework/core/type/AnnotationTypeFilterTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,8 @@
1717
package org.springframework.core.type;
1818

1919
import java.lang.annotation.Inherited;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
2022

2123
import org.junit.Test;
2224

@@ -108,6 +110,7 @@ public void testMatchesInterfacesIfConfigured() throws Exception {
108110
// and interfering with ClassloadingAssertions.assertClassNotLoaded()
109111

110112
@Inherited
113+
@Retention(RetentionPolicy.RUNTIME)
111114
private @interface InheritedAnnotation {
112115
}
113116

@@ -132,6 +135,7 @@ private static class SomeSubclassOfSomeComponent extends SomeComponent {
132135
}
133136

134137

138+
@Retention(RetentionPolicy.RUNTIME)
135139
private @interface NonInheritedAnnotation {
136140
}
137141

0 commit comments

Comments
 (0)