JDK-8252495 : Address reliance on default constructors in the Java 2D APIs
  • Type: CSR
  • Component: client-libs
  • Sub-Component: 2d
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 16
  • Submitted: 2020-08-28
  • Updated: 2020-09-21
  • Resolved: 2020-09-21
Related Reports
CSR :  
Description
Summary
-------

Address the reliance on default constructors in several classes in the java 2D APIs.

Problem
-------

Several classes in the java 2D APIs rely on the use of implicit Default Constructors. This is unsuitable as certain access modifiers are required for some constructors and API descriptions but are not included with the use of implicit Default Constructors. The use of explicitly defined no-arg constructors is required.

Solution
--------

The following classes have had an explicit no-arg constructor added, with a protected access modifier and accompanying API description:

 - Default ctor on java.awt.Image
 - Default ctor on java.awt.PrintJob
 - Default ctor on java.awt.font.GlyphVector
 - Default ctor on java.awt.font.LayoutPath
 - Default ctor on java.awt.font.LineMetrics
 - Default ctor on java.awt.image.AbstractMultiResolutionImage
 - Default ctor on java.awt.image.BufferStrategy
 - Default ctor on java.awt.image.RGBImageFilter
 - Default ctor on java.awt.image.VolatileImage
 - Default ctor on javax.print.PrintServiceLookup
 - Default ctor on javax.print.ServiceUIFactory
 - Default ctor on javax.print.StreamPrintServiceFactory
 - Default ctor on javax.print.event.PrintJobAdapter

The following classes have had an explicit no-arg constructor added, with a public access modifier and accompanying API description:

 - Default ctor on java.awt.image.ImageFilter
 - Default ctor on javax.print.ServiceUI

Specification
-------------

    --- old/src/java.desktop/share/classes/java/awt/Image.java	2020-09-04 14:38:14.905370142 +0100
    +++ new/src/java.desktop/share/classes/java/awt/Image.java	2020-09-04 14:38:14.573375564 +0100
    @@ -46,6 +46,11 @@
     public abstract class Image {
     
         /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected Image() {}
    +
    +    /**
          * convenience object; we can use this single static object for
          * all images that do not create their own image caps; it holds the
          * default (unaccelerated) properties.
    --- old/src/java.desktop/share/classes/java/awt/PrintJob.java	2020-09-04 14:38:15.501360410 +0100
    +++ new/src/java.desktop/share/classes/java/awt/PrintJob.java	2020-09-04 14:38:15.193365439 +0100
    @@ -37,6 +37,11 @@
     public abstract class PrintJob {
     
         /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected PrintJob() {}
    +
    +    /**
          * Gets a Graphics object that will draw to the next page.
          * The page is sent to the printer when the graphics
          * object is disposed.  This graphics object will also implement
    --- old/src/java.desktop/share/classes/java/awt/font/GlyphVector.java	2020-09-04 14:38:16.105350547 +0100
    +++ new/src/java.desktop/share/classes/java/awt/font/GlyphVector.java	2020-09-04 14:38:15.785355773 +0100
    @@ -108,6 +108,11 @@
     
     public abstract class GlyphVector implements Cloneable {
     
    +    /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected GlyphVector() {}
    +
         //
         // methods associated with creation-time state
         //
    --- old/src/java.desktop/share/classes/java/awt/font/LayoutPath.java	2020-09-04 14:38:16.713340620 +0100
    +++ new/src/java.desktop/share/classes/java/awt/font/LayoutPath.java	2020-09-04 14:38:16.393345845 +0100
    @@ -41,6 +41,12 @@
      * @since 1.6
      */
     public abstract class LayoutPath {
    +
    +    /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected LayoutPath() {}
    +
         /**
          * Convert a point in user space to a location relative to the
          * path. The location is chosen so as to minimize the distance
    --- old/src/java.desktop/share/classes/java/awt/font/LineMetrics.java	2020-09-04 14:38:17.333330497 +0100
    +++ new/src/java.desktop/share/classes/java/awt/font/LineMetrics.java	2020-09-04 14:38:17.009335787 +0100
    @@ -43,6 +43,10 @@
     
     public abstract class LineMetrics {
     
    +    /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected LineMetrics() {}
     
         /**
          * Returns the number of characters ({@code char} values) in the text whose
    --- old/src/java.desktop/share/classes/java/awt/image/AbstractMultiResolutionImage.java	2020-09-04 14:38:17.945320506 +0100
    +++ new/src/java.desktop/share/classes/java/awt/image/AbstractMultiResolutionImage.java	2020-09-04 14:38:17.629325665 +0100
    @@ -66,6 +66,11 @@
             implements MultiResolutionImage {
     
         /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected AbstractMultiResolutionImage() {}
    +
    +    /**
          * This method simply delegates to the same method on the base image and
          * it is equivalent to: {@code getBaseImage().getWidth(observer)}.
          *
    --- old/src/java.desktop/share/classes/java/awt/image/BufferStrategy.java	2020-09-04 14:38:18.549310646 +0100
    +++ new/src/java.desktop/share/classes/java/awt/image/BufferStrategy.java	2020-09-04 14:38:18.229315870 +0100
    @@ -135,6 +135,11 @@
     public abstract class BufferStrategy {
     
         /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected BufferStrategy() {}
    +
    +    /**
          * Returns the {@code BufferCapabilities} for this
          * {@code BufferStrategy}.
          *
    --- old/src/java.desktop/share/classes/java/awt/image/ImageFilter.java	2020-09-04 14:38:19.205299937 +0100
    +++ new/src/java.desktop/share/classes/java/awt/image/ImageFilter.java	2020-09-04 14:38:18.885305162 +0100
    @@ -43,6 +43,12 @@
      * @author      Jim Graham
      */
     public class ImageFilter implements ImageConsumer, Cloneable {
    +
    +    /**
    +     * Constructs an {@code ImageFilter}.
    +     */
    +    public ImageFilter() {}
    +
         /**
          * The consumer of the particular image data stream for which this
          * instance of the ImageFilter is filtering data.  It is not
    --- old/src/java.desktop/share/classes/java/awt/image/RGBImageFilter.java	2020-09-04 14:38:19.829289753 +0100
    +++ new/src/java.desktop/share/classes/java/awt/image/RGBImageFilter.java	2020-09-04 14:38:19.497295172 +0100
    @@ -67,6 +67,11 @@
     public abstract class RGBImageFilter extends ImageFilter {
     
         /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected RGBImageFilter() {}
    +
    +    /**
          * The {@code ColorModel} to be replaced by
          * {@code newmodel} when the user calls
          * {@link #substituteColorModel(ColorModel, ColorModel) substituteColorModel}.
    --- old/src/java.desktop/share/classes/java/awt/image/VolatileImage.java	2020-09-04 14:38:20.433279895 +0100
    +++ new/src/java.desktop/share/classes/java/awt/image/VolatileImage.java	2020-09-04 14:38:20.121284987 +0100
    @@ -133,6 +133,11 @@
     public abstract class VolatileImage extends Image implements Transparency
     {
     
    +    /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected VolatileImage() {}
    +
         // Return codes for validate() method
     
         /**
    --- old/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java	2020-09-04 14:38:21.061269645 +0100
    +++ new/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java	2020-09-04 14:38:20.717275259 +0100
    @@ -66,6 +66,11 @@
     public abstract class PrintServiceLookup {
     
         /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected PrintServiceLookup() {}
    +
    +    /**
          * Contains a lists of services.
          */
         static class Services {
    --- old/src/java.desktop/share/classes/javax/print/ServiceUI.java	2020-09-04 14:38:21.725258809 +0100
    +++ new/src/java.desktop/share/classes/javax/print/ServiceUI.java	2020-09-04 14:38:21.401264097 +0100
    @@ -66,6 +66,11 @@
     public class ServiceUI {
     
         /**
    +     * Constructs a {@code ServiceUI}.
    +     */
    +    public ServiceUI() {}
    +
    +    /**
          * Presents a dialog to the user for selecting a print service (printer). It
          * is displayed at the location specified by the application and is modal.
          * If the specification is invalid or would make the dialog not visible it
    --- old/src/java.desktop/share/classes/javax/print/ServiceUIFactory.java	2020-09-04 14:38:22.345248692 +0100
    +++ new/src/java.desktop/share/classes/javax/print/ServiceUIFactory.java	2020-09-04 14:38:22.021253978 +0100
    @@ -57,6 +57,11 @@
     public abstract class ServiceUIFactory {
     
         /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected ServiceUIFactory() {}
    +
    +    /**
          * Denotes a UI implemented as a Swing component. The value of the string is
          * the fully qualified classname : "javax.swing.JComponent".
          */
    --- old/src/java.desktop/share/classes/javax/print/event/PrintJobAdapter.java	2020-09-04 14:38:22.953238771 +0100
    +++ new/src/java.desktop/share/classes/javax/print/event/PrintJobAdapter.java	2020-09-04 14:38:22.641243862 +0100
    @@ -37,6 +37,11 @@
     public abstract class PrintJobAdapter implements PrintJobListener {
     
         /**
    +     * Constructor for subclasses to call.
    +     */
    +    protected PrintJobAdapter() {}
    +
    +    /**
          * Called to notify the client that data has been successfully transferred
          * to the print service, and the client may free local resources allocated
          * for that data. The client should not assume that the data has been

A zip of the spec diff highlighting the API Documentation changes is added as an attachment. The API Documentation changes can also be browsed at the following location for the reviewer���s convenience: http://cr.openjdk.java.net/~ccleary/issues/webrevs-store/8250855/webrevs/webrev.02/specdiff/overview-summary.html



Comments
Moving to Approved.
21-09-2020

CSR has been updated to include spec in the Specification section, please review [~prr]. Attempted to remove diff.patch from attachments but it seems I dont have permission to do so.
18-09-2020

Chris: I was (am) waiting until the spec is in the spec section in a readable format. We don't see specdiff.zip attachments being the only option as very friendly. I am surprised anyone would think that sufficient. Also this CSR should not have been made final without my review - or that of someone from the client team. It should be withdrawn, updated and made ready for review.
17-09-2020

[~prr] Can you please confirm that you are in agreement with the changes described by this CSR.
16-09-2020

Looks fine; moving to Approved.
15-09-2020

Code Diff and Specdiff for these changes have now been provided as attachments to the CSR.
15-09-2020

The CSR can't rely solely on a link to an external webite. The diffs need to be provided here. Others like this have the spec updates direcrly in the specfication section. Take a look at this one as a reference : https://bugs.openjdk.java.net/browse/JDK-8251856
14-09-2020