File tree Expand file tree Collapse file tree 4 files changed +53
-5
lines changed
main/java24/org/springframework/core/type/classreading
test/java/org/springframework/core/type Expand file tree Collapse file tree 4 files changed +53
-5
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ class ClassFileClassMetadata implements AnnotationMetadata {
72
72
this .className = className ;
73
73
this .accessFlags = accessFlags ;
74
74
this .enclosingClassName = enclosingClassName ;
75
- this .superClassName = superClassName ;
75
+ this .superClassName = (! className . endsWith ( ".package-info" )) ? superClassName : null ;
76
76
this .independentInnerClass = independentInnerClass ;
77
77
this .interfaceNames = interfaceNames ;
78
78
this .memberClassNames = memberClassNames ;
Original file line number Diff line number Diff line change @@ -161,6 +161,12 @@ void getSuperClassNameWhenHasNoSuperClassReturnsNull() {
161
161
assertThat (get (TestSubInterface .class ).getSuperClassName ()).isIn (null , "java.lang.Object" );
162
162
}
163
163
164
+ @ Test
165
+ void getSuperClassNameWhenPackageInfoReturnsNull () throws Exception {
166
+ Class <?> packageClass = Class .forName (getClass ().getPackageName () + ".package-info" );
167
+ assertThat (get (packageClass ).getSuperClassName ()).isNull ();
168
+ }
169
+
164
170
@ Test
165
171
void getInterfaceNamesWhenHasInterfacesReturnsNames () {
166
172
assertThat (get (TestSubclass .class ).getInterfaceNames ()).containsExactly (TestInterface .class .getName ());
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2002-2025 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package org .springframework .core .type .classreading ;
18
+
19
+ import org .springframework .core .type .AbstractAnnotationMetadataTests ;
20
+ import org .springframework .core .type .AnnotationMetadata ;
21
+
22
+ /**
23
+ * Tests for {@link SimpleAnnotationMetadata} and
24
+ * {@link SimpleAnnotationMetadataReadingVisitor} on Java < 24,
25
+ * and for the ClassFile API variant on Java >= 24.
26
+ *
27
+ * @author Phillip Webb
28
+ */
29
+ class DefaultAnnotationMetadataTests extends AbstractAnnotationMetadataTests {
30
+
31
+ @ Override
32
+ protected AnnotationMetadata get (Class <?> source ) {
33
+ try {
34
+ return MetadataReaderFactory .create (source .getClassLoader ())
35
+ .getMetadataReader (source .getName ()).getAnnotationMetadata ();
36
+ }
37
+ catch (Exception ex ) {
38
+ throw new IllegalStateException (ex );
39
+ }
40
+ }
41
+
42
+ }
Original file line number Diff line number Diff line change 21
21
22
22
/**
23
23
* Tests for {@link SimpleAnnotationMetadata} and
24
- * {@link SimpleAnnotationMetadataReadingVisitor} on Java < 24,
25
- * and for the ClassFile API variant on Java >= 24.
24
+ * {@link SimpleAnnotationMetadataReadingVisitor}.
26
25
*
27
26
* @author Phillip Webb
28
27
*/
@@ -31,8 +30,9 @@ class SimpleAnnotationMetadataTests extends AbstractAnnotationMetadataTests {
31
30
@ Override
32
31
protected AnnotationMetadata get (Class <?> source ) {
33
32
try {
34
- return MetadataReaderFactory .create (source .getClassLoader ())
35
- .getMetadataReader (source .getName ()).getAnnotationMetadata ();
33
+ return new SimpleMetadataReaderFactory (
34
+ source .getClassLoader ()).getMetadataReader (
35
+ source .getName ()).getAnnotationMetadata ();
36
36
}
37
37
catch (Exception ex ) {
38
38
throw new IllegalStateException (ex );
You can’t perform that action at this time.
0 commit comments