This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 22451 - Problem with SharedClassObject.findObject()
Summary: Problem with SharedClassObject.findObject()
Status: VERIFIED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 3.x
Hardware: PC Linux
: P2 blocker (vote)
Assignee: David Strupl
URL:
Keywords: THREAD
: 15668 (view as bug list)
Depends on:
Blocks: 22527
  Show dependency tree
 
Reported: 2002-04-15 17:10 UTC by mslama
Modified: 2008-12-22 18:48 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
patch - apply at your own risk! ;-)) (10.28 KB, patch)
2002-04-23 09:55 UTC, David Strupl
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mslama 2002-04-15 17:10:11 UTC
When I call simultaneously
SharedClassObject.findObject from two threads
(main and AWT) for IDESettings class I receive the
same instance of IDESettings but setting uiMode
has incorrect default value
1 instead of 2 which is deserialized by first call
of findObject.

This behaviour cause annoing trouble in winsys so
please take care about it. I can help with
reproduction.

Steps to reproduce:
Take any dev build from Tuesday last week (9 Apr
2002) or later.
First call of findObject is from
Main.initializeMainWindow
second from UIModeManager.getUIMode. The problem
is that instance
of IDESettings from second call still returns
incorrect value of
setting uiMode.

I suspect synchronization in findObject should be
improved not to return instance before settings
are completely deserialized.
Comment 1 mslama 2002-04-15 17:13:05 UTC
My commit from 8 Apr is causing that second early call of findObject
for IDESettings. As workaround I will try to avoid it but anyway
problem with findObject remains.
Comment 2 _ ttran 2002-04-16 16:38:22 UTC
David, please take care of this issue.  Thanks
Comment 3 _ ttran 2002-04-17 10:28:23 UTC
this is causing bug 22227 - "The Welcome screen is always shown"
Comment 4 David Strupl 2002-04-17 14:31:45 UTC
while trying to fix #22451 I noticed Jesse's comments
from the fix for #17711

// #17711: folder lookup not yet initialized. Try to load the option
later.
// In the meantime the default state of the option will be available.
// If any attempt is made to change the option, _and_ it is later loaded,
// then we print a stack trace of the mutation for debugging (since
the mutations
// would get clobbered by loading the settings from layer or whatever).

The above comment and SharedClassObject.findObject(x, true)
implementation allows returning an object which is actively being modified
and whose getter methods return default values because the values are
being extracted from disk.

My question is whether it makes some sense to try to change it or
whether the current impl. is ok? I mean to change the behaviour to
block in a second thread before returning the value and wait for the
first thread to finish
loading of the SystemOption? And is the proposed solution safe? Or
better to leave the code there as it is now?

Any suggestions? 
Comment 5 Jesse Glick 2002-04-17 15:10:04 UTC
Please read carefully my last comment in issue #17711. A call to
SCO.findObject *after* lookup is ready should block and give you the
prepared object. If you try to use SCO.findObject *before* lookup is
ready, and the object is in fact persisted in a .settings file, you
will have serious problems - so don't ever do that. It is up to the
caller to ensure that lookup is ready first. After that point, you
should be safe.
Comment 6 David Strupl 2002-04-17 15:42:14 UTC
Where does it block if created is false? Sorry but I don't understand
the code in findObject - I cannot see the blocking call.
Comment 7 Jesse Glick 2002-04-17 17:01:03 UTC
IMHO correct behavior of SCO is that findObject should only return an
initialized object, if it is available from lookup. If this does not
work currently, it is a bug in SCO - should be fixed and a test
written. A pathologically written SystemOption (with some kind of
cycle) might deadlock as a result, we will see.
Comment 8 David Strupl 2002-04-23 09:55:06 UTC
Created attachment 5516 [details]
patch - apply at your own risk! ;-))
Comment 9 David Strupl 2002-04-23 10:00:09 UTC
I have tried to run all core/openide tests and don't see any problem.
But adding these two lines to SCO.findObject

      // synchronizing on the same object as returned from getLock()
      synchronized (clazz.getName().intern()) {
      ...
      }

does not sound like something we would like to do. But after trying to
find something more clever (like trying to invent some waiting scheme
instead of simple lock) I didn't find anything that would not be
equivalent of the patch above.

I propose either 
  1. apply the patch
  2. mark the issue as WONTFIX

Currently I am in favour of 2. I would like to hear from you what you
think.
Comment 10 David Strupl 2002-04-25 13:43:37 UTC
Waiting for your comments, suggestions. Thanks.
Comment 11 mslama 2002-04-25 14:10:08 UTC
I vote for fix. If any problem would appear we can always revert fix
back. I do not like current inconsistent behaviour of findObject().
Comment 12 Jesse Glick 2002-04-25 14:32:39 UTC
I also vote for applying the patch. We know the current behavior is
wrong. If the patch seems to be introducing some deadlocks etc., maybe
it will have to be backed out, if there does not seem to be a clean
solution - but that is still hypothetical.

BTW David patches for review might better use the -b "ignore changes
in whitespace" switch to cvs diff (in addition to -u or -c); would
show much more clearly what you are doing.
Comment 13 David Strupl 2002-05-13 13:32:00 UTC
Diff applied and created SharedClassObject 1.51.
Comment 14 _ ttran 2002-05-15 22:04:11 UTC
*** Issue 15668 has been marked as a duplicate of this issue. ***
Comment 15 pzajac 2003-07-31 11:02:00 UTC
verified.