#78877: Remove all usage of ErrorManager cddl_root
authorjtulach@netbeans.org
Thu, 22 Jun 2006 07:21:32 +0000
changeset 179e24000faf9f6
parent 178 efed407395cc
child 180 c7aa1777c91e
#78877: Remove all usage of ErrorManager
openide.util/src/org/openide/ServiceType.java
openide.util/src/org/openide/util/Exceptions.java
openide.util/src/org/openide/util/Mutex.java
openide.util/src/org/openide/util/NbBundle.java
openide.util/src/org/openide/util/RequestProcessor.java
openide.util/src/org/openide/util/SharedClassObject.java
openide.util/src/org/openide/util/Task.java
openide.util/src/org/openide/util/Utilities.java
openide.util/src/org/openide/util/WeakListenerImpl.java
openide.util/src/org/openide/util/io/NbObjectInputStream.java
openide.util/src/org/openide/xml/XMLUtil.java
     1.1 --- a/openide.util/src/org/openide/ServiceType.java	Wed Jun 21 06:40:22 2006 +0000
     1.2 +++ b/openide.util/src/org/openide/ServiceType.java	Thu Jun 22 07:21:32 2006 +0000
     1.3 @@ -26,6 +26,7 @@
     1.4  import java.util.logging.Level;
     1.5  import java.util.logging.Logger;
     1.6  import org.openide.util.Enumerations;
     1.7 +import org.openide.util.Exceptions;
     1.8  import org.openide.util.HelpCtx;
     1.9  import org.openide.util.Lookup;
    1.10  
    1.11 @@ -63,7 +64,7 @@
    1.12              return Introspector.getBeanInfo(getClass()).getBeanDescriptor().getDisplayName();
    1.13          } catch (Exception e) {
    1.14              // Catching IntrospectionException, but also maybe NullPointerException...?
    1.15 -            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
    1.16 +            Logger.global.log(Level.WARNING, null, e);
    1.17  
    1.18              return getClass().getName();
    1.19          }
    1.20 @@ -106,9 +107,8 @@
    1.21          // moreover it should never happen that this code is executed
    1.22          IllegalStateException ex = new IllegalStateException();
    1.23  
    1.24 -        ErrorManager err = ErrorManager.getDefault();
    1.25 -        err.copyAnnotation(ex, anEx);
    1.26 -        err.annotate(ex, "Cannot createClone for " + this); // NOI18N
    1.27 +        ex.initCause(anEx);
    1.28 +        Exceptions.attachLocalizedMessage(ex, "Cannot createClone for " + this); // NOI18N
    1.29  
    1.30          throw ex;
    1.31      }
     2.1 --- a/openide.util/src/org/openide/util/Exceptions.java	Wed Jun 21 06:40:22 2006 +0000
     2.2 +++ b/openide.util/src/org/openide/util/Exceptions.java	Thu Jun 22 07:21:32 2006 +0000
     2.3 @@ -120,7 +120,6 @@
     2.4          Logger.global.log(OwnLevel.UNKNOWN, null, t);
     2.5      }
     2.6  
     2.7 -
     2.8      /** An exception that has a log record associated with itself, so
     2.9       * the NbErrorManager can extract info about the annotation.
    2.10       */
     3.1 --- a/openide.util/src/org/openide/util/Mutex.java	Wed Jun 21 06:40:22 2006 +0000
     3.2 +++ b/openide.util/src/org/openide/util/Mutex.java	Thu Jun 22 07:21:32 2006 +0000
     3.3 @@ -22,7 +22,6 @@
     3.4  import java.util.Map;
     3.5  import java.util.logging.Level;
     3.6  import java.util.logging.Logger;
     3.7 -import org.openide.ErrorManager;
     3.8  
     3.9  /** Read-many/write-one lock.
    3.10  * Allows control over resources that
    3.11 @@ -539,7 +538,6 @@
    3.12  
    3.13          for (;;) {
    3.14              loopc++;
    3.15 -
    3.16              synchronized (LOCK) {
    3.17                  // does the thread reenter this mutex?
    3.18                  ThreadInfo info = getThreadInfo(t);
    3.19 @@ -549,103 +547,77 @@
    3.20                          // defensive
    3.21                          throw new IllegalStateException();
    3.22                      }
    3.23 -
    3.24                      // reenters
    3.25                      // requested == S -> always succeeds
    3.26                      // info.mode == X -> always succeeds
    3.27 -                    if (((info.mode == S) && (grantedMode == X)) || ((info.mode == X) && (grantedMode == S))) {
    3.28 +                    if (((info.mode == S) && (grantedMode == X)) ||
    3.29 +                        ((info.mode == X) && (grantedMode == S))) {
    3.30                          // defensive
    3.31                          throw new IllegalStateException();
    3.32                      }
    3.33 -
    3.34 -                    if ((info.mode == X) || (info.mode == requested)) { // X - X, X - S, S - S
    3.35 -
    3.36 +                    if ((info.mode == X) || (info.mode == requested)) {
    3.37                          if (info.forced) {
    3.38                              info.forced = false;
    3.39                          } else {
    3.40                              if ((requested == X) && (info.counts[S] > 0)) {
    3.41 -                                IllegalStateException e = new IllegalStateException(
    3.42 -                                        "WARNING: Going from readAccess to writeAccess, see #10778: http://www.netbeans.org/issues/show_bug.cgi?id=10778 "
    3.43 -                                    ); // NOI18N
    3.44 +                                IllegalStateException e = new IllegalStateException("WARNING: Going from readAccess to writeAccess, see #10778: http://www.netbeans.org/issues/show_bug.cgi?id=10778 ");
    3.45  
    3.46                                  if (beStrict) {
    3.47                                      throw e;
    3.48                                  }
    3.49 -
    3.50 -                                ErrorManager.getDefault().notify(e);
    3.51 +                                Exceptions.printStackTrace(e);
    3.52                              }
    3.53 -
    3.54                              info.counts[requested]++;
    3.55 -
    3.56 -                            if ((requested == S) && (info.counts[requested] == 1)) {
    3.57 +                            if ((requested == S) &&
    3.58 +                                (info.counts[requested] == 1)) {
    3.59                                  readersNo++;
    3.60                              }
    3.61                          }
    3.62 -
    3.63                          return true;
    3.64 -                    } else if (canUpgrade(info.mode, requested)) { // S - X and no holders
    3.65 -
    3.66 -                        IllegalStateException e = new IllegalStateException(
    3.67 -                                "WARNING: Going from readAccess to writeAccess, see #10778: http://www.netbeans.org/issues/show_bug.cgi?id=10778 "
    3.68 -                            ); // NOI18N
    3.69 +                    } else if (canUpgrade(info.mode, requested)) {
    3.70 +                        IllegalStateException e = new IllegalStateException("WARNING: Going from readAccess to writeAccess, see #10778: http://www.netbeans.org/issues/show_bug.cgi?id=10778 ");
    3.71  
    3.72                          if (beStrict) {
    3.73                              throw e;
    3.74                          }
    3.75 -
    3.76 -                        ErrorManager.getDefault().notify(e);
    3.77 -
    3.78 +                        Exceptions.printStackTrace(e);
    3.79                          info.mode = X;
    3.80                          info.counts[requested]++;
    3.81                          info.rsnapshot = info.counts[S];
    3.82 -
    3.83                          if (grantedMode == S) {
    3.84                              setGrantedMode(X);
    3.85                          } else if (grantedMode == X) {
    3.86                              // defensive
    3.87                              throw new IllegalStateException();
    3.88                          }
    3.89 -                         // else if grantedMode == CHAIN - let it be
    3.90 -
    3.91 +                        // else if grantedMode == CHAIN - let it be
    3.92                          return true;
    3.93 -                    } else { // S - X and holders
    3.94 -
    3.95 -                        IllegalStateException e = new IllegalStateException(
    3.96 -                                "WARNING: Going from readAccess to writeAccess through queue, see #10778: http://www.netbeans.org/issues/show_bug.cgi?id=10778 "
    3.97 -                            ); // NOI18N
    3.98 +                    } else {
    3.99 +                        IllegalStateException e = new IllegalStateException("WARNING: Going from readAccess to writeAccess through queue, see #10778: http://www.netbeans.org/issues/show_bug.cgi?id=10778 ");
   3.100  
   3.101                          if (beStrict) {
   3.102                              throw e;
   3.103                          }
   3.104 -
   3.105 -                        ErrorManager.getDefault().notify(e);
   3.106 -
   3.107 -                        // chain follows
   3.108 +                        Exceptions.printStackTrace(e);
   3.109                      }
   3.110 -                } else { // first acquisition
   3.111 -
   3.112 -                    if (isCompatible(requested)) { // NONE -> S,X or S -> S
   3.113 +                } else {
   3.114 +                    if (isCompatible(requested)) {
   3.115                          setGrantedMode(requested);
   3.116 -                        registeredThreads.put(t, info = new ThreadInfo(t, requested));
   3.117 -
   3.118 +                        registeredThreads.put(t,
   3.119 +                                              info = new ThreadInfo(t, requested));
   3.120                          if (requested == S) {
   3.121                              readersNo++;
   3.122                          }
   3.123 -
   3.124                          return true;
   3.125                      }
   3.126 -                     // else {
   3.127                  }
   3.128 -
   3.129                  if (!block) {
   3.130                      return false;
   3.131                  }
   3.132 -
   3.133                  setGrantedMode(CHAIN);
   3.134                  cell = chain(requested, t, 0);
   3.135              }
   3.136 -             // sync
   3.137 -
   3.138 +            // sync
   3.139              cell.sleep();
   3.140          }
   3.141           // for
   3.142 @@ -829,19 +801,23 @@
   3.143                  for (int i = 0; i < size; i++) {
   3.144                      try {
   3.145                          Runnable r = (Runnable) runnables.get(i);
   3.146 +
   3.147                          r.run();
   3.148 -                    } catch (Exception e) {
   3.149 -                        ErrorManager.getDefault().notify(e);
   3.150 -                    } catch (StackOverflowError e) {
   3.151 +                    }
   3.152 +                    catch (Exception e) {
   3.153 +                        Exceptions.printStackTrace(e);
   3.154 +                    }
   3.155 +                    catch (StackOverflowError e) {
   3.156                          // Try as hard as possible to get a real stack trace
   3.157                          e.printStackTrace();
   3.158 -                        ErrorManager.getDefault().notify(e);
   3.159 -                    } catch (ThreadDeath td) {
   3.160 +                        Exceptions.printStackTrace(e);
   3.161 +                    }
   3.162 +                    catch (ThreadDeath td) {
   3.163                          throw td;
   3.164 -                    } catch (Error e) { // #20467: LinkageError, AssertionError
   3.165 -                        ErrorManager.getDefault().notify(e);
   3.166                      }
   3.167 -                     // try
   3.168 +                    catch (Error e) {
   3.169 +                        Exceptions.printStackTrace(e);
   3.170 +                    }
   3.171                  }
   3.172                   // for
   3.173  
   3.174 @@ -1260,7 +1236,7 @@
   3.175              throw (RuntimeException) arr[0];
   3.176          }
   3.177  
   3.178 -        throw notifyException(ErrorManager.EXCEPTION, arr[0]);
   3.179 +        throw notifyException(arr[0]);
   3.180      }
   3.181  
   3.182      /** @return true iff current thread is EventDispatchThread */
   3.183 @@ -1277,7 +1253,7 @@
   3.184      }
   3.185  
   3.186      /** Notify exception and returns new MutexException */
   3.187 -    private static final MutexException notifyException(int severity, Throwable t) {
   3.188 +    private static final MutexException notifyException(Throwable t) {
   3.189          if (t instanceof InvocationTargetException) {
   3.190              t = unfoldInvocationTargetException((InvocationTargetException) t);
   3.191          }
   3.192 @@ -1293,13 +1269,13 @@
   3.193          }
   3.194  
   3.195          MutexException exc = new MutexException((Exception) t);
   3.196 -        ErrorManager.getDefault().annotate(exc, t);
   3.197 +        exc.initCause(t);
   3.198  
   3.199          return exc;
   3.200      }
   3.201  
   3.202      private static final void annotateEventStack(Throwable t) {
   3.203 -        ErrorManager.getDefault().annotate(t, new Exception("Caught here in mutex")); // NOI18N
   3.204 +        //ErrorManager.getDefault().annotate(t, new Exception("Caught here in mutex")); // NOI18N
   3.205      }
   3.206  
   3.207      private static final Throwable unfoldInvocationTargetException(InvocationTargetException e) {
   3.208 @@ -1466,7 +1442,7 @@
   3.209  
   3.210                          return;
   3.211                      } catch (InterruptedException e) {
   3.212 -                        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
   3.213 +                        Logger.global.log(Level.WARNING, null, e);
   3.214                      }
   3.215                  }
   3.216              } finally {
     4.1 --- a/openide.util/src/org/openide/util/NbBundle.java	Wed Jun 21 06:40:22 2006 +0000
     4.2 +++ b/openide.util/src/org/openide/util/NbBundle.java	Thu Jun 22 07:21:32 2006 +0000
     4.3 @@ -33,7 +33,8 @@
     4.4  import java.util.ResourceBundle;
     4.5  import java.util.WeakHashMap;
     4.6  import java.util.jar.Attributes;
     4.7 -import org.openide.ErrorManager;
     4.8 +import java.util.logging.Level;
     4.9 +import java.util.logging.Logger;
    4.10  
    4.11  /** Convenience class permitting easy loading of localized resources of various sorts.
    4.12  * Extends the functionality of the default Java resource support, and interacts
    4.13 @@ -411,13 +412,10 @@
    4.14              MissingResourceException e = new MissingResourceException("No such bundle " + baseName, baseName, null); // NOI18N
    4.15  
    4.16              if (Lookup.getDefault().lookup(ClassLoader.class) == null) {
    4.17 -                ErrorManager.getDefault().annotate(
    4.18 -                    e, ErrorManager.UNKNOWN, "Class loader not yet initialized in lookup", null, null, null
    4.19 -                ); // NOI18N
    4.20 +                Exceptions.attachMessage(e,
    4.21 +                                         "Class loader not yet initialized in lookup"); // NOI18N
    4.22              } else {
    4.23 -                ErrorManager.getDefault().annotate(
    4.24 -                    e, ErrorManager.UNKNOWN, "Offending classloader: " + loader, null, null, null
    4.25 -                ); // NOI18N
    4.26 +                Exceptions.attachMessage(e, "Offending classloader: " + loader); // NOI18N
    4.27              }
    4.28  
    4.29              throw e;
    4.30 @@ -532,10 +530,8 @@
    4.31                          is.close();
    4.32                      }
    4.33                  } catch (IOException e) {
    4.34 -                    ErrorManager.getDefault().annotate(
    4.35 -                        e, ErrorManager.UNKNOWN, "While loading: " + res, null, null, null
    4.36 -                    ); // NOI18N
    4.37 -                    ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
    4.38 +                    Exceptions.attachMessage(e, "While loading: " + res); // NOI18N
    4.39 +                    Logger.global.log(Level.WARNING, null, e);
    4.40  
    4.41                      return null;
    4.42                  }
    4.43 @@ -582,9 +578,9 @@
    4.44              } catch (ClassNotFoundException cnfe) {
    4.45                  // fine - ignore
    4.46              } catch (Exception e) {
    4.47 -                ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
    4.48 +                Logger.global.log(Level.WARNING, null, e);
    4.49              } catch (LinkageError e) {
    4.50 -                ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
    4.51 +                Logger.global.log(Level.WARNING, null, e);
    4.52              }
    4.53          }
    4.54  
    4.55 @@ -748,13 +744,10 @@
    4.56                  an = new Attributes.Name(k);
    4.57              } catch (IllegalArgumentException iae) {
    4.58                  // Robustness, and workaround for reported MRJ locale bug:
    4.59 -                ErrorManager em = ErrorManager.getDefault();
    4.60 -                em.annotate(
    4.61 -                    iae, ErrorManager.WARNING, k,
    4.62 -                    getMessage(NbBundle.class, "EXC_bad_attributes_name", k, Locale.getDefault().toString()), null,
    4.63 -                    null
    4.64 +                Exceptions.attachLocalizedMessage(iae, 
    4.65 +                    getMessage(NbBundle.class, "EXC_bad_attributes_name", k, Locale.getDefault().toString()) 
    4.66                  );
    4.67 -                em.notify(iae);
    4.68 +                Exceptions.printStackTrace(iae);
    4.69  
    4.70                  return null;
    4.71              }
     5.1 --- a/openide.util/src/org/openide/util/RequestProcessor.java	Wed Jun 21 06:40:22 2006 +0000
     5.2 +++ b/openide.util/src/org/openide/util/RequestProcessor.java	Thu Jun 22 07:21:32 2006 +0000
     5.3 @@ -23,7 +23,6 @@
     5.4  import java.util.TimerTask;
     5.5  import java.util.logging.Level;
     5.6  import java.util.logging.Logger;
     5.7 -import org.openide.ErrorManager;
     5.8  
     5.9  /** Request processor that is capable to execute requests in dedicated threads.
    5.10   * You can create your own instance or use the shared one.
    5.11 @@ -577,18 +576,17 @@
    5.12              if (delay == 0) { // Place it to pending queue immediatelly
    5.13                  enqueue(localItem);
    5.14              } else { // Post the starter
    5.15 -                starterThread.schedule(
    5.16 -                    new TimerTask() {
    5.17 -                        public void run() { // enqueue the created
    5.18 +                starterThread.schedule(new TimerTask() {
    5.19  
    5.20 -                            try {
    5.21 -                                enqueue(localItem); // it may be already neutralized
    5.22 -                            } catch (RuntimeException e) {
    5.23 -                                ErrorManager.getDefault().notify(e);
    5.24 -                            }
    5.25 -                        }
    5.26 -                    }, delay
    5.27 -                );
    5.28 +                                           public void run() {
    5.29 +                                               try {
    5.30 +                                                   enqueue(localItem);
    5.31 +                                               }
    5.32 +                                               catch (RuntimeException e) {
    5.33 +                                                   Exceptions.printStackTrace(e);
    5.34 +                                               }
    5.35 +                                           }
    5.36 +                                       }, delay);
    5.37              }
    5.38          }
    5.39  
     6.1 --- a/openide.util/src/org/openide/util/SharedClassObject.java	Wed Jun 21 06:40:22 2006 +0000
     6.2 +++ b/openide.util/src/org/openide/util/SharedClassObject.java	Thu Jun 22 07:21:32 2006 +0000
     6.3 @@ -35,7 +35,6 @@
     6.4  import java.util.WeakHashMap;
     6.5  import java.util.logging.Level;
     6.6  import java.util.logging.Logger;
     6.7 -import org.openide.ErrorManager;
     6.8  
     6.9  /** Shared object that allows different instances of the same class
    6.10  * to share common data.
     7.1 --- a/openide.util/src/org/openide/util/Task.java	Wed Jun 21 06:40:22 2006 +0000
     7.2 +++ b/openide.util/src/org/openide/util/Task.java	Thu Jun 22 07:21:32 2006 +0000
     7.3 @@ -287,7 +287,7 @@
     7.4  
     7.5                  return does.booleanValue();
     7.6              } catch (Exception ex) {
     7.7 -                org.openide.ErrorManager.getDefault().notify(ex);
     7.8 +                Exceptions.printStackTrace(ex);
     7.9  
    7.10                  return true;
    7.11              }
     8.1 --- a/openide.util/src/org/openide/util/Utilities.java	Wed Jun 21 06:40:22 2006 +0000
     8.2 +++ b/openide.util/src/org/openide/util/Utilities.java	Thu Jun 22 07:21:32 2006 +0000
     8.3 @@ -364,15 +364,15 @@
     8.4          try {
     8.5              bi = java.beans.Introspector.getBeanInfo(clazz);
     8.6          } catch (java.beans.IntrospectionException ie) {
     8.7 -            org.openide.ErrorManager.getDefault().annotate(
     8.8 -                ie, org.openide.ErrorManager.UNKNOWN, "Encountered while introspecting " + clazz.getName(), null, null, null
     8.9 -            ); // NOI18N
    8.10 +            Exceptions.attachMessage(ie,
    8.11 +                                     "Encountered while introspecting " +
    8.12 +                                     clazz.getName()); // NOI18N
    8.13              throw ie;
    8.14          } catch (Error e) {
    8.15              // Could be a bug in Introspector triggered by NB code.
    8.16 -            org.openide.ErrorManager.getDefault().annotate(
    8.17 -                e, org.openide.ErrorManager.UNKNOWN, "Encountered while introspecting " + clazz.getName(), null, null, null
    8.18 -            ); // NOI18N
    8.19 +            Exceptions.attachMessage(e,
    8.20 +                                     "Encountered while introspecting " +
    8.21 +                                     clazz.getName()); // NOI18N
    8.22              throw e;
    8.23          }
    8.24  
     9.1 --- a/openide.util/src/org/openide/util/WeakListenerImpl.java	Wed Jun 21 06:40:22 2006 +0000
     9.2 +++ b/openide.util/src/org/openide/util/WeakListenerImpl.java	Thu Jun 22 07:21:32 2006 +0000
     9.3 @@ -37,7 +37,6 @@
     9.4  import javax.swing.event.ChangeListener;
     9.5  import javax.swing.event.DocumentEvent;
     9.6  import javax.swing.event.DocumentListener;
     9.7 -import org.openide.ErrorManager;
     9.8  
     9.9  /**
    9.10   * A listener wrapper that delegates to another listener but hold
    10.1 --- a/openide.util/src/org/openide/util/io/NbObjectInputStream.java	Wed Jun 21 06:40:22 2006 +0000
    10.2 +++ b/openide.util/src/org/openide/util/io/NbObjectInputStream.java	Thu Jun 22 07:21:32 2006 +0000
    10.3 @@ -12,7 +12,6 @@
    10.4   */
    10.5  package org.openide.util.io;
    10.6  
    10.7 -import org.openide.ErrorManager;
    10.8  import org.openide.util.Lookup;
    10.9  import org.openide.util.Utilities;
   10.10  
   10.11 @@ -24,6 +23,7 @@
   10.12  import java.io.ObjectStreamClass;
   10.13  
   10.14  import java.lang.reflect.InvocationTargetException;
   10.15 +import org.openide.util.Exceptions;
   10.16  
   10.17  
   10.18  // note: keep method resolveObject consistent with NbObjectOutputStream.replaceObject
   10.19 @@ -61,7 +61,7 @@
   10.20              return Class.forName(v.getName(), false, cl);
   10.21          } catch (ClassNotFoundException cnfe) {
   10.22              String msg = "Offending classloader: " + cl; // NOI18N
   10.23 -            ErrorManager.getDefault().annotate(cnfe, ErrorManager.INFORMATIONAL, msg, null, null, null);
   10.24 +            Exceptions.attachMessage(cnfe, msg);
   10.25              throw cnfe;
   10.26          }
   10.27      }
    11.1 --- a/openide.util/src/org/openide/xml/XMLUtil.java	Wed Jun 21 06:40:22 2006 +0000
    11.2 +++ b/openide.util/src/org/openide/xml/XMLUtil.java	Thu Jun 22 07:21:32 2006 +0000
    11.3 @@ -30,7 +30,6 @@
    11.4  import javax.xml.transform.dom.DOMSource;
    11.5  import javax.xml.transform.stream.StreamResult;
    11.6  import javax.xml.transform.stream.StreamSource;
    11.7 -import org.openide.ErrorManager;
    11.8  import org.openide.util.Lookup;
    11.9  import org.w3c.dom.DOMException;
   11.10  import org.w3c.dom.DOMImplementation;