<Swing Dev> RFR: 8049301: Suspicious use of string identity checks in JComponent.setUIProperty
    Alexander Zvegintsev 
    azvegint at openjdk.java.net
       
    Fri Jul 30 09:35:34 UTC 2021
    
    
  
On Fri, 30 Jul 2021 06:04:17 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
> JComponent.setUIProperty method uses string identity check (==) rather than string equality checks (.equals) when comparing against the property name. This is suspicious since string identity and equality and equivalent only for interned strings. 
> Rectified to use String.equals() check.
src/java.desktop/share/classes/javax/swing/JComponent.java line 4194:
> 4192:      */
> 4193:     void setUIProperty(String propertyName, Object value) {
> 4194:         if (propertyName.equals("opaque")) {
This will throw an NPE if `propertyName` is `null`, which didn't happened before the fix.
> this method could be rewritten to use strings in switch. 
Probably we might still want to use switch, it will handle the NPE case as before the fix.
Did you run CI tests after the fix?
-------------
PR: https://git.openjdk.java.net/jdk/pull/4943
    
    
More information about the swing-dev
mailing list