@@ -74,7 +74,7 @@ public String getPrivilegedPackageName(String packageName) throws ProtectedAcces
74
74
return null ;
75
75
}
76
76
List <String > packageNames = protectedElements .stream ()
77
- .map (element -> element .getType ().toClass (). getPackageName ())
77
+ .map (element -> element .getType ().getPackageName ())
78
78
.distinct ().toList ();
79
79
if (packageNames .size () == 1 ) {
80
80
return packageNames .get (0 );
@@ -86,7 +86,7 @@ public String getPrivilegedPackageName(String packageName) throws ProtectedAcces
86
86
private List <ProtectedElement > getProtectedElements (String packageName ) {
87
87
List <ProtectedElement > matches = new ArrayList <>();
88
88
for (ProtectedElement element : this .elements ) {
89
- if (!element .getType ().toClass (). getPackage ().getName ().equals (packageName )) {
89
+ if (!element .getType ().getPackage ().getName ().equals (packageName )) {
90
90
matches .add (element );
91
91
}
92
92
}
@@ -99,8 +99,9 @@ private List<ProtectedElement> getProtectedElements(String packageName) {
99
99
* @param type the type to analyze
100
100
*/
101
101
public void analyze (ResolvableType type ) {
102
- if (isProtected (type )) {
103
- registerProtectedType (type , null );
102
+ Class <?> protectedType = isProtected (type );
103
+ if (protectedType != null ) {
104
+ registerProtectedType (protectedType , null );
104
105
}
105
106
}
106
107
@@ -119,8 +120,9 @@ public void analyze(Member member, Options options) {
119
120
}
120
121
if (member instanceof Field field ) {
121
122
ResolvableType fieldType = ResolvableType .forField (field );
122
- if (isProtected (fieldType ) && options .assignReturnType .apply (field )) {
123
- registerProtectedType (fieldType , field );
123
+ Class <?> protectedType = isProtected (fieldType );
124
+ if (protectedType != null && options .assignReturnType .apply (field )) {
125
+ registerProtectedType (protectedType , field );
124
126
}
125
127
}
126
128
else if (member instanceof Constructor <?> constructor ) {
@@ -129,8 +131,9 @@ else if (member instanceof Constructor<?> constructor) {
129
131
}
130
132
else if (member instanceof Method method ) {
131
133
ResolvableType returnType = ResolvableType .forMethodReturnType (method );
132
- if (isProtected (returnType ) && options .assignReturnType .apply (method )) {
133
- registerProtectedType (returnType , method );
134
+ Class <?> protectedType = isProtected (returnType );
135
+ if (protectedType != null && options .assignReturnType .apply (method )) {
136
+ registerProtectedType (protectedType , method );
134
137
}
135
138
analyzeParameterTypes (method , i -> ResolvableType .forMethodParameter (method , i ));
136
139
}
@@ -141,37 +144,41 @@ private void analyzeParameterTypes(Executable executable, Function<Integer,
141
144
142
145
for (int i = 0 ; i < executable .getParameters ().length ; i ++) {
143
146
ResolvableType parameterType = parameterTypeFactory .apply (i );
144
- if (isProtected (parameterType )) {
145
- registerProtectedType (parameterType , executable );
147
+ Class <?> protectedType = isProtected (parameterType );
148
+ if (protectedType != null ) {
149
+ registerProtectedType (protectedType , executable );
146
150
}
147
151
}
148
152
}
149
153
150
- boolean isProtected (ResolvableType resolvableType ) {
154
+ @ Nullable
155
+ Class <?> isProtected (ResolvableType resolvableType ) {
151
156
return isProtected (new HashSet <>(), resolvableType );
152
157
}
153
158
154
- private boolean isProtected (Set <ResolvableType > seen , ResolvableType target ) {
159
+ @ Nullable
160
+ private Class <?> isProtected (Set <ResolvableType > seen , ResolvableType target ) {
155
161
if (seen .contains (target )) {
156
- return false ;
162
+ return null ;
157
163
}
158
164
seen .add (target );
159
165
ResolvableType nonProxyTarget = target .as (ClassUtils .getUserClass (target .toClass ()));
160
- if (isProtected (nonProxyTarget .toClass ())) {
161
- return true ;
166
+ Class <?> rawClass = nonProxyTarget .toClass ();
167
+ if (isProtected (rawClass )) {
168
+ return rawClass ;
162
169
}
163
- Class <?> declaringClass = nonProxyTarget . toClass () .getDeclaringClass ();
170
+ Class <?> declaringClass = rawClass .getDeclaringClass ();
164
171
if (declaringClass != null ) {
165
172
if (isProtected (declaringClass )) {
166
- return true ;
173
+ return declaringClass ;
167
174
}
168
175
}
169
176
if (nonProxyTarget .hasGenerics ()) {
170
177
for (ResolvableType generic : nonProxyTarget .getGenerics ()) {
171
178
return isProtected (seen , generic );
172
179
}
173
180
}
174
- return false ;
181
+ return null ;
175
182
}
176
183
177
184
private boolean isProtected (Class <?> type ) {
@@ -183,14 +190,10 @@ private boolean isProtected(int modifiers) {
183
190
return !Modifier .isPublic (modifiers );
184
191
}
185
192
186
- private void registerProtectedType (ResolvableType type , @ Nullable Member member ) {
193
+ private void registerProtectedType (Class <?> type , @ Nullable Member member ) {
187
194
this .elements .add (ProtectedElement .of (type , member ));
188
195
}
189
196
190
- private void registerProtectedType (Class <?> type , Member member ) {
191
- registerProtectedType (ResolvableType .forClass (type ), member );
192
- }
193
-
194
197
/**
195
198
* Options to use to analyze if invoking a {@link Member} requires
196
199
* privileged access.
0 commit comments