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 192759

Summary: Missing WeakSet.putIfAbsent
Product: platform Reporter: Jaroslav Tulach <jtulach>
Component: -- Other --Assignee: Vladimir Voskresensky <vv159170>
Status: RESOLVED FIXED    
Severity: normal CC: apireviews, jglick
Priority: P3 Keywords: API, API_REVIEW_FAST
Version: 7.0   
Hardware: Other   
OS: Linux   
Issue Type: DEFECT Exception Reporter:
Attachments: hg diff after (hg rm, hg mv, fix of names)
patch

Description Jaroslav Tulach 2010-12-01 18:42:30 UTC
Vladimir mentioned that he has better implementation of WeakSet that could replace the existing org.openide.util.WeakSet.

That implementation also provides putIfAbsent which could simplify code for example in org.netbeans.modules.masterfs.filebasedfs.children.ChildrenSupport.lookupChildInCache
and in other places.
Comment 1 Vladimir Voskresensky 2010-12-03 21:29:22 UTC
Can you advise how to better proceed from hg and patch point of view?
I can move WeakSharedSet, but as I remember you wanted to replace WeakSet.
So my class should be WeakSet as well. 
But if I just replace content of WeakSet.java => diff will be awful and not readable at all.
May be it's better to have one commit which removes current WeakSet.java and next commit which add new WeakSet.java?
Comment 2 Vladimir Voskresensky 2010-12-03 21:37:26 UTC
note: we are talking about implementation of Set with weak keys and access to keys which is absent in usual Set classes.

http://hg.netbeans.org/cnd-main/file/tip/cnd.utils/src/org/netbeans/modules/cnd/utils/cache/WeakSharedSet.java

usual usecase of this class is like:

WeakSharedSet set;
Item shared = set.putIfAbsent(new Item());

putIfAbsent returns passed object if no equal element yet in set 
or return what is in set equal to passed object
Comment 3 Vladimir Voskresensky 2010-12-03 21:38:38 UTC
also our set uses smaller Entry impl comparing to current WeakSet
Comment 4 Jesse Glick 2010-12-04 15:36:17 UTC
(In reply to comment #1)
> Can you advise how to better proceed from hg and patch point of view?
> I can move WeakSharedSet, but as I remember you wanted to replace WeakSet.
> So my class should be WeakSet as well. 
> But if I just replace content of WeakSet.java => diff will be awful and not
> readable at all.
> May be it's better to have one commit which removes current WeakSet.java and
> next commit which add new WeakSet.java?

I think it can be one commit/patch:

hg rm openide.util/src/org/openide/util/WeakSet.java
hg mv cnd.utils/src/org/netbeans/modules/cnd/utils/cache/WeakSharedSet.java openide.util/src/org/openide/util/WeakSet.java
# fix up package decl, usages, ...

which 'hg di' ought to show as a removal plus a rename with minor diffs, since Hg remembers the provenance of the new version of the file. Try it anyway.
Comment 5 Vladimir Voskresensky 2010-12-11 21:54:03 UTC
Created attachment 103969 [details]
hg diff after (hg rm, hg mv, fix of names)
Comment 6 Vladimir Voskresensky 2010-12-11 21:54:47 UTC
Created attachment 103970 [details]
patch
Comment 7 Vladimir Voskresensky 2010-12-11 21:56:08 UTC
I think patch is unreadable. It is result of 
#hg rm
#hg mv
modifications
#hg ci -A -m 
#hg tip -p
Comment 8 Vladimir Voskresensky 2010-12-11 22:01:04 UTC
How do we prefer to proceed?
WeakSetTest passes with new impl. I can add test for new putIfAbsent method and after increasing spec versions integrate.
Comment 9 Vladimir Voskresensky 2010-12-13 09:18:28 UTC
remark: the current WeakSet implementation doesn't have internal concurrency check.
So, when I replace impl we should expect exceptions like issue #193312
Comment 11 Vladimir Voskresensky 2010-12-22 06:12:37 UTC
extra fix
http://hg.netbeans.org/cnd-main/rev/c11c3368dd18
Comment 12 Vladimir Voskresensky 2010-12-23 00:52:20 UTC
serializable and cloneable
http://hg.netbeans.org/cnd-main/rev/ba6077eca996
Comment 13 Jaroslav Tulach 2010-12-23 09:48:59 UTC
I am afraid the clone() method is not correctly implemented with respect to subclassing. If I look at HashSet.clone(), it will guarantee that this.getClass() == this.clone().getClass() I think people will expect the same from WeakSet too (unless there is something I am missing).
Comment 14 Vladimir Voskresensky 2010-12-23 10:45:42 UTC
Although implementation in old WeakSet has the same weak point, I agree with you and will improve the situation in new version.
Comment 15 Vladimir Voskresensky 2010-12-23 11:31:46 UTC
better clone with test
http://hg.netbeans.org/cnd-main/rev/7620423b8d35
Comment 16 Vladimir Voskresensky 2010-12-23 12:13:02 UTC
one more... to have same signatures (without thrown exception) for clone
http://hg.netbeans.org/cnd-main/rev/58d02418997a
Comment 17 Quality Engineering 2010-12-29 07:10:44 UTC
Integrated into 'main-golden', will be available in build *201012290001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/bc23d919ec47
User: Vladimir Voskresensky <vv159170@netbeans.org>
Log: remove old impl of WeakSet (#192759)
Comment 18 Quality Engineering 2011-01-09 06:23:43 UTC
Integrated into 'main-golden', will be available in build *201101090000* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/82810428149a
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #192759: Additional tweaks for double add of the same object. Caused duplicated events in FileSystem Event delivery mechanism