|
26 | 26 |
|
27 | 27 | import java.io.IOException;
|
28 | 28 | import java.net.URL;
|
29 |
| -import java.security.AccessControlException; |
30 |
| -import java.security.AccessController; |
31 |
| -import java.security.PrivilegedAction; |
32 | 29 | import java.util.ArrayList;
|
33 | 30 | import java.util.Arrays;
|
34 | 31 | import java.util.Enumeration;
|
@@ -104,24 +101,27 @@ public final class LoggerFactory {
|
104 | 101 |
|
105 | 102 | // Package access for tests
|
106 | 103 | static List<SLF4JServiceProvider> findServiceProviders() {
|
107 |
| - final ClassLoader cl = LoggerFactory.class.getClassLoader(); |
108 |
| - final PrivilegedAction<ServiceLoader<SLF4JServiceProvider>> action = () -> ServiceLoader.load(SLF4JServiceProvider.class, cl); |
109 |
| - final ServiceLoader<SLF4JServiceProvider> serviceLoader = System.getSecurityManager() != null |
110 |
| - ? AccessController.doPrivileged(action) |
111 |
| - : action.run(); |
| 104 | + // retain behaviour similar to that of 1.7 series and earlier. More specifically, use the class loader that |
| 105 | + // loaded the present class to search for services |
| 106 | + final ClassLoader classLoaderOfLoggerFactory = LoggerFactory.class.getClassLoader(); |
| 107 | + ServiceLoader<SLF4JServiceProvider> serviceLoader = ServiceLoader.load(SLF4JServiceProvider.class, classLoaderOfLoggerFactory); |
112 | 108 | List<SLF4JServiceProvider> providerList = new ArrayList<>();
|
113 | 109 | Iterator<SLF4JServiceProvider> iterator = serviceLoader.iterator();
|
114 | 110 | while (iterator.hasNext()) {
|
115 |
| - try { |
116 |
| - providerList.add(iterator.next()); |
117 |
| - } catch (ServiceConfigurationError | AccessControlException e) { |
118 |
| - // Short warning |
119 |
| - Util.report("A SLF4J service provider failed to instantiate:\n" + e.getMessage()); |
120 |
| - } |
| 111 | + safelyInstantiate(providerList, iterator); |
121 | 112 | }
|
122 | 113 | return providerList;
|
123 | 114 | }
|
124 | 115 |
|
| 116 | + private static void safelyInstantiate(List<SLF4JServiceProvider> providerList, Iterator<SLF4JServiceProvider> iterator) { |
| 117 | + try { |
| 118 | + SLF4JServiceProvider provider = iterator.next(); |
| 119 | + providerList.add(provider); |
| 120 | + } catch (ServiceConfigurationError e) { |
| 121 | + Util.report("A SLF4J service provider failed to instantiate:\n" + e.getMessage()); |
| 122 | + } |
| 123 | + } |
| 124 | + |
125 | 125 | /**
|
126 | 126 | * It is LoggerFactory's responsibility to track version changes and manage
|
127 | 127 | * the compatibility list.
|
|
0 commit comments