From daee16a014eaf7276e6dc35dfe0e9638ddaf9c1b Mon Sep 17 00:00:00 2001 From: Phil Race Date: Mon, 6 Feb 2017 15:31:37 -0800 Subject: [PATCH] 8172461: Service Registration Lifecycle Reviewed-by: serb, vadim, skoivu, shurailine --- .../javax/imageio/spi/ServiceRegistry.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/jdk/src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java b/jdk/src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java index 0d87431fbbf..ae3b643215d 100644 --- a/jdk/src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java +++ b/jdk/src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java @@ -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; @@ -755,13 +758,14 @@ class SubRegistry { 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 // No way to express heterogeneous map, we want // Map, T>, where T is ? - Map, Object> map = new HashMap<>(); + final Map, Object> map = new HashMap<>(); + final Map, AccessControlContext> accMap = new HashMap<>(); public SubRegistry(ServiceRegistry registry, Class category) { this.registry = registry; @@ -776,6 +780,7 @@ class SubRegistry { deregisterServiceProvider(oprovider); } map.put(provider.getClass(), provider); + accMap.put(provider.getClass(), AccessController.getContext()); poset.add(provider); if (provider instanceof RegisterableService) { RegisterableService rs = (RegisterableService)provider; @@ -800,6 +805,7 @@ class SubRegistry { if (provider == oprovider) { map.remove(provider.getClass()); + accMap.remove(provider.getClass()); poset.remove(provider); if (provider instanceof RegisterableService) { RegisterableService rs = (RegisterableService)provider; @@ -849,10 +855,17 @@ class SubRegistry { 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) () -> { + rs.onDeregistration(registry, category); + return null; + }, acc); + } } } poset.clear(); + accMap.clear(); } @SuppressWarnings("deprecation")