[platform] no logging for control-flow exceptions (EA-75751)

This commit is contained in:
Roman Shevchenko
2015-11-03 21:28:43 +01:00
parent 2e39d71e2c
commit ec5b26da41
8 changed files with 53 additions and 27 deletions
@@ -15,16 +15,15 @@
*/
package com.intellij.debugger;
public class NoDataException extends Exception {
import com.intellij.openapi.diagnostic.ControlFlowException;
public class NoDataException extends Exception implements ControlFlowException {
@SuppressWarnings({"deprecation", "ThrowableInstanceNeverThrown"})
public static final NoDataException INSTANCE = new NoDataException();
/**
* @deprecated Use shared {@link NoDataException#INSTANCE} instead
*/
/** @deprecated Use shared {@link NoDataException#INSTANCE} instead */
@Deprecated
public NoDataException() {
}
public NoDataException() { }
@Override
public synchronized Throwable fillInStackTrace() {
@@ -18,6 +18,7 @@ package com.intellij.psi.text;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.ControlFlowException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
@@ -48,7 +49,7 @@ public abstract class BlockSupport {
public static final Key<Boolean> DO_NOT_REPARSE_INCREMENTALLY = Key.create("DO_NOT_REPARSE_INCREMENTALLY");
public static final Key<Pair<ASTNode, CharSequence>> TREE_TO_BE_REPARSED = Key.create("TREE_TO_BE_REPARSED");
public static class ReparsedSuccessfullyException extends RuntimeException {
public static class ReparsedSuccessfullyException extends RuntimeException implements ControlFlowException {
private final DiffLog myDiffLog;
public ReparsedSuccessfullyException(@NotNull DiffLog diffLog) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 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.
@@ -21,11 +21,7 @@ import com.intellij.openapi.application.ex.ApplicationInfoEx;
import com.intellij.openapi.application.impl.ApplicationImpl;
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.diagnostic.ApplicationInfoProvider;
import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.IdeaLoggingEvent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.diagnostic.*;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.impl.DebugUtil;
import org.apache.log4j.Level;
@@ -120,14 +116,14 @@ public class IdeaLogger extends Logger {
@Override
public void error(String message, @Nullable Throwable t, @NotNull String... details) {
if (t instanceof ProcessCanceledException) {
myLogger.error(message, new Throwable("Do not log ProcessCanceledException").initCause(t));
throw (ProcessCanceledException)t;
}
if (t != null && t.getClass().getName().contains("ReparsedSuccessfullyException")) {
myLogger.error(new Throwable("Do not log ReparsedSuccessfullyException").initCause(t));
throw (RuntimeException)t;
if (t instanceof ControlFlowException) {
myLogger.error(message, new Throwable("Control-flow exceptions should never be logged", t));
if (t instanceof RuntimeException) {
throw (RuntimeException)t;
}
else {
throw new RuntimeException(t);
}
}
String detailString = StringUtil.join(details, "\n");
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 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.
@@ -59,11 +59,13 @@ public class TestLogger extends com.intellij.openapi.diagnostic.Logger {
@Override
public void warn(String message, @Nullable Throwable t) {
t = checkException(t);
LoggedErrorProcessor.getInstance().processWarn(message, t, myLogger);
}
@Override
public void error(String message, @Nullable Throwable t, @NotNull String... details) {
t = checkException(t);
LoggedErrorProcessor.getInstance().processError(message, t, details, myLogger);
}
@@ -0,0 +1,22 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.diagnostic;
/**
* A marker interface for exceptions that should never be logged.
*/
@SuppressWarnings("NonExceptionNameEndsWithException")
public interface ControlFlowException { }
@@ -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.
@@ -47,6 +47,7 @@ public class DefaultLogger extends Logger {
@Override
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public void warn(@NonNls String message, @Nullable Throwable t) {
t = checkException(t);
System.err.println("WARN: " + message);
if (t != null) t.printStackTrace(System.err);
}
@@ -54,6 +55,7 @@ public class DefaultLogger extends Logger {
@Override
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public void error(String message, @Nullable Throwable t, @NotNull String... details) {
t = checkException(t);
System.err.println("ERROR: " + message);
if (t != null) t.printStackTrace(System.err);
if (details.length > 0) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 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.
@@ -154,4 +154,8 @@ public abstract class Logger {
}
public abstract void setLevel(Level level);
protected static Throwable checkException(@Nullable Throwable t) {
return t instanceof ControlFlowException ? new Throwable("Control-flow exceptions should never be logged", t) : t;
}
}
@@ -15,11 +15,11 @@
*/
package com.intellij.openapi.progress;
import com.intellij.openapi.diagnostic.ControlFlowException;
import org.jetbrains.annotations.NotNull;
public class ProcessCanceledException extends RuntimeException {
public ProcessCanceledException() {
}
public class ProcessCanceledException extends RuntimeException implements ControlFlowException {
public ProcessCanceledException() { }
public ProcessCanceledException(@NotNull Throwable cause) {
super(cause);