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

DebugGraphics NPE @ setFont();

    XMLWordPrintable

Details

    • behavioral
    • low
    • Instead of generating NPEs when calling various instance methods, they will just return.
    • Java API
    • SE

    Description

      Summary

      Update the public no-args constructor of Swing's DebugGaphics class to document that it is not intended to be called by applications.

      Problem

      It is a mistake that the no-args constructor is public since it can't then be connected to a real Graphics instance to debug, and trying to use it just results in unexpected NPEs due to the uninitialised internal variable.

      Solution

      Update the javadoc of the DebugGraphics() constructor is updated to indicate that it is not intended to be called by applications and that it will result in a non-useful instance. The undocumented NPEs are resolved by creating a dummy Graphics which is what makes it non-useful, but no longer harmful.

      Specification

        public class javax.swing.DebugGraphics 
          /**
           * Constructs a new debug graphics context that supports slowed
           * down drawing.
           * <p>
         +  * NOTE: This constructor should not be called by
         +  * applications, it is for internal use only. When called directly
         +  * it will create an un-usable instance.
           */
           public DebugGraphics() {

      Attachments

        Issue Links

          Activity

            People

              tr Tejesh R
              ndcosta Nelson Dcosta (Inactive)
              Philip Race
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: