RFR: 8278620: properties installed by javax.swing.LookAndFeel installColors and installColorsAndFont are not uninstalled [v3]

SWinxy duke at openjdk.org
Mon Feb 20 08:12:10 UTC 2023


On Sun, 19 Feb 2023 09:35:53 GMT, SWinxy <duke at openjdk.org> wrote:

>> Many `installDefaults` methods set the font, foreground, and background on objects but their inverse methods `uninstallDefaults` do not remove them. I've added an inverse method to remove the colors and font to call for the `uninstallDefaults` methods that install defaults.
>> 
>> `AquaButtonUI` can call its super since it would otherwise be repeated code. `BasicComboBoxUI` (weirdly) installs the properties again when it should be uninstalling them, so I changed.
>> 
>> I noticed that, in a few subclasses, only one of calls to the super of `installDefaults` and `uninstallDefaults` are made. That is, an overridden `installDefaults` may call its super while the overridden `uninstallDefaults` does not call its super (or vise versa). These classes are: `AquaTabbedPaneUI`, `SynthMenuItemUI`, `SynthSplitPaneUI`, and `XTextAreaPeer`.
>> 
>> Sorry I couldn't write a test; I wasn't sure how I should have accessed the protected variable aside from creating extending classes for each class that changed.
>> 
>> See also #6603, where this issue was discovered.
>
> SWinxy has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
> 
>  - BasicPanelUI uninstalling font causes cascading problems
>  - Merge branch 'master' into 8278620
>  - Sync with CSR
>    
>    Only difference is that I added an Oxford comma
>  - Accidental imports added
>  - 8278620: properties installed by javax.swing.LookAndFeel installColors and installColorsAndFont are not uninstalled
>    
>    Many installDefaults methods set the font, foreground, and background on objects but their inverse methods uninstallDefaults do not remove them. I've added an inverse method to remove the colors and font to call for the uninstallDefaults methods that install defaults.
>    
>    AquaButtonUI can call its super since it would otherwise be repeated code. BasicComboBoxUI (weirdly) installs the properties again when it should be uninstalling them, so I changed.
>    
>    I noticed that, in a few subclasses, only one of calls to the super of installDefaults and uninstallDefaults are made. That is, an overridden installDefaults may call its super while the overridden uninstallDefaults does not call its super (or vise versa). These classes are: AquaTabbedPaneUI, SynthMenuItemUI, SynthSplitPaneUI, and XTextAreaPeer.

Figured it out. When setting a `Component`'s font to `null`, it inherits the font from the component tree. (Some classes omit this fact from their respective documentations.) Window peers will check `isFontSet` when they are created, and will set it to a `Font` if no font is set. The problem is that installing the font checks if the font is critically a `FontUIResource`. This means that `setFont(null)` is called on `FontUIResource` fonts, the code goes up the hierarchy to non-null fonts, and finds a non-`FontUIResource` font, and sets the component to that font, which is originally set by the component peers on creation, and then the components can't install a default because it will replace a `null` or a `FontUIResource` font. Changing the fallback font type to a `FontUIResource` in the peers fixes this. I hope this doesn't break anything else lol. (It probably will.)

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

PR: https://git.openjdk.org/jdk/pull/10565



More information about the client-libs-dev mailing list