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

Update sun.print.PrintJob2D to use Disposer

XMLWordPrintable

    • 2d

      sun.print.PrintJob2D is the concrete implementation class for java.awt.PrintJob.

      java.awt.PrintJob has a finalize() method which calls PrintJob.end()
      finalize is thus a backstop for applications which do not call end() directly.
      Note that end() is always called by the finalize() method, so any implementation of end() must be idempotent, and the JDK's is.

      The problem here is that to move away from finalize() to a disposer/cleaner, the PrintJob must no longer be reachable. But if it is not reachable then the end() method can't be called.

      A viable solution for any client of the JDK's implementation is to make the real work be done by a delegate. Once the PrintJob is no longer reachable, dispose can call the delegate's end() method.

      This also means that we can leave the finalize() method in place and it can be trivially removed at a later date. And in the event finalize() is disabled by a successor to https://openjdk.org/jeps/421, it can be re-enabled as a transition measure.

            prr Philip Race
            prr Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: