Avoid assignment to catch block parameter

GitOrigin-RevId: 9d28cc640717e4a1513e3c2a2c30fd0db4977b42
This commit is contained in:
Tagir Valeev
2021-04-13 07:20:55 +00:00
committed by intellij-monorepo-bot
parent c0f99f7af7
commit 3e15e5f77a
5 changed files with 30 additions and 17 deletions
@@ -393,11 +393,11 @@ public final class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implement
assert progress.isCanceled() && progress.isDisposed();
}
catch (Throwable e) {
if (e instanceof ExecutionException) e = e.getCause();
Throwable unwrapped = ExceptionUtilRt.unwrapException(e, ExecutionException.class);
if (progress.isCanceled() && progress.isRunning()) {
e.addSuppressed(new RuntimeException("Daemon progress was canceled unexpectedly: " + progress));
unwrapped.addSuppressed(new RuntimeException("Daemon progress was canceled unexpectedly: " + progress));
}
ExceptionUtil.rethrow(e);
ExceptionUtil.rethrow(unwrapped);
}
finally {
DaemonProgressIndicator.setDebug(false);
@@ -12,6 +12,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.PluginDescriptor;
import com.intellij.openapi.util.ClassLoaderUtil;
import com.intellij.openapi.util.text.StringHash;
import com.intellij.util.ExceptionUtilRt;
import com.intellij.util.concurrency.AppExecutorUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.JBIterable;
@@ -232,9 +233,7 @@ final class IdeScriptEngineManagerImpl extends IdeScriptEngineManager {
return myEngine.eval(script);
}
catch (Throwable ex) {
//noinspection InstanceofCatchParameter
while (ex instanceof ScriptException && ex.getCause() != null) ex = ex.getCause();
throw new IdeScriptException(ex);
throw new IdeScriptException(ExceptionUtilRt.unwrapException(ex, ScriptException.class));
}
});
}
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
public class ExceptionUtilRt {
public static void rethrowUnchecked(@Nullable Throwable t) {
@@ -34,6 +35,25 @@ public class ExceptionUtilRt {
return findCause(e, klass) != null;
}
/**
* @param throwable exception to unwrap
* @return the supplied exception, or unwrapped exception (if the supplied exception is InvocationTargetException)
*/
public static @NotNull Throwable unwrapInvocationTargetException(@NotNull Throwable throwable) {
return unwrapException(throwable, InvocationTargetException.class);
}
/**
* @param throwable exception to unwrap
* @param classToUnwrap exception class to unwrap
* @return the supplied exception, or unwrapped exception (if the supplied exception class is classToUnwrap)
*/
public static @NotNull Throwable unwrapException(@NotNull Throwable throwable, @NotNull Class<? extends Throwable> classToUnwrap) {
while (classToUnwrap.isInstance(throwable) && throwable.getCause() != null && throwable.getCause() != throwable) {
throwable = throwable.getCause();
}
return throwable;
}
@NotNull
public static String getThrowableText(@NotNull Throwable aThrowable, @NotNull String stackFrameSkipPattern) {
@@ -1,12 +1,12 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.groovy.compiler.rt;
import com.intellij.util.ExceptionUtilRt;
import com.intellij.util.lang.java6.UrlClassLoader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.Charset;
@@ -81,11 +81,7 @@ public final class GroovycRunner {
method.invoke(null, Boolean.valueOf(forStubs), argPath, configScript, targetBytecode, mailbox, out, err);
}
catch (Throwable e) {
//noinspection InstanceofCatchParameter
while (e instanceof InvocationTargetException) {
e = e.getCause();
}
e.printStackTrace(err);
ExceptionUtilRt.unwrapInvocationTargetException(e).printStackTrace(err);
return 1;
}
return 0;
@@ -40,6 +40,7 @@ import com.intellij.uiDesigner.designSurface.GuiEditor;
import com.intellij.uiDesigner.palette.Palette;
import com.intellij.uiDesigner.propertyInspector.properties.*;
import com.intellij.uiDesigner.radComponents.*;
import com.intellij.util.ExceptionUtilRt;
import com.intellij.util.ui.EmptyIcon;
import com.intellij.util.ui.IndentedIcon;
import com.intellij.util.ui.UIUtil;
@@ -59,7 +60,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.*;
@@ -875,10 +875,8 @@ public final class PropertyInspectorTable extends JBTable implements DataProvide
}
catch (Throwable e) {
LOG.debug(e);
if(e instanceof InvocationTargetException){ // special handling of warapped exceptions
e = ((InvocationTargetException)e).getTargetException();
}
Messages.showMessageDialog(e.getMessage(), UIDesignerBundle.message("title.invalid.input"), Messages.getErrorIcon());
String message = ExceptionUtilRt.unwrapInvocationTargetException(e).getMessage();
Messages.showMessageDialog(message, UIDesignerBundle.message("title.invalid.input"), Messages.getErrorIcon());
return false;
}
return true;