changeset 12321:d7bd49ad8f0a

8172461: Service Registration Lifecycle Reviewed-by: serb, vadim, skoivu, shurailine
author prr
date Mon, 06 Feb 2017 15:32:59 -0800
parents 09eae0bade20
children 51631f9fa8d8
files src/share/classes/javax/imageio/spi/ServiceRegistry.java
diffstat 1 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/imageio/spi/ServiceRegistry.java	Wed Dec 21 10:15:49 2016 -0500
+++ b/src/share/classes/javax/imageio/spi/ServiceRegistry.java	Mon Feb 06 15:32:59 2017 -0800
@@ -26,6 +26,9 @@
 package javax.imageio.spi;
 
 import java.io.File;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -701,11 +704,12 @@
 
     Class category;
 
-    // Provider Objects organized by partial oridering
-    PartiallyOrderedSet poset = new PartiallyOrderedSet();
+    // Provider Objects organized by partial ordering
+    final PartiallyOrderedSet poset = new PartiallyOrderedSet();
 
     // Class -> Provider Object of that class
-    Map<Class<?>,Object> map = new HashMap();
+    final Map<Class<?>,Object> map = new HashMap();
+    final Map<Class<?>,AccessControlContext> accMap = new HashMap<>();
 
     public SubRegistry(ServiceRegistry registry, Class category) {
         this.registry = registry;
@@ -720,6 +724,7 @@
             deregisterServiceProvider(oprovider);
         }
         map.put(provider.getClass(), provider);
+        accMap.put(provider.getClass(), AccessController.getContext());
         poset.add(provider);
         if (provider instanceof RegisterableService) {
             RegisterableService rs = (RegisterableService)provider;
@@ -739,6 +744,7 @@
 
         if (provider == oprovider) {
             map.remove(provider.getClass());
+            accMap.remove(provider.getClass());
             poset.remove(provider);
             if (provider instanceof RegisterableService) {
                 RegisterableService rs = (RegisterableService)provider;
@@ -785,10 +791,17 @@
 
             if (provider instanceof RegisterableService) {
                 RegisterableService rs = (RegisterableService)provider;
-                rs.onDeregistration(registry, category);
+                AccessControlContext acc = accMap.get(provider.getClass());
+                if (acc != null || System.getSecurityManager() == null) {
+                    AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+                    rs.onDeregistration(registry, category);
+                        return null;
+                    }, acc);
+                }
             }
         }
         poset.clear();
+        accMap.clear();
     }
 
     public void finalize() {