Skip to content

Commit 9d9ad96

Browse files
committedFeb 24, 2021
8261919: java/util/Locale/LocaleProvidersRun.java failed with "RuntimeException: Expected log was not emitted. LogRecord: null"
Reviewed-by: joehw, dfuchs
1 parent 2c99bad commit 9d9ad96

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed
 

‎test/jdk/java/util/Locale/LocaleProviders.java

+21-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
2929
import java.time.format.FormatStyle;
3030
import java.time.temporal.WeekFields;
3131
import java.util.*;
32+
import java.util.concurrent.CopyOnWriteArrayList;
3233
import java.util.logging.Level;
3334
import java.util.logging.LogRecord;
3435
import java.util.logging.StreamHandler;
@@ -398,22 +399,29 @@ static void bug8232860Test() {
398399
}
399400

400401
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() {
403417
@Override
404418
public void publish(LogRecord record) {
405-
lra[0] = record;
419+
logRecordList.add(record);
420+
System.out.println("LogRecord: " + record.getMessage());
406421
}
407422
};
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);
417425
}
418426
}
419427

‎test/jdk/java/util/Locale/LocaleProvidersRun.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
2626
* @bug 6336885 7196799 7197573 7198834 8000245 8000615 8001440 8008577
2727
* 8010666 8013086 8013233 8013903 8015960 8028771 8054482 8062006
2828
* 8150432 8215913 8220227 8228465 8232871 8232860 8236495 8245241
29-
* 8246721 8248695 8257964
29+
* 8246721 8248695 8257964 8261919
3030
* @summary tests for "java.locale.providers" system property
3131
* @library /test/lib
3232
* @build LocaleProviders
@@ -184,6 +184,7 @@ private static void testRun(String prefList, String methodName,
184184
.addToolArg("-esa")
185185
.addToolArg("-cp")
186186
.addToolArg(Utils.TEST_CLASS_PATH)
187+
.addToolArg("-Djava.util.logging.config.class=LocaleProviders$LogConfig")
187188
.addToolArg("-Djava.locale.providers=" + prefList)
188189
.addToolArg("--add-exports=java.base/sun.util.locale.provider=ALL-UNNAMED")
189190
.addToolArg("LocaleProviders")

0 commit comments

Comments
 (0)
Failed to load comments.