Index: ant/src/org/apache/tools/ant/module/AntSettings.java =================================================================== RCS file: /cvs/ant/src/org/apache/tools/ant/module/AntSettings.java,v retrieving revision 1.28 diff -u -r1.28 AntSettings.java --- ant/src/org/apache/tools/ant/module/AntSettings.java 31 Aug 2004 00:37:44 -0000 1.28 +++ ant/src/org/apache/tools/ant/module/AntSettings.java 2 Sep 2004 10:12:47 -0000 @@ -58,6 +58,13 @@ protected void initialize () { super.initialize(); + reset (); + } + + /** Called from initialize and also using reflection when this option + * is about to be "reset". See issue #20962. + */ + protected void reset () { setVerbosity(2 /*Project.MSG_INFO*/); Properties p = new Properties (); // Enable hyperlinking for Jikes: Index: openide/api/doc/changes/apichanges.xml =================================================================== RCS file: /cvs/openide/api/doc/changes/apichanges.xml,v retrieving revision 1.217 diff -u -r1.217 apichanges.xml --- openide/api/doc/changes/apichanges.xml 25 Aug 2004 13:34:49 -0000 1.217 +++ openide/api/doc/changes/apichanges.xml 2 Sep 2004 10:12:48 -0000 @@ -114,6 +114,25 @@ + + + Added SharedClassObject.reset method to allow subclasses to implement reset correctly + + + + + + The new SharedClassObject.reset method is called + by the infrastructure in moments when an original (at the time + of start) state of an option or any other SharedClassObject + is requested. Interested subclasses (like SystemOptions + in Tools/Option dialog) are free to implement any kind of clean + then need. + + + + + Fixed TreeView.drag/dropActive switcher Index: openide/src/org/openide/util/SharedClassObject.java =================================================================== RCS file: /cvs/openide/src/org/openide/util/SharedClassObject.java,v retrieving revision 1.64 diff -u -r1.64 SharedClassObject.java --- openide/src/org/openide/util/SharedClassObject.java 18 Aug 2004 21:42:59 -0000 1.64 +++ openide/src/org/openide/util/SharedClassObject.java 2 Sep 2004 10:12:49 -0000 @@ -547,8 +547,16 @@ } } - /** Resets shared data to it default value. */ - private void reset () { + /** Is called by the infrastructure in cases when a clean instance is requested. + * As instances of SharedClassObject are singletons, there is + * no way how to create new instance that would not contain the same data + * as previously existing one. This method allows all subclasses that care + * about the ability to refresh the settings (like SystemOptions) + * to be notified about the cleaning request and clean their settings themselves. + * + * @since made protected in version 4.46 + */ + protected void reset () { if (!systemOption || !isProjectOption ()) { return; } Index: openide/test/unit/src/org/openide/loaders/InstanceDataObjectTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/loaders/InstanceDataObjectTest.java,v retrieving revision 1.32 diff -u -r1.32 InstanceDataObjectTest.java --- openide/test/unit/src/org/openide/loaders/InstanceDataObjectTest.java 31 Aug 2004 11:21:22 -0000 1.32 +++ openide/test/unit/src/org/openide/loaders/InstanceDataObjectTest.java 2 Sep 2004 10:12:49 -0000 @@ -564,6 +564,49 @@ assertNotNull ("Has cookie", ic); assertEquals ("And its value is x", x, ic.instanceCreate ()); } + + + public void testWeAreAbleToResetSharedClassObjectByCallingResetOnItIssue20962 () throws Exception { + FileObject lookupFO; + { + Object x = Setting.findObject (Setting.class, true); + lookupFO = lfs.findResource("/system/Services/lookupTest"); + DataFolder folderTest = DataFolder.findFolder(lookupFO); + InstanceDataObject ido = InstanceDataObject.create (folderTest, "testLookupRefresh", x, null); + lookupFO = ido.getPrimaryFile (); + WeakReference ref = new WeakReference (ido); + Setting.resetCalled = 0; + } + + InstanceDataObject ido = (InstanceDataObject)DataObject.find (lookupFO); + InstanceCookie ic = (InstanceCookie)ido.getCookie (InstanceCookie.class); + assertNotNull ("Has cookie", ic); + Object obj = ic.instanceCreate (); + assertNotNull ("Not null", obj); + assertEquals ("It is settings", Setting.class, obj.getClass ()); + + + FileLock lock = lookupFO.lock (); + OutputStream os = lookupFO.getOutputStream (lock); + + PrintWriter pw = new PrintWriter (os); + pw.println (""); + pw.println (""); + pw.println (""); + pw.println (" "); + pw.println (" "); + pw.println (" "); + pw.println (""); + pw.close (); + lock.releaseLock (); + + ic = (InstanceCookie)ido.getCookie (InstanceCookie.class); + assertNotNull ("Has cookie", ic); + assertNotNull ("Not null", obj); + assertEquals ("It is settings", Setting.class, obj.getClass ()); + Setting s = (Setting)Setting.findObject (Setting.class, true); + assertEquals ("Refresh has been called", 1, s.resetCalled); + } /** Checks whether the instance is not saved multiple times. * @@ -920,4 +963,15 @@ } } + public static final class Setting extends org.openide.options.SystemOption { + private static int resetCalled; + + protected void reset () { + resetCalled++; + } + + public String displayName () { + return "My Setting"; + } + } }