提交 f02b149f 编写于 作者: P prr

8172461: Service Registration Lifecycle

Reviewed-by: serb, vadim, skoivu, shurailine
上级 7fe61077
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
package javax.imageio.spi; package javax.imageio.spi;
import java.io.File; import java.io.File;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
...@@ -701,11 +704,12 @@ class SubRegistry { ...@@ -701,11 +704,12 @@ class SubRegistry {
Class category; Class category;
// Provider Objects organized by partial oridering // Provider Objects organized by partial ordering
PartiallyOrderedSet poset = new PartiallyOrderedSet(); final PartiallyOrderedSet poset = new PartiallyOrderedSet();
// Class -> Provider Object of that class // 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) { public SubRegistry(ServiceRegistry registry, Class category) {
this.registry = registry; this.registry = registry;
...@@ -720,6 +724,7 @@ class SubRegistry { ...@@ -720,6 +724,7 @@ class SubRegistry {
deregisterServiceProvider(oprovider); deregisterServiceProvider(oprovider);
} }
map.put(provider.getClass(), provider); map.put(provider.getClass(), provider);
accMap.put(provider.getClass(), AccessController.getContext());
poset.add(provider); poset.add(provider);
if (provider instanceof RegisterableService) { if (provider instanceof RegisterableService) {
RegisterableService rs = (RegisterableService)provider; RegisterableService rs = (RegisterableService)provider;
...@@ -739,6 +744,7 @@ class SubRegistry { ...@@ -739,6 +744,7 @@ class SubRegistry {
if (provider == oprovider) { if (provider == oprovider) {
map.remove(provider.getClass()); map.remove(provider.getClass());
accMap.remove(provider.getClass());
poset.remove(provider); poset.remove(provider);
if (provider instanceof RegisterableService) { if (provider instanceof RegisterableService) {
RegisterableService rs = (RegisterableService)provider; RegisterableService rs = (RegisterableService)provider;
...@@ -785,10 +791,17 @@ class SubRegistry { ...@@ -785,10 +791,17 @@ class SubRegistry {
if (provider instanceof RegisterableService) { if (provider instanceof RegisterableService) {
RegisterableService rs = (RegisterableService)provider; 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(); poset.clear();
accMap.clear();
} }
public void finalize() { public void finalize() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册