@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2019 the original author or authors .
* Copyright 2002 - 2024 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 .
@ -43,55 +43,45 @@ class AnnotationIntrospectionFailureTests {
@@ -43,55 +43,45 @@ class AnnotationIntrospectionFailureTests {
@Test
void filteredTypeThrowsTypeNotPresentException ( ) throws Exception {
FilteringClassLoader classLoader = new FilteringClassLoader (
getClass ( ) . getClassLoader ( ) ) ;
Class < ? > withExampleAnnotation = ClassUtils . forName (
WithExampleAnnotation . class . getName ( ) , classLoader ) ;
Annotation annotation = withExampleAnnotation . getAnnotations ( ) [ 0 ] ;
FilteringClassLoader classLoader = new FilteringClassLoader ( getClass ( ) . getClassLoader ( ) ) ;
Class < ? > withAnnotation = ClassUtils . forName ( WithExampleAnnotation . class . getName ( ) , classLoader ) ;
Annotation annotation = withAnnotation . getAnnotations ( ) [ 0 ] ;
Method method = annotation . annotationType ( ) . getMethod ( "value" ) ;
method . setAccessible ( true ) ;
assertThatExceptionOfType ( TypeNotPresentException . class ) . isThrownBy ( ( ) - >
ReflectionUtils . invokeMethod ( method , annotation ) )
. withCauseInstanceOf ( ClassNotFoundException . class ) ;
assertThatExceptionOfType ( TypeNotPresentException . class )
. isThrownBy ( ( ) - > ReflectionUtils . invokeMethod ( method , annotation ) )
. withCauseInstanceOf ( ClassNotFoundException . class ) ;
}
@Test
@SuppressWarnings ( "unchecked" )
void filteredTypeInMetaAnnotationWhenUsingAnnotatedElementUtilsHandlesException ( ) throws Exception {
FilteringClassLoader classLoader = new FilteringClassLoader (
getClass ( ) . getClassLoader ( ) ) ;
Class < ? > withExampleMetaAnnotation = ClassUtils . forName (
WithExampleMetaAnnotation . class . getName ( ) , classLoader ) ;
Class < Annotation > exampleAnnotationClass = ( Class < Annotation > ) ClassUtils . forName (
ExampleAnnotation . class . getName ( ) , classLoader ) ;
Class < Annotation > exampleMetaAnnotationClass = ( Class < Annotation > ) ClassUtils . forName (
ExampleMetaAnnotation . class . getName ( ) , classLoader ) ;
assertThat ( AnnotatedElementUtils . getMergedAnnotationAttributes (
withExampleMetaAnnotation , exampleAnnotationClass ) ) . isNull ( ) ;
assertThat ( AnnotatedElementUtils . getMergedAnnotationAttributes (
withExampleMetaAnnotation , exampleMetaAnnotationClass ) ) . isNull ( ) ;
assertThat ( AnnotatedElementUtils . hasAnnotation ( withExampleMetaAnnotation ,
exampleAnnotationClass ) ) . isFalse ( ) ;
assertThat ( AnnotatedElementUtils . hasAnnotation ( withExampleMetaAnnotation ,
exampleMetaAnnotationClass ) ) . isFalse ( ) ;
FilteringClassLoader classLoader = new FilteringClassLoader ( getClass ( ) . getClassLoader ( ) ) ;
Class < ? > withAnnotation = ClassUtils . forName ( WithExampleMetaAnnotation . class . getName ( ) , classLoader ) ;
Class < Annotation > annotationClass = ( Class < Annotation > )
ClassUtils . forName ( ExampleAnnotation . class . getName ( ) , classLoader ) ;
Class < Annotation > metaAnnotationClass = ( Class < Annotation > )
ClassUtils . forName ( ExampleMetaAnnotation . class . getName ( ) , classLoader ) ;
assertThat ( AnnotatedElementUtils . getMergedAnnotationAttributes ( withAnnotation , annotationClass ) ) . isNull ( ) ;
assertThat ( AnnotatedElementUtils . getMergedAnnotationAttributes ( withAnnotation , metaAnnotationClass ) ) . isNull ( ) ;
assertThat ( AnnotatedElementUtils . hasAnnotation ( withAnnotation , annotationClass ) ) . isFalse ( ) ;
assertThat ( AnnotatedElementUtils . hasAnnotation ( withAnnotation , metaAnnotationClass ) ) . isFalse ( ) ;
}
@Test
@SuppressWarnings ( "unchecked" )
void filteredTypeInMetaAnnotationWhenUsingMergedAnnotationsHandlesException ( ) throws Exception {
FilteringClassLoader classLoader = new FilteringClassLoader (
getClass ( ) . getClassLoader ( ) ) ;
Class < ? > withExampleMetaAnnotation = ClassUtils . forName (
WithExampleMetaAnnotation . class . getName ( ) , classLoader ) ;
Class < Annotation > exampleAnnotationClass = ( Class < Annotation > ) ClassUtils . forName (
ExampleAnnotation . class . getName ( ) , classLoader ) ;
Class < Annotation > exampleMetaAnnotationClass = ( Class < Annotation > ) ClassUtils . forName (
ExampleMetaAnnotation . class . getName ( ) , classLoader ) ;
MergedAnnotations annotations = MergedAnnotations . from ( withExampleMetaAnnotation ) ;
assertThat ( annotations . get ( exampleAnnotationClass ) . isPresent ( ) ) . isFalse ( ) ;
assertThat ( annotations . get ( exampleMetaAnnotationClass ) . isPresent ( ) ) . isFalse ( ) ;
assertThat ( annotations . isPresent ( exampleMetaAnnotationClass ) ) . isFalse ( ) ;
assertThat ( annotations . isPresent ( exampleAnnotationClass ) ) . isFalse ( ) ;
FilteringClassLoader classLoader = new FilteringClassLoader ( getClass ( ) . getClassLoader ( ) ) ;
Class < ? > withAnnotation = ClassUtils . forName ( WithExampleMetaAnnotation . class . getName ( ) , classLoader ) ;
Class < Annotation > annotationClass = ( Class < Annotation > )
ClassUtils . forName ( ExampleAnnotation . class . getName ( ) , classLoader ) ;
Class < Annotation > metaAnnotationClass = ( Class < Annotation > )
ClassUtils . forName ( ExampleMetaAnnotation . class . getName ( ) , classLoader ) ;
MergedAnnotations annotations = MergedAnnotations . from ( withAnnotation ) ;
assertThat ( annotations . get ( annotationClass ) . isPresent ( ) ) . isFalse ( ) ;
assertThat ( annotations . get ( metaAnnotationClass ) . isPresent ( ) ) . isFalse ( ) ;
assertThat ( annotations . isPresent ( metaAnnotationClass ) ) . isFalse ( ) ;
assertThat ( annotations . isPresent ( annotationClass ) ) . isFalse ( ) ;
}
@ -103,17 +93,16 @@ class AnnotationIntrospectionFailureTests {
@@ -103,17 +93,16 @@ class AnnotationIntrospectionFailureTests {
@Override
protected boolean isEligibleForOverriding ( String className ) {
return className . startsWith (
AnnotationIntrospectionFailureTests . class . getName ( ) ) ;
return className . startsWith ( AnnotationIntrospectionFailureTests . class . getName ( ) ) | |
className . startsWith ( "jdk.internal" ) ;
}
@Override
protected Class < ? > loadClass ( String name , boolean resolve ) throws ClassNotFoundException {
if ( name . startsWith ( AnnotationIntrospectionFailureTests . class . getName ( ) ) & &
name . contains ( "Filtered" ) ) {
protected Class < ? > loadClassForOverriding ( String name ) throws ClassNotFoundException {
if ( name . contains ( "Filtered" ) | | name . startsWith ( "jdk.internal" ) ) {
throw new ClassNotFoundException ( name ) ;
}
return super . loadClass ( name , resolv e ) ;
return super . loadClassForOverriding ( name ) ;
}
}