RFR: JDK-8346465 : Add a check in setData() to restrict the update of Built-In ICC_Profiles [v11]

Sergey Bylokhov serb at openjdk.org
Wed Mar 12 19:29:56 UTC 2025


On Tue, 11 Mar 2025 19:56:52 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> The System Properties case isn't something I'd want to follow. It doesn't really make them read-only.
>> It just ensures that the JDK internally caches the original value for use in certain places.
>> 
>> Consider this program
>> 
>> public class jh {
>>   public static void main(String[] args) {
>>    String jhpstr = "java.home";
>>    String jhp1 = System.getProperty(jhpstr);
>>    System.setProperty(jhpstr, "foo");
>>    String jhp2 = System.getProperty("java.home");
>>    System.out.println(jhp1+" " +jhp2);
>>   }
>> } 
>> % java jh
>> /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home foo
>
>> There are two other exceptions that may be better suited that ISE in this case - [UnsupportedOperationException ](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/UnsupportedOperationException.html) and [ProfileDataException](https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/java/awt/color/ProfileDataException.html) but still IAE was chosen over them as it is existing and documented exception.
> 
> `UnsupportedOperationException` could be used.
> 
> `HeadlessException` extends `UnsupportedOperationException` and indicates a situation where a method cannot proceed because of the platform configuration.
> 
> `ProfileDataException` doesn't suit either because there's nothing wrong with the profile data in the case of built-in profiles.

> The System Properties case isn't something I'd want to follow. It doesn't really make them read-only.
> It just ensures that the JDK internally caches the original value for use in certain places.

Right. The application may attempt to change these java properties, but it won't affect the behavior of the JDK since the JDK internally will use the initially cached value of the property via StaticProperty.userDir()/userHome()/etc.

This is even specified similarly to what we want for color profiles.

>  * <strong>Changing a standard system property may have unpredictable results
     * unless otherwise specified.</strong>
     * Property values may be cached during initialization or on first use.
     * Setting a standard property after initialization using {@link #getProperties()},
     * {@link #setProperties(Properties)}, {@link #setProperty(String, String)}, or
     * {@link #clearProperty(String)} may not have the desired effect.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/23606#discussion_r1992167456


More information about the client-libs-dev mailing list