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 6, 2019
1 parent 9bd6cc1 commit f4519b4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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 All @@ -132,6 +135,7 @@ private static class SomeSubclassOfSomeComponent extends SomeComponent {
}


@Retention(RetentionPolicy.RUNTIME)
private @interface NonInheritedAnnotation {
}

Expand Down

0 comments on commit f4519b4

Please sign in to comment.