From 204acd9c4b4740031e0c9afd2b8b9857126a3438 Mon Sep 17 00:00:00 2001
From: Pavel Vojtechovsky
Date: Mon, 28 Nov 2016 09:14:20 +0100
Subject: [PATCH] fix ClassNotFound when building shadow class by reflection
---
src/main/java/spoon/reflect/factory/TypeFactory.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/main/java/spoon/reflect/factory/TypeFactory.java b/src/main/java/spoon/reflect/factory/TypeFactory.java
index d0e1e0ae016..189591cc8ec 100644
--- a/src/main/java/spoon/reflect/factory/TypeFactory.java
+++ b/src/main/java/spoon/reflect/factory/TypeFactory.java
@@ -30,6 +30,7 @@
import spoon.reflect.visitor.CtScanner;
import spoon.reflect.visitor.filter.TypeFilter;
import spoon.support.DefaultCoreFactory;
+import spoon.support.SpoonClassNotFoundException;
import spoon.support.StandardEnvironment;
import spoon.support.visitor.java.JavaReflectionTreeBuilder;
@@ -473,7 +474,12 @@ public CtType get(Class> cl) {
if (aType == null) {
final CtType shadowClass = (CtType) this.shadowCache.get(cl);
if (shadowClass == null) {
- final CtType newShadowClass = new JavaReflectionTreeBuilder(createFactory()).scan((Class) cl);
+ CtType newShadowClass;
+ try {
+ newShadowClass = new JavaReflectionTreeBuilder(createFactory()).scan((Class) cl);
+ } catch (Throwable e) {
+ throw new SpoonClassNotFoundException("cannot create shadow class: " + cl.getName(), e);
+ }
newShadowClass.setFactory(factory);
newShadowClass.accept(new CtScanner() {
@Override