From e409d07ae84c693b656c02befb636593f9293635 Mon Sep 17 00:00:00 2001 From: Sean Coffey Date: Fri, 8 Sep 2023 14:25:58 +0000 Subject: [PATCH] 8315696: SignedLoggerFinderTest.java test failed Co-authored-by: Daniel Fuchs Reviewed-by: dfuchs --- .../RecursiveLoading/PlatformRecursiveLoadingTest.java | 7 ++++--- .../RecursiveLoading/RecursiveLoadingTest.java | 4 ++++ .../SignedLoggerFinderTest/SignedLoggerFinderTest.java | 7 ++++++- .../internal/BootstrapLogger/BootstrapLoggerAPIsTest.java | 7 ++++--- .../internal/BootstrapLogger/BootstrapLoggerTest.java | 5 +++-- .../LoggerFinder/internal/BootstrapLogger/LogStream.java | 4 +--- .../BootstrapLogger => lib}/BootstrapLoggerUtils.java | 8 ++++---- 7 files changed, 26 insertions(+), 16 deletions(-) rename test/jdk/java/lang/System/LoggerFinder/{internal/BootstrapLogger => lib}/BootstrapLoggerUtils.java (89%) diff --git a/test/jdk/java/lang/System/LoggerFinder/RecursiveLoading/PlatformRecursiveLoadingTest.java b/test/jdk/java/lang/System/LoggerFinder/RecursiveLoading/PlatformRecursiveLoadingTest.java index 9865523e127..43c00050d2f 100644 --- a/test/jdk/java/lang/System/LoggerFinder/RecursiveLoading/PlatformRecursiveLoadingTest.java +++ b/test/jdk/java/lang/System/LoggerFinder/RecursiveLoading/PlatformRecursiveLoadingTest.java @@ -26,13 +26,12 @@ * @bug 8314263 * @summary Creating a logger while loading the Logger finder * triggers recursion and StackOverflowError - * @modules java.base/sun.util.logging - * @library /test/lib + * @modules java.base/sun.util.logging java.base/jdk.internal.logger:+open + * @library ../lib * @compile RecursiveLoadingTest.java SimpleLoggerFinder.java * @run main/othervm PlatformRecursiveLoadingTest */ - import java.time.Instant; import java.util.Arrays; import java.util.List; @@ -50,6 +49,8 @@ public class PlatformRecursiveLoadingTest { */ public static void main(String[] args) throws Throwable { PlatformLogger.getLogger("main").info("in main"); + // allow time to let bootstrap logger flush data + BootstrapLoggerUtils.awaitPending(); List logs = loggerfinder.SimpleLoggerFinder.LOGS; logs.stream().map(SimpleLogRecord::of).forEach(System.out::println); logs.stream().map(SimpleLogRecord::of).forEach(SimpleLogRecord::check); diff --git a/test/jdk/java/lang/System/LoggerFinder/RecursiveLoading/RecursiveLoadingTest.java b/test/jdk/java/lang/System/LoggerFinder/RecursiveLoading/RecursiveLoadingTest.java index 4a7d2b397c5..014d9be457d 100644 --- a/test/jdk/java/lang/System/LoggerFinder/RecursiveLoading/RecursiveLoadingTest.java +++ b/test/jdk/java/lang/System/LoggerFinder/RecursiveLoading/RecursiveLoadingTest.java @@ -26,6 +26,8 @@ * @bug 8314263 * @summary Creating a logger while loading the Logger finder * triggers recursion and StackOverflowError + * @modules java.base/jdk.internal.logger:+open + * @library ../lib * @compile RecursiveLoadingTest.java SimpleLoggerFinder.java * @run main/othervm RecursiveLoadingTest */ @@ -45,6 +47,8 @@ public class RecursiveLoadingTest { */ public static void main(String[] args) throws Throwable { System.getLogger("main").log(System.Logger.Level.INFO, "in main"); + // allow time to let bootstrap logger flush data + BootstrapLoggerUtils.awaitPending(); List logs = loggerfinder.SimpleLoggerFinder.LOGS; logs.stream().map(SimpleLogRecord::of).forEach(System.out::println); logs.stream().map(SimpleLogRecord::of).forEach(SimpleLogRecord::check); diff --git a/test/jdk/java/lang/System/LoggerFinder/SignedLoggerFinderTest/SignedLoggerFinderTest.java b/test/jdk/java/lang/System/LoggerFinder/SignedLoggerFinderTest/SignedLoggerFinderTest.java index f7b8a316b7f..f452d2ef0ad 100644 --- a/test/jdk/java/lang/System/LoggerFinder/SignedLoggerFinderTest/SignedLoggerFinderTest.java +++ b/test/jdk/java/lang/System/LoggerFinder/SignedLoggerFinderTest/SignedLoggerFinderTest.java @@ -25,7 +25,8 @@ * @test * @bug 8314263 * @summary Signed jars triggering Logger finder recursion and StackOverflowError - * @library /test/lib + * @modules java.base/jdk.internal.logger:+open + * @library /test/lib ../lib * @build jdk.test.lib.compiler.CompilerUtils * jdk.test.lib.process.* * jdk.test.lib.util.JarUtils @@ -146,6 +147,8 @@ public class SignedLoggerFinderTest { // LoggerFinder should be initialized, trigger a simple log call Security.setProperty("test_2", "test"); + // allow time to let bootstrap logger flush data + BootstrapLoggerUtils.awaitPending(); } } @@ -165,6 +168,8 @@ public class SignedLoggerFinderTest { System.getProperty("test.classes"))); } cmds.addAll(List.of( + // allow test to access internal bootstrap logger functionality + "--add-opens=java.base/jdk.internal.logger=ALL-UNNAMED", // following debug property seems useful to tickle the issue "-Dsun.misc.URLClassPath.debug=true", // console logger level to capture event output diff --git a/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerAPIsTest.java b/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerAPIsTest.java index 19b100960e5..d38d0943928 100644 --- a/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerAPIsTest.java +++ b/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerAPIsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, 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,7 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.Enumeration; import java.util.List; import java.util.ResourceBundle; -import java.util.Set; + import jdk.internal.logger.BootstrapLogger; import jdk.internal.logger.LazyLoggers; @@ -38,9 +38,10 @@ import jdk.internal.logger.LazyLoggers; * @bug 8144460 8144214 * @summary Cover the logXX and LogEvent.valueOf APIs of BootstrapLogger * and logXX APIs of SimpleConsoleLogger. + * @library ../../lib * @modules java.base/jdk.internal.logger:+open * java.base/sun.util.logging - * @build BootstrapLoggerUtils LogStream + * @build LogStream * @run main/othervm BootstrapLoggerAPIsTest */ diff --git a/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerTest.java b/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerTest.java index 3ddf32f12df..9f17478f35f 100644 --- a/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerTest.java +++ b/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023, 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 @@ -53,9 +53,10 @@ import jdk.internal.logger.LazyLoggers; * @summary JDK implementation specific unit test for JDK internal artifacts. Tests the behavior of bootstrap loggers (and SimpleConsoleLoggers * too). + * @library ../../lib * @modules java.base/jdk.internal.logger:+open * java.logging - * @build BootstrapLoggerUtils LogStream + * @build LogStream * @run main/othervm BootstrapLoggerTest NO_SECURITY * @run main/othervm -Djava.security.manager=allow BootstrapLoggerTest SECURE * @run main/othervm/timeout=120 -Djava.security.manager=allow BootstrapLoggerTest SECURE_AND_WAIT diff --git a/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/LogStream.java b/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/LogStream.java index d6e218a2a43..a7f20fc7948 100644 --- a/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/LogStream.java +++ b/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/LogStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, 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 @@ -25,8 +25,6 @@ import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.io.PrintStream; -import jdk.internal.logger.BootstrapLogger; - /** * We use an instance of this class to check what the logging system has printed * on System.err. diff --git a/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerUtils.java b/test/jdk/java/lang/System/LoggerFinder/lib/BootstrapLoggerUtils.java similarity index 89% rename from test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerUtils.java rename to test/jdk/java/lang/System/LoggerFinder/lib/BootstrapLoggerUtils.java index 0e78b588e99..2e551f94491 100644 --- a/test/jdk/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerUtils.java +++ b/test/jdk/java/lang/System/LoggerFinder/lib/BootstrapLoggerUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, 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 @@ -28,7 +28,7 @@ import java.util.function.BooleanSupplier; import jdk.internal.logger.BootstrapLogger; -class BootstrapLoggerUtils { +public final class BootstrapLoggerUtils { private static final Field IS_BOOTED; private static final Method AWAIT_PENDING; @@ -46,11 +46,11 @@ class BootstrapLoggerUtils { } } - static void setBootedHook(BooleanSupplier supplier) throws IllegalAccessException { + public static void setBootedHook(BooleanSupplier supplier) throws IllegalAccessException { IS_BOOTED.set(null, supplier); } - static void awaitPending() { + public static void awaitPending() { try { AWAIT_PENDING.invoke(null); } catch (IllegalAccessException | IllegalArgumentException