Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4368193

Toolkit's getDesktopProperty returns stale values on win32

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      generic
    • OS:
      solaris_10
    • Verification:
      Verified

      Description

      In Toolkit, there is a HashMap which stores the desktop properties
      which are gettable via getDesktopProperty().

      getDesktopProperty() first looks up the property name, and if
      the value is null, it invokes lazilyLoadDesktopProperty(), which
      is overridden by sun.awt.windows.WToolkit.

      java.awt.Toolkit: getDesktopProperty() -->

              Object value = desktopProperties.get(propertyName);

      if (value == null) {
      value = lazilyLoadDesktopProperty(propertyName);

      if (value != null) {
      setDesktopProperty(propertyName, value);
      }
      }

      return value;

      Now WToolkit has it's own desktop property mechanism, WDesktopProperties,
      which manages the win32 system properties (which begin with the prefix
      "win."). WDesktopProperties has it's own HashMap and PropertyChangeSupport
      for these properties and WToolkit delegates to it for these "win."
      properties.

      The problem is that the "win." properties are maintained in WDesktopProperties,
      but when one of these properties is requested by toolkit.getDesktopProperty()
      (i.e. from Swing) Toolkit caches the value in it's own HashMap.
      Unfortunately when WDesktopProperties detects a change to one of these
      "win." properties from the system, it notifies all property change listeners,
      but never refreshes the value in Toolkit's HashMap. So Swing get's notified
      the value has changed (with correct old and new values), but when it later
      invokes toolkit.getDesktopProperty(), it gets the old stale value.

      Compile/run the program below and follow these steps to reproduce:

      1. run program (wait til frame pops on screen)
      2. On Windows desktop, use desktop popup menu to bring up
         "Properties"
      3. Select "Appearance" tab
      4. Change "Item" to be "3D Objects"
      5. Change "Color" value
      6. Press "OK"

      println output shows error....



      //-----------------------------------------------------------
      import java.awt.*;
      import java.beans.*;

      public class DesktopPropertyTest {
          static String propName = "win.3d.backgroundColor";

          public static void main(String args[]) {

      queryProperty();

      Toolkit.getDefaultToolkit().addPropertyChangeListener(propName, new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent e) {
      System.out.println("PropertyChangeEvent: "+e.getPropertyName()+
      "\n old value="+e.getOldValue()+
      "\n new value="+e.getNewValue());

      queryProperty();
      }
      });

      Frame f = new Frame();
      f.show();


          }

          public static void queryProperty() {
      Object value = Toolkit.getDefaultToolkit().getDesktopProperty(propName);
      System.out.println("toolkit.getDesktopProperty:"+propName+"="+value);
          }
      }


        Attachments

          Activity

            People

            Assignee:
            son Oleg Sukhodolsky (Inactive)
            Reporter:
            amfowler Anne Fowler (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: