RFR: 8367384: The ICC_Profile class may throw exceptions during serialization
Harshitha Onkar
honkar at openjdk.org
Thu Sep 25 00:46:29 UTC 2025
On Tue, 16 Sep 2025 23:51:06 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
> Additional checks were recently added to ICC_Profile (see [JDK-8347377](https://bugs.openjdk.org/browse/JDK-8347377)). As a result, objects previously stored as valid profiles may now throw an IllegalArgumentException during serialization. Discussion about serialization was started in https://github.com/openjdk/jdk/pull/23044 but it seems at the end non-serialization related check was [verified](https://github.com/openjdk/jdk/pull/23044/commits/a5201b5f353e8957a1274261372496768edbc7a2). =(
>
> The patch itself is simple, but I found that we do not have good test coverage in this area. So I added two tests to cover all possible variants specified by the serialization spec.
test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/SerializationSpecTest.java line 64:
> 62: test("wrongType_valid", InvalidObjectException.class);
> 63: test("wrongType_invalid", InvalidObjectException.class);
> 64: test("wrongType_wrongType", InvalidObjectException.class);
Since it is not clear what case is being tested from filename, adding a short description per test would be helpful in case someone wants to update or debug this test in future.
`test("invalid_valid", null, "invalid name with valid profile data"); `
And adding some logs to the test() method as below.
test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/SerializationSpecTest.java line 89:
> 87: throw new RuntimeException("Test failed");
> 88: }
> 89: }
Suggestion:
private static void test(String test, Class<?> expected, String msg) {
System.out.println("Testing: " + test);
System.out.println("Description: " + msg);
String fileName = test + ".ser";
File file = new File(System.getProperty("test.src", "."), fileName);
Class<?> actual = null;
try (var fis = new FileInputStream(file);
var ois = new ObjectInputStream(fis))
{
ois.readObject();
} catch (Exception e) {
actual = e.getClass();
}
if (actual != expected) {
System.err.println("Test: " + test);
System.err.println("Expected: " + expected);
System.err.println("Actual: " + actual);
throw new RuntimeException("Test failed");
}
System.out.println("Test Case: " + test + " passed \n");
}
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27326#discussion_r2377366130
PR Review Comment: https://git.openjdk.org/jdk/pull/27326#discussion_r2377370355
More information about the client-libs-dev
mailing list