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

Unify exceptions used by all variants of ICC_Profile.getInstance(null)

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 21
    • client-libs
    • None
    • 2d
    • behavioral
    • low
    • This patch reverts the behavioral change added by the JDK-8227816: in "ICC_Profile#getInstance(InputStream)" the IOException is replaced by the NullPointerException.
    • Java API
    • SE

      Summary

      Specify the correct exceptions thrown by methods in the java.awt.color.ICC_Profile class.

      Problem

      ICC_Profile#getInstance(String fileName) - always throws unspecified
                                                 NullPointerException on null
      ICC_Profile#getInstance(InputStream) - thrown unspecified NullPointerException
                                             before JDK-8227816 and now throws specified but
                                             misleading "IOException: Stream closed" exception on null
      ICC_Profile#write(String fileName) - always throws unspecified NullPointerException on null
      ICC_Profile#write(OutputStream) - always throws unspecified NullPointerException on null

      Solution

      Specify the missing NullPointerException for all methods, and change back the implementation of ICC_Profile#getInstance(InputStream) to always throw NPE on null.

      Specification

      src/java.desktop/share/classes/java/awt/color/ICC_Profile.java
      
      @@ -850,10 +851,7 @@ public static ICC_Profile getInstance(int cspace) {
            * {@code java.class.path} property; finally, in a directory used to store
            * profiles always available, such as the profile for sRGB. Built-in
            * profiles use {@code .pf} as the file name extension for profiles, e.g.
      -     * {@code sRGB.pf}. This method throws an {@code IOException} if the
      -     * specified file cannot be opened or if an I/O error occurs while reading
      -     * the file. It throws an {@code IllegalArgumentException} if the file does
      -     * not contain valid ICC Profile data.
      +     * {@code sRGB.pf}.
            *
            * @param  fileName the file that contains the data for the profile
            * @return an {@code ICC_Profile} object corresponding to the data in the
            *         specified file
            * @throws IOException If the specified file cannot be opened or an I/O
            *         error occurs while reading the file
            * @throws IllegalArgumentException If the file does not contain valid ICC
            *         Profile data
            * @throws SecurityException If a security manager is installed and it does
            *         not permit read access to the given file
      +     * @throws NullPointerException if {@code fileName} is {@code null}
            */
           public static ICC_Profile getInstance(String fileName) throws IOException
      
           /**
            * Constructs an {@code ICC_Profile} corresponding to the data in an
      -     * {@code InputStream}. This method throws an
      -     * {@code IllegalArgumentException} if the stream does not contain valid ICC
      -     * Profile data. It throws an {@code IOException} if an I/O error occurs
      -     * while reading the stream.
      +     * {@code InputStream}.
            *
            * @param  s the input stream from which to read the profile data
            * @return an {@code ICC_Profile} object corresponding to the data in the
            * @throws IOException If an I/O error occurs while reading the stream
            * @throws IllegalArgumentException If the stream does not contain valid ICC
            *         Profile data
      +     * @throws NullPointerException if {@code s} is {@code null}
            */
           public static ICC_Profile getInstance(InputStream s) throws IOException
      
            * @param  fileName the file to write the profile data to
            * @throws IOException If the file cannot be opened for writing or an I/O
            *         error occurs while writing to the file
      +     * @throws NullPointerException if {@code fileName} is {@code null}
            */
           public void write(String fileName) throws IOException {
      
      @@ -1058,6 +1057,7 @@ public void write(String fileName) throws IOException
            *
            * @param  s the stream to write the profile data to
            * @throws IOException If an I/O error occurs while writing to the stream
      +     * @throws NullPointerException if {@code s} is {@code null}
            */
           public void write(OutputStream s) throws IOException

      link for convenience: https://github.com/openjdk/jdk/pull/11784/files

            serb Sergey Bylokhov
            serb Sergey Bylokhov
            Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: