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:45:17 UTC

[GitHub] [netbeans] mbien commented on a diff in pull request #4130: Invoke correct overload of ReferenceQueue::remove

mbien commented on code in PR #4130:
URL: https://github.com/apache/netbeans/pull/4130#discussion_r878531439


##########
platform/openide.util.lookup/src/org/openide/util/lookup/implspi/ActiveQueue.java:
##########
@@ -67,7 +70,26 @@ public Reference<Object> remove() throws InterruptedException {
         }
         
         final Reference<? extends Object> removeSuper() throws InterruptedException {
-            return super.remove(0);
+            if(isReferenceQueueV2()) {
+                return super.remove();
+            } else {
+                return super.remove(0);
+            }
+        }
+
+        private static boolean isReferenceQueueV2() {
+            for(Class<?> member : Runtime.class.getDeclaredClasses()) {
+                if(member.getSimpleName().equals("Version")) {
+                    try {
+                        Object version = Runtime.class.getDeclaredMethod("version").invoke(null);
+                        int feature = (int) member.getDeclaredMethod("feature").invoke(version);
+                        return feature >= 19;
+                    } catch(ReflectiveOperationException e) {
+                        throw new AssertionError(e);
+                    }
+                }
+            }
+            return false;
         }

Review Comment:
   can you put this into a static final field and add a short comment that the JDK impl changed in 19?
   
   example:
   
   ```java
   private static final boolean jdk19 = is19();
   
   ...
        if (jdk19) {
   ...
   ```
   
   this would make it JDK 8 compatible:
   ```java
       private static boolean is19() {
           // TODO remove reflection post JDK 11 migration
           try {
               Object version = Runtime.class.getDeclaredMethod("version").invoke(null);
               int feature = (int) version.getClass().getDeclaredMethod("feature").invoke(version);
               return feature >= 19;
           } catch (NoSuchMethodException e) {
               return false; // JDK 8
           } catch (ReflectiveOperationException e) {
               throw new AssertionError(e);
           }
       }
   ```
   
   regarding your question if there is an API for that, unfortunately not. Usually NB only cares about javac versions, which is easier to figure out via the `SourceVersion` class, but we can't do that here, because we patch javac to a recent version via nb-javac no matter what runtime JDK is in use, so it would always return true.



-- 
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