assertion for circular progress indicators to avoid EA-76328 - SOE: CoreProgressManager.registerIndicatorAndRun

This commit is contained in:
Alexey Kudravtsev
2015-12-02 13:38:33 +03:00
parent cce7d9a9a7
commit 80fdda667a
4 changed files with 20 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,11 +19,13 @@ import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.ThrowableComputable;
import gnu.trove.THashSet;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Set;
public abstract class ProgressManager extends ProgressIndicatorProvider {
private static class ProgressManagerHolder {
@@ -191,4 +193,14 @@ public abstract class ProgressManager extends ProgressIndicatorProvider {
public abstract void executeProcessUnderProgress(@NotNull Runnable process,
@Nullable("null means reuse current progress") ProgressIndicator progress)
throws ProcessCanceledException;
public static void assertNotCircular(@NotNull ProgressIndicator original) {
Set<ProgressIndicator> wrappedParents = null;
for (ProgressIndicator parent = original; parent instanceof WrappedProgressIndicator; parent = ((WrappedProgressIndicator)parent).getOriginalProgressIndicator()) {
if (wrappedParents == null) wrappedParents = new THashSet<ProgressIndicator>();
if (!wrappedParents.add(parent)) {
throw new IllegalArgumentException(parent + " wraps itself");
}
}
}
}
@@ -24,6 +24,7 @@ package com.intellij.openapi.progress.util;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.StandardProgressIndicator;
import com.intellij.openapi.progress.WrappedProgressIndicator;
import org.jetbrains.annotations.Contract;
@@ -48,6 +49,7 @@ public class ProgressWrapper extends AbstractProgressIndicatorBase implements Wr
if (nested > 50) {
LOG.error("Too many wrapped indicators");
}
ProgressManager.assertNotCircular(original);
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ public class DelegatingProgressIndicator implements WrappedProgressIndicator, St
public DelegatingProgressIndicator(@NotNull ProgressIndicator indicator) {
myIndicator = indicator;
ProgressManager.assertNotCircular(indicator);
}
public DelegatingProgressIndicator() {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package com.intellij.openapi.progress.util;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.StandardProgressIndicator;
import com.intellij.openapi.progress.WrappedProgressIndicator;
import com.intellij.openapi.project.Project;
@@ -67,6 +68,7 @@ public class SmoothProgressAdapter extends AbstractProgressIndicatorExBase imple
myOriginal.setModalityProgress(this);
setModalityProgress(this);
}
ProgressManager.assertNotCircular(original);
}
@NotNull