From fb25078de10c8f764ccd8e30a18529dae1a2bc22 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Fri, 12 Feb 2010 13:04:29 +0300 Subject: [PATCH] exception processor for toolkit bugs + added bug 6857057 --- .../src/com/intellij/ide/IdeEventQueue.java | 6 +- .../src/com/intellij/ide/ToolkitBugsProcessor.java | 99 ++++++++++++++++++++++ .../src/misc/registry.properties | 1 + 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 platform/platform-impl/src/com/intellij/ide/ToolkitBugsProcessor.java diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index 8eccf23303..4ad3015d48 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -84,6 +84,8 @@ public class IdeEventQueue extends EventQueue { private final IdePopupManager myPopupManager = new IdePopupManager(); + private final ToolkitBugsProcessor myToolkitBugsProcessor = new ToolkitBugsProcessor(); + private boolean mySuspendMode; /** @@ -611,7 +613,9 @@ public class IdeEventQueue extends EventQueue { throw pce; } catch (Throwable exc) { - LOG.error("Error during dispatching of " + e, exc); + if (!myToolkitBugsProcessor.process(exc)) { + LOG.error("Error during dispatching of " + e, exc); + } } } diff --git a/platform/platform-impl/src/com/intellij/ide/ToolkitBugsProcessor.java b/platform/platform-impl/src/com/intellij/ide/ToolkitBugsProcessor.java new file mode 100644 index 0000000000..eb75012615 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/ToolkitBugsProcessor.java @@ -0,0 +1,99 @@ +/* + * Copyright 2000-2010 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.ide; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.registry.Registry; + +import java.util.ArrayList; +import java.util.List; + +public class ToolkitBugsProcessor { + + private static final Logger LOG = Logger.getInstance("ToolkirBugProcessor"); + + List myHandlers = new ArrayList(); + + public ToolkitBugsProcessor() { + Class[] classes = getClass().getDeclaredClasses(); + for (Class each : classes) { + if (each.equals(Handler.class)) continue; + if (Handler.class.isAssignableFrom(each)) { + try { + Handler eachHandler = (Handler)each.newInstance(); + if (eachHandler.isActual()) { + myHandlers.add(eachHandler); + } + } + catch (Throwable e) { + LOG.error(e); + continue; + } + } + } + } + + public boolean process(Throwable e) { + if (!Registry.is("ide.consumeKnownToolkitBugs")) return false; + + for (Handler each : myHandlers) { + if (each.process(e)) { + LOG.info("Ignored exception by toolkit bug processor, bug id=" + each.toString()); + return true; + } + } + return false; + } + + + abstract static class Handler { + + abstract boolean process(Throwable e); + + boolean isActual() { + return true; + } + + @Override + public String toString() { + String className = getClass().getName(); + String name = className.substring(className.lastIndexOf("$") + 1); + if (name.startsWith("Sun_")) { + name = name.substring("Sun_".length()); + return "http://bugs.sun.com/view_bug.do?bug_id=" + name; + } + return super.toString(); + } + } + + static class Sun_6857057 extends Handler { + @Override + public boolean process(Throwable e) { + if (e instanceof ArrayIndexOutOfBoundsException) { + StackTraceElement[] stack = e.getStackTrace(); + if (stack.length > 5) { + if (stack[0].getClassName().equals("sun.font.FontDesignMetrics") + && stack[0].getMethodName().equals("charsWidth") + && stack[5].getClassName().equals("javax.swing.text.CompositeView") + && stack[5].getMethodName().equals("viewToModel")) { + return true; + } + } + } + return false; + } + } +} diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 1540d23fe7..941a0d02e8 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -25,6 +25,7 @@ ide.debugMode.description=Record additonal information to make bug reports more ide.forcedShowTooltip=alt ide.forcedShowTooltip.description=Shortcut for forced show tooltip ide.popup.dropShadow=false +ide.consumeKnownToolkitBugs=true ide.windowSystem.hScrollChars=15 ide.windowSystem.vScrollChars=5 -- 2.11.4.GIT