File tree 3 files changed +29
-3
lines changed
main/java/spoon/support/reflect/declaration
3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 59
59
import java .util .Comparator ;
60
60
import java .util .HashSet ;
61
61
import java .util .List ;
62
+ import java .util .Optional ;
62
63
import java .util .Set ;
63
64
64
65
/**
@@ -283,7 +284,7 @@ public Set<CtTypeReference<?>> getUsedTypes(boolean includeSamePackage) {
283
284
}
284
285
285
286
private boolean shouldIncludeSamePackage (boolean includeSamePackage , CtTypeReference <?> typeRef ) {
286
- return includeSamePackage || (getPackage () != null && !getPackageReference (typeRef ).equals (getPackage ().getReference ()));
287
+ return includeSamePackage || (getPackage () != null && !getPackageReference (typeRef ).map ( v -> v . equals (getPackage ().getReference ())). orElse ( false ));
287
288
}
288
289
289
290
private boolean isValidTypeReference (CtTypeReference <?> typeRef ) {
@@ -305,13 +306,16 @@ private boolean isFromJavaLang(CtTypeReference<?> typeRef) {
305
306
* @see CtTypeReference#getPackage()
306
307
* @since 4.0
307
308
*/
308
- private static CtPackageReference getPackageReference (CtTypeReference <?> tref ) {
309
+ private static Optional < CtPackageReference > getPackageReference (CtTypeReference <?> tref ) {
309
310
CtPackageReference pref = tref .getPackage ();
310
311
while (pref == null ) {
311
312
tref = tref .getDeclaringType ();
313
+ if (tref == null ) {
314
+ return Optional .empty ();
315
+ }
312
316
pref = tref .getPackage ();
313
317
}
314
- return pref ;
318
+ return Optional . of ( pref ) ;
315
319
}
316
320
317
321
@ Override
Original file line number Diff line number Diff line change @@ -237,4 +237,16 @@ public void testRetainsInterfaceOrder() {
237
237
238
238
assertEquals (expectedInterfaceOrder , interfaces );
239
239
}
240
+ @ Test
241
+ public void getUsedTypesWithWildcard () {
242
+ //contract: Wildcard types like "?" shouldn't create a NPE. For more context see issue#3514
243
+ String input = "src/test/resources/layornos/AllocationStorage.java" ;
244
+ Launcher launcher = new Launcher ();
245
+ launcher .getEnvironment ().setNoClasspath (true );
246
+ launcher .addInputResource (input );
247
+ CtModel model = launcher .buildModel ();
248
+ model .getAllTypes ().forEach (type -> {
249
+ type .getUsedTypes (false );
250
+ });
251
+ }
240
252
}
Original file line number Diff line number Diff line change
1
+ public class AllocationStorage
2
+ {
3
+
4
+ public void initContainerTemplate ()
5
+ {
6
+ Class <?> component ;
7
+
8
+ }
9
+ }
10
+
You can’t perform that action at this time.
0 commit comments