|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
29 | 29 | import java.time.format.FormatStyle;
|
30 | 30 | import java.time.temporal.WeekFields;
|
31 | 31 | import java.util.*;
|
| 32 | +import java.util.concurrent.CopyOnWriteArrayList; |
32 | 33 | import java.util.logging.Level;
|
33 | 34 | import java.util.logging.LogRecord;
|
34 | 35 | import java.util.logging.StreamHandler;
|
@@ -398,22 +399,29 @@ static void bug8232860Test() {
|
398 | 399 | }
|
399 | 400 |
|
400 | 401 | static void bug8245241Test(String expected) {
|
401 |
| - LogRecord[] lra = new LogRecord[1]; |
402 |
| - StreamHandler handler = new StreamHandler() { |
| 402 | + // this will ensure LocaleProviderAdapter initialization |
| 403 | + DateFormat.getDateInstance(); |
| 404 | + LogConfig.handler.flush(); |
| 405 | + |
| 406 | + if (LogConfig.logRecordList.stream() |
| 407 | + .noneMatch(r -> r.getLevel() == Level.INFO && |
| 408 | + r.getMessage().equals(expected))) { |
| 409 | + throw new RuntimeException("Expected log was not emitted."); |
| 410 | + } |
| 411 | + } |
| 412 | + |
| 413 | + // Set the root logger on loading the logging class |
| 414 | + public static class LogConfig { |
| 415 | + final static CopyOnWriteArrayList<LogRecord> logRecordList = new CopyOnWriteArrayList<>(); |
| 416 | + final static StreamHandler handler = new StreamHandler() { |
403 | 417 | @Override
|
404 | 418 | public void publish(LogRecord record) {
|
405 |
| - lra[0] = record; |
| 419 | + logRecordList.add(record); |
| 420 | + System.out.println("LogRecord: " + record.getMessage()); |
406 | 421 | }
|
407 | 422 | };
|
408 |
| - getLogManager().getLogger("").addHandler(handler); |
409 |
| - |
410 |
| - DateFormat.getDateInstance(); // this will init LocaleProviderAdapter |
411 |
| - handler.flush(); |
412 |
| - |
413 |
| - if (lra[0] == null || |
414 |
| - lra[0].getLevel() != Level.INFO || |
415 |
| - !lra[0].getMessage().equals(expected)) { |
416 |
| - throw new RuntimeException("Expected log was not emitted. LogRecord: " + lra[0]); |
| 423 | + static { |
| 424 | + getLogManager().getLogger("").addHandler(handler); |
417 | 425 | }
|
418 | 426 | }
|
419 | 427 |
|
|
0 commit comments