Skip to content
Permalink
Browse files
8261919: java/util/Locale/LocaleProvidersRun.java failed with "Runtim…
…eException: Expected log was not emitted. LogRecord: null"

Reviewed-by: joehw, dfuchs
  • Loading branch information
naotoj committed Feb 24, 2021
1 parent 2c99bad commit 9d9ad969cae7be97263c0d32e1d10fe59b728cb2
Showing with 24 additions and 15 deletions.
  1. +21 −13 test/jdk/java/util/Locale/LocaleProviders.java
  2. +3 −2 test/jdk/java/util/Locale/LocaleProvidersRun.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
import java.time.format.FormatStyle;
import java.time.temporal.WeekFields;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.StreamHandler;
@@ -398,22 +399,29 @@ static void bug8232860Test() {
}

static void bug8245241Test(String expected) {
LogRecord[] lra = new LogRecord[1];
StreamHandler handler = new StreamHandler() {
// this will ensure LocaleProviderAdapter initialization
DateFormat.getDateInstance();
LogConfig.handler.flush();

if (LogConfig.logRecordList.stream()
.noneMatch(r -> r.getLevel() == Level.INFO &&
r.getMessage().equals(expected))) {
throw new RuntimeException("Expected log was not emitted.");
}
}

// Set the root logger on loading the logging class
public static class LogConfig {
final static CopyOnWriteArrayList<LogRecord> logRecordList = new CopyOnWriteArrayList<>();
final static StreamHandler handler = new StreamHandler() {
@Override
public void publish(LogRecord record) {
lra[0] = record;
logRecordList.add(record);
System.out.println("LogRecord: " + record.getMessage());
}
};
getLogManager().getLogger("").addHandler(handler);

DateFormat.getDateInstance(); // this will init LocaleProviderAdapter
handler.flush();

if (lra[0] == null ||
lra[0].getLevel() != Level.INFO ||
!lra[0].getMessage().equals(expected)) {
throw new RuntimeException("Expected log was not emitted. LogRecord: " + lra[0]);
static {
getLogManager().getLogger("").addHandler(handler);
}
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
* @bug 6336885 7196799 7197573 7198834 8000245 8000615 8001440 8008577
* 8010666 8013086 8013233 8013903 8015960 8028771 8054482 8062006
* 8150432 8215913 8220227 8228465 8232871 8232860 8236495 8245241
* 8246721 8248695 8257964
* 8246721 8248695 8257964 8261919
* @summary tests for "java.locale.providers" system property
* @library /test/lib
* @build LocaleProviders
@@ -184,6 +184,7 @@ private static void testRun(String prefList, String methodName,
.addToolArg("-esa")
.addToolArg("-cp")
.addToolArg(Utils.TEST_CLASS_PATH)
.addToolArg("-Djava.util.logging.config.class=LocaleProviders$LogConfig")
.addToolArg("-Djava.locale.providers=" + prefList)
.addToolArg("--add-exports=java.base/sun.util.locale.provider=ALL-UNNAMED")
.addToolArg("LocaleProviders")

1 comment on commit 9d9ad96

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 9d9ad96 Feb 24, 2021

Please sign in to comment.