neilcsmith-net commented on code in PR #6596:
URL: https://github.com/apache/netbeans/pull/6596#discussion_r1368353056


##########
enterprise/glassfish.common/src/org/netbeans/modules/glassfish/common/LogViewMgr.java:
##########
@@ -135,14 +147,11 @@ private LogViewMgr(final String uri) {
      */
     public static LogViewMgr getInstance(String uri) {
         LogViewMgr logViewMgr;
-        synchronized (instances) {
-            WeakReference<LogViewMgr> viewRef = instances.get(uri);
-            logViewMgr = viewRef != null ? viewRef.get() : null;
-            if(logViewMgr == null) {
-                logViewMgr = new LogViewMgr(uri);
-                instances.put(uri, new WeakReference<LogViewMgr>(logViewMgr));
-            }
-        }
+        
+        logViewMgr = instances.computeIfAbsent(uri, key -> 
+                        new WeakReference<LogViewMgr>(new LogViewMgr(uri))
+                    ).get();

Review Comment:
   Yes, both these things need fixing. Using `new` in the arguments to a 
`WeakReference` should _always_ be considered an anti-pattern.  I mean, the 
language doesn't even guarantee not to garbage collect an object before the 
constructor has finished! :wink:  The strong reference needs to be held, and 
the reference needs checking on every retrieval.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to