Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4023283

Exception within class initializer treated like Error; crashes AWT

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.1.1
    • 1.1
    • client-libs
    • None
    • 1.1.1
    • generic
    • generic

      If a class is loaded within the AWT-Event Queue thread, and if that
      class' initializer throws an exception, then the AWT-Event thread will
      be killed. This happens because a
      java.lang.ExceptionInInitializerError gets thrown. This is an Error, and not an
      Exception, so the try block in java.awt.EventDispatchThread.run() doesn't catch
      it.

      IMHO, the problem here is than an exception in an initializer is considered an
      "Error". Error means "something that we expect will never happen", but
      exceptions get thrown in initializers all the time (well, at least there's
      nothing to prevent a programmer from throwing such an exception.) It's
      also quite easy to do by mistake: Invoke a method that throws
      a RuntimeException.

      Here's the stack backtrace, as of this writing:

      java.lang.ExceptionInInitializerError
              at java.lang.ClassLoader.loadClassInternal(ClassLoader.java)
              at
              at java.awt.Button.processActionEvent(Button.java)
              at java.awt.Button.processEvent(Button.java)
              at java.awt.Component.dispatchEvent(Component.java)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java)

      To reproduce, run HotJava on file:///home/billf/bugs/hostile/hostile.html

            dmendenhsunw David Mendenhall (Inactive)
            bfootesunw Bill Foote (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: