changeset 16227:7e27a1e6e339

8170664: SystemLoggerInPlatformLoader.java failing in case of module limitation Reviewed-by: dfuchs, mchung
author skovalev
date Thu, 08 Dec 2016 15:35:56 +0300
parents 8a0ce9899148
children ed04e8712261
files test/java/lang/System/LoggerFinder/internal/SystemLoggerInPlatformLoader/SystemLoggerInPlatformLoader.java
diffstat 1 files changed, 27 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/lang/System/LoggerFinder/internal/SystemLoggerInPlatformLoader/SystemLoggerInPlatformLoader.java	Thu Dec 08 12:35:18 2016 +0530
+++ b/test/java/lang/System/LoggerFinder/internal/SystemLoggerInPlatformLoader/SystemLoggerInPlatformLoader.java	Thu Dec 08 15:35:56 2016 +0300
@@ -28,9 +28,10 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Layer;
 import java.lang.reflect.Method;
 
-/**
+/*
  * @test 8163162
  * @summary Checks that LazyLoggers are returned for System.Logger instances
  *          created by modules in the platform class loader.
@@ -98,25 +99,36 @@
     }
 
     public static void main(String[] args) {
-        System.Logger splogger = getSystemLogger("bar"); // for a platform class
-        System.Logger slogger = System.getLogger("bar"); // for an application class
-        if (slogger == splogger) {
+        System.Logger platformLogger = getSystemLogger("bar"); // for a platform class
+        System.Logger appLogger = System.getLogger("bar"); // for an application class
+        if (appLogger == platformLogger) {
             throw new RuntimeException("Same loggers");
         }
-        Class sploggerType = splogger.getClass();
-        System.out.println("splogger: " + sploggerType);
-        if (!sploggerType.getSimpleName().equals("JdkLazyLogger")) {
-            throw new RuntimeException(sploggerType.getSimpleName()
-                      + ": unexpected class for splogger"
+        Class<?> platformLoggerType = platformLogger.getClass();
+        System.out.println("platformLogger: " + platformLoggerType);
+        boolean simpleConsoleOnly = !Layer.boot().findModule("java.logging").isPresent();
+        if (simpleConsoleOnly) {
+            /* Happens if the test is called with custom JDK without java.logging module
+               or in case usage commandline option --limit-modules java.base */
+            if (!platformLoggerType.getSimpleName().equals("SimpleConsoleLogger")) {
+                throw new RuntimeException(platformLoggerType.getSimpleName()
+                      + ": unexpected class for platform logger"
+                      + " (expected a simple console logger class)");
+            }
+        } else {
+            if (!platformLoggerType.getSimpleName().equals("JdkLazyLogger")) {
+                throw new RuntimeException(platformLoggerType.getSimpleName()
+                      + ": unexpected class for platform logger"
                       + " (expected a lazy logger for a platform class)");
-        }
-        Class sloggerType = slogger.getClass();
-        System.out.println("slogger: " + sloggerType);
-        if (sloggerType.equals(sploggerType)) {
-            throw new RuntimeException(sloggerType
-                      + ": unexpected class for slogger"
+            }
+            Class<?> appLoggerType = appLogger.getClass();
+            System.out.println("appLogger: " + appLoggerType);
+            if (appLoggerType.equals(platformLoggerType)) {
+                throw new RuntimeException(appLoggerType
+                      + ": unexpected class for application logger"
                       + " (a lazy logger was not expected"
                       + " for a non platform class)");
+            }
         }
     }
 }