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

UIDefaults.getUIError swallows exceptions

XMLWordPrintable

      Run:

      ---%<---
      import javax.swing.JComponent;
      import javax.swing.UIManager;
      import javax.swing.plaf.ComponentUI;
      public class UIDefaults_getError {
          public static void main(String[] x) {
              JComponent c = new JComponent() {
                  @Override
                  public String getUIClassID() {
                      return "fake";
                  }
                  @Override
                  public String toString() {
                      return "<the component>";
                  }
              };
              UIManager.getDefaults().put("fake", FakeID.class.getName());
              UIManager.getDefaults().getUI(c);
          }
          public static class FakeID extends ComponentUI {
              public static FakeID createUI(JComponent c) {
                  throw new IllegalStateException("Oops!");
              }
          }
      }
      ---%<---

      I get:

      ---%<---
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b04)
      Java HotSpot(TM) Client VM (build 1.7.0-ea-b04, mixed mode, sharing)

      UIDefaults.getUI() failed: createUI() failed for <the component> java.lang.reflect.InvocationTargetException
      java.lang.Error
              at javax.swing.UIDefaults.getUIError(UIDefaults.java:706)
              at javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:117)
              at javax.swing.UIDefaults.getUI(UIDefaults.java:752)
              at UIDefaults_getError.main(UIDefaults_getError.java:17)
      ---%<---

      Note that the original stack trace is lost; even its message is gone.

            Unassigned Unassigned
            jglick Jesse Glick (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: