extension loading: more cancellability, remove log.warn producing too much noise and unrealistic to fix

This commit is contained in:
peter
2018-11-21 08:18:19 +01:00
parent 1f33ba2d30
commit 2d6a4904a8
2 changed files with 11 additions and 19 deletions
@@ -63,6 +63,9 @@ public class ExtensionComponentAdapter implements LoadingOrder.Orderable, Assign
if (instance == null) {
try {
Class impl = loadImplementationClass();
ExtensionPointImpl.CHECK_CANCELED.run();
instance = new CachingConstructorInjectionComponentAdapter(getComponentKey(), impl, null, true).getComponentInstance(container);
if (myExtensionElement != null) {
@@ -552,27 +552,16 @@ public final class ExtensionPointImpl<T> implements ExtensionPoint<T> {
}
@SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized")
private static Runnable CHECK_CANCELED = EmptyRunnable.getInstance();
static Runnable CHECK_CANCELED = EmptyRunnable.getInstance();
public static void setCheckCanceledAction(Runnable checkCanceled) {
CHECK_CANCELED = new Runnable() {
final Set<Throwable> reported = ContainerUtil.newConcurrentSet();
@Override
public void run() {
try {
checkCanceled.run();
}
catch (ProcessCanceledException e) {
if (!isInsideClassInitializer(e.getStackTrace())) { // otherwise ExceptionInInitializerError happens and the class is screwed forever
throw e;
}
else {
Throwable throwable = new Throwable();
if (reported.add(throwable)) {
LOG.warn("Don't instantiate extensions from class initializer", throwable);
}
}
CHECK_CANCELED = () -> {
try {
checkCanceled.run();
}
catch (ProcessCanceledException e) {
if (!isInsideClassInitializer(e.getStackTrace())) { // otherwise ExceptionInInitializerError happens and the class is screwed forever
throw e;
}
}
};