You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/05/20 20:19:16 UTC

[GitHub] [netbeans] matthiasblaesing commented on pull request #4130: Invoke correct overload of ReferenceQueue::remove

matthiasblaesing commented on PR #4130:
URL: https://github.com/apache/netbeans/pull/4130#issuecomment-1133322110

   I think we should stay away from the implementation details of the JDK. It _always_ comes back to haunt us. If I read the implementation correctly, the idea is, that only the implementation inside the Lookup API should be able to `remove` from the `ReferenceQueue`. So why not change the guard method (untested!):
   
   ```diff
   # This patch file was generated by NetBeans IDE
   # It uses platform neutral UTF-8 encoding and \n newlines.
   --- a/platform/openide.util.lookup/src/org/openide/util/lookup/implspi/ActiveQueue.java
   +++ b/platform/openide.util.lookup/src/org/openide/util/lookup/implspi/ActiveQueue.java
   @@ -48,6 +48,8 @@
    
        private static final class Impl extends ReferenceQueue<Object> {
            
   +        private ThreadLocal<Boolean> accessOk = new ThreadLocal<>();
   +
            Impl() {
            }
    
   @@ -58,18 +60,31 @@
    
            @Override
            public Reference<Object> remove(long timeout) throws IllegalArgumentException, InterruptedException {
   +            if(accessOk.get() != null && accessOk.get()) {
   +                return (Reference<Object>) super.remove(timeout);
   +            } else {
                throw new InterruptedException();
            }
   +        }
    
            @Override
            public Reference<Object> remove() throws InterruptedException {
   +            if(accessOk.get() != null && accessOk.get()) {
   +                return (Reference<Object>) super.remove();
   +            } else {
                throw new InterruptedException();
            }
   +        }
            
            final Reference<? extends Object> removeSuper() throws InterruptedException {
   -            return super.remove(0);
   +            accessOk.set(Boolean.TRUE);
   +            try {
   +                return super.remove();
   +            } finally {
   +                accessOk.set(Boolean.FALSE);
            }
        }
   +    }
    
        private static final class Daemon extends Thread {
            private static boolean initialized;
   
   ```
   
   The permitted callers can come though `removeSuper` and are cleared, while public callers will not get through the `accessOk`check. Another alternative would be to store the thread, that is working the reference queue and reject all calls not from that thread.
   


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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