180 // 1. Test loggers returned by LoggerFinder, both for system callers |
180 // 1. Test loggers returned by LoggerFinder, both for system callers |
181 // and not system callers. |
181 // and not system callers. |
182 TestLoggerFinder.LoggerImpl appLogger1 = null; |
182 TestLoggerFinder.LoggerImpl appLogger1 = null; |
183 try { |
183 try { |
184 appLogger1 = |
184 appLogger1 = |
185 TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerFinderTest.class)); |
185 TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerFinderTest.class.getModule())); |
186 loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", BaseLoggerFinderTest.class)"); |
186 loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", BaseLoggerFinderTest.class.getModule())"); |
187 if (!hasRequiredPermissions) { |
187 if (!hasRequiredPermissions) { |
188 throw new RuntimeException("Managed to obtain a logger without permission"); |
188 throw new RuntimeException("Managed to obtain a logger without permission"); |
189 } |
189 } |
190 } catch (AccessControlException acx) { |
190 } catch (AccessControlException acx) { |
191 if (hasRequiredPermissions) { |
191 if (hasRequiredPermissions) { |
197 System.out.println("Got expected exception for logger: " + acx); |
197 System.out.println("Got expected exception for logger: " + acx); |
198 final boolean old = allowControl.get().get(); |
198 final boolean old = allowControl.get().get(); |
199 allowControl.get().set(true); |
199 allowControl.get().set(true); |
200 try { |
200 try { |
201 appLogger1 = |
201 appLogger1 = |
202 TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerFinderTest.class)); |
202 TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerFinderTest.class.getModule())); |
203 loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", BaseLoggerFinderTest.class)"); |
203 loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", BaseLoggerFinderTest.class.getModule())"); |
204 } finally { |
204 } finally { |
205 allowControl.get().set(old); |
205 allowControl.get().set(old); |
206 } |
206 } |
207 } |
207 } |
208 |
208 |
209 TestLoggerFinder.LoggerImpl sysLogger1 = null; |
209 TestLoggerFinder.LoggerImpl sysLogger1 = null; |
210 try { |
210 try { |
211 sysLogger1 = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class)); |
211 sysLogger1 = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class.getModule())); |
212 loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class)"); |
212 loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class.getModule())"); |
213 if (!hasRequiredPermissions) { |
213 if (!hasRequiredPermissions) { |
214 throw new RuntimeException("Managed to obtain a system logger without permission"); |
214 throw new RuntimeException("Managed to obtain a system logger without permission"); |
215 } |
215 } |
216 } catch (AccessControlException acx) { |
216 } catch (AccessControlException acx) { |
217 if (hasRequiredPermissions) { |
217 if (hasRequiredPermissions) { |
222 } |
222 } |
223 System.out.println("Got expected exception for system logger: " + acx); |
223 System.out.println("Got expected exception for system logger: " + acx); |
224 final boolean old = allowControl.get().get(); |
224 final boolean old = allowControl.get().get(); |
225 allowControl.get().set(true); |
225 allowControl.get().set(true); |
226 try { |
226 try { |
227 sysLogger1 = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class)); |
227 sysLogger1 = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class.getModule())); |
228 loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class)"); |
228 loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class.getModule())"); |
229 } finally { |
229 } finally { |
230 allowControl.get().set(old); |
230 allowControl.get().set(old); |
231 } |
231 } |
232 } |
232 } |
233 if (appLogger1 == sysLogger1) { |
233 if (appLogger1 == sysLogger1) { |
252 |
252 |
253 // 2. Test localized loggers returned LoggerFinder, both for system |
253 // 2. Test localized loggers returned LoggerFinder, both for system |
254 // callers and non system callers |
254 // callers and non system callers |
255 Logger appLogger2 = null; |
255 Logger appLogger2 = null; |
256 try { |
256 try { |
257 appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, BaseLoggerFinderTest.class); |
257 appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, BaseLoggerFinderTest.class.getModule()); |
258 loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, BaseLoggerFinderTest.class)"); |
258 loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, BaseLoggerFinderTest.class.getModule())"); |
259 if (!hasRequiredPermissions) { |
259 if (!hasRequiredPermissions) { |
260 throw new RuntimeException("Managed to obtain a logger without permission"); |
260 throw new RuntimeException("Managed to obtain a logger without permission"); |
261 } |
261 } |
262 } catch (AccessControlException acx) { |
262 } catch (AccessControlException acx) { |
263 if (hasRequiredPermissions) { |
263 if (hasRequiredPermissions) { |
268 } |
268 } |
269 System.out.println("Got expected exception for logger: " + acx); |
269 System.out.println("Got expected exception for logger: " + acx); |
270 final boolean old = allowControl.get().get(); |
270 final boolean old = allowControl.get().get(); |
271 allowControl.get().set(true); |
271 allowControl.get().set(true); |
272 try { |
272 try { |
273 appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, BaseLoggerFinderTest.class); |
273 appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, BaseLoggerFinderTest.class.getModule()); |
274 loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, BaseLoggerFinderTest.class)"); |
274 loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, BaseLoggerFinderTest.class.getModule())"); |
275 } finally { |
275 } finally { |
276 allowControl.get().set(old); |
276 allowControl.get().set(old); |
277 } |
277 } |
278 } |
278 } |
279 |
279 |
280 Logger sysLogger2 = null; |
280 Logger sysLogger2 = null; |
281 try { |
281 try { |
282 sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class); |
282 sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class.getModule()); |
283 loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class)"); |
283 loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class.getModule())"); |
284 if (!hasRequiredPermissions) { |
284 if (!hasRequiredPermissions) { |
285 throw new RuntimeException("Managed to obtain a system logger without permission"); |
285 throw new RuntimeException("Managed to obtain a system logger without permission"); |
286 } |
286 } |
287 } catch (AccessControlException acx) { |
287 } catch (AccessControlException acx) { |
288 if (hasRequiredPermissions) { |
288 if (hasRequiredPermissions) { |
293 } |
293 } |
294 System.out.println("Got expected exception for localized system logger: " + acx); |
294 System.out.println("Got expected exception for localized system logger: " + acx); |
295 final boolean old = allowControl.get().get(); |
295 final boolean old = allowControl.get().get(); |
296 allowControl.get().set(true); |
296 allowControl.get().set(true); |
297 try { |
297 try { |
298 sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class); |
298 sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class.getModule()); |
299 loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class))"); |
299 loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class.getModule()))"); |
300 } finally { |
300 } finally { |
301 allowControl.get().set(old); |
301 allowControl.get().set(old); |
302 } |
302 } |
303 } |
303 } |
304 if (appLogger2 == sysLogger2) { |
304 if (appLogger2 == sysLogger2) { |