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 2019/09/10 12:20:51 UTC

[GitHub] [netbeans] matthiasblaesing commented on a change in pull request #1422: [NETBEANS-2940] Cache ArchiveRootProviders

matthiasblaesing commented on a change in pull request #1422: [NETBEANS-2940] Cache ArchiveRootProviders
URL: https://github.com/apache/netbeans/pull/1422#discussion_r322709540
 
 

 ##########
 File path: platform/openide.filesystems/src/org/openide/filesystems/FileUtil.java
 ##########
 @@ -2323,17 +2324,24 @@ private static boolean isArchiveFileImpl(final URL url, final boolean strict) {
     }
 
     private static Iterable<? extends ArchiveRootProvider> getArchiveRootProviders() {
-        Lookup.Result<ArchiveRootProvider> res = archiveRootProviders.get();
-        if (res == null) {
-            res = new ProxyLookup(
-                Lookups.singleton(new JarArchiveRootProvider()),
-                Lookup.getDefault()).lookupResult(ArchiveRootProvider.class);
-            if (!archiveRootProviders.compareAndSet(null, res)) {
-                res = archiveRootProviders.get();
+        if (archiveRootProviderCache == null) {
+            Lookup.Result<ArchiveRootProvider> res = archiveRootProviders.get();
+            if (res == null) {
+                res = new ProxyLookup(
+                    Lookups.singleton(new JarArchiveRootProvider()),
+                    Lookup.getDefault()).lookupResult(ArchiveRootProvider.class);
+                if (!archiveRootProviders.compareAndSet(null, res)) {
+                    res = archiveRootProviders.get();
+                    res.addLookupListener((ev) -> {
+                        archiveRootProviderCache = null;
+                    });
+                }
             }
+            archiveRootProviderCache = new LinkedList<>(res.allInstances());
         }
-        return res.allInstances();
+        return archiveRootProviderCache;
 
 Review comment:
   Why is this safe? If I'm reading it correctly after the first query no new ArchiveRootProvider will be found. So If at an unfortunate moment this is called before all ArchiveRootProviders are found (or they are loaded at runtime) this will return invalid results.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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