diff --git a/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java b/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java index 8afdc638d42..3e86fcf6141 100644 --- a/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java +++ b/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java @@ -758,12 +758,13 @@ protected void finalize () { /** * Constructs an {@code ICC_Profile} object corresponding to the data in a - * byte array. Throws an {@code IllegalArgumentException} if the data does - * not correspond to a valid ICC Profile. + * byte array. * * @param data the specified ICC Profile data * @return an {@code ICC_Profile} object corresponding to the data in the * specified {@code data} array + * @throws IllegalArgumentException If the byte array does not contain valid + * ICC Profile data */ public static ICC_Profile getInstance(byte[] data) { ICC_Profile thisProfile; @@ -957,12 +958,7 @@ public static ICC_Profile getInstance(String fileName) throws IOException { * Profile data */ public static ICC_Profile getInstance(InputStream s) throws IOException { - byte[] profileData; - if ((profileData = getProfileDataFromStream(s)) == null) { - throw new IllegalArgumentException("Invalid ICC Profile Data"); - } - - return getInstance(profileData); + return getInstance(getProfileDataFromStream(s)); } diff --git a/test/jdk/java/awt/color/GetInstanceBrokenData.java b/test/jdk/java/awt/color/GetInstanceBrokenData.java new file mode 100644 index 00000000000..1ba78177b33 --- /dev/null +++ b/test/jdk/java/awt/color/GetInstanceBrokenData.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.color.ICC_Profile; + +/** + * @test + * @bug 6211198 + * @summary IllegalArgumentException in ICC_Profile.getInstance for broken data + */ +public final class GetInstanceBrokenData { + + public static void main(String[] argv) { + byte b[] = {-21, -22, -23}; + try { + ICC_Profile p = ICC_Profile.getInstance(b); + throw new RuntimeException("IllegalArgumentException is expected"); + } catch (IllegalArgumentException ignored) { + // expected + } + } +} diff --git a/test/jdk/java/awt/color/GetInstanceNullData.java b/test/jdk/java/awt/color/GetInstanceNullData.java index 9543455477a..b31e3cc4d3d 100644 --- a/test/jdk/java/awt/color/GetInstanceNullData.java +++ b/test/jdk/java/awt/color/GetInstanceNullData.java @@ -27,7 +27,7 @@ /** * @test - * @bug 4176618 7042594 + * @bug 4176618 7042594 6211198 * @summary This interactive test verifies that passing null to * ICC_ProfileRGB.getInstance() does not crash the VM. * An IllegalArgumentException: Invalid ICC Profile Data should be