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

JComponent.paintImmediately() always prints stack trace for NPE

XMLWordPrintable

      The method JComponent.paintImmediately() includes the following lines of code:

      4614 try {
      4615 try {
      4616 Graphics pcg = paintingComponent.getGraphics();
      4617 g = SwingGraphics.createSwingGraphics(pcg);
      4618 pcg.dispose();
      4619 } catch(NullPointerException e) {
      4620 g = null;
      4621 e.printStackTrace();
      4622 }

      When a GUI interaction in the application code causes a NPE, the stack trace is printed to the user, but the application code is not given the opportunity to react to the exception - the application code is not aware of the exception since it is caught in JComponent. In addition, the application does not have the option to turn off the printing of the stack trace to the user.

      If you could remove the catching of the NPE (or perhaps re-throw the exception), the application would have the opportunity to handle the exception, if desired, and otherwise would simply print the stack trace as it does now.

            svioletsunw Scott Violet (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: