Skip to content

Commit

Permalink
Don't expose RetentionPolicy.CLASS annotations
Browse files Browse the repository at this point in the history
Update ASM based metadata readers so that only RetentionPolicy.RUNTIME
annotations are exposed. This aligned behavior with the reflection based
implementation.

Closes spring-projectsgh-22886
  • Loading branch information
philwebb committed May 4, 2019
1 parent ffbecf1 commit 070b95a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package example.scannable_scoped;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ScopedProxyMode;

@Retention(RetentionPolicy.RUNTIME)
public @interface MyScope {
String value() default BeanDefinition.SCOPE_SINGLETON;
ScopedProxyMode proxyMode() default ScopedProxyMode.DEFAULT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

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

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import org.junit.Test;

import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -75,5 +78,6 @@ static class LowLevelConfig {
@Autowired Spr9031Component scanned;
}

@Retention(RetentionPolicy.RUNTIME)
public @interface MarkerAnnotation {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si

@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
if (!visible) {
return null;
}
String className = Type.getType(desc).getClassName();
this.annotationSet.add(className);
return new AnnotationAttributesReadingVisitor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public MethodMetadataReadingVisitor(String methodName, int access, String declar

@Override
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
if (!visible) {
return null;
}
this.methodMetadataSet.add(this);
String className = Type.getType(desc).getClassName();
return new AnnotationAttributesReadingVisitor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.springframework.core.type;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import org.junit.Test;

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

@Inherited
@Retention(RetentionPolicy.RUNTIME)
private @interface InheritedAnnotation {
}

Expand Down

0 comments on commit 070b95a

Please sign in to comment.