From 74f33164ff9efbb8a7926809c7115ee1fbf6ec91 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 6 Sep 2023 10:14:48 +0200 Subject: [PATCH 1/2] Do not warn if sun.reflect.Reflection.getCallerClass() is unavailable Modern Java releases disallow the access to internal sun.* API. There is not much the user can do about it, hence this warning is not actionable and therefore unneeded. It also does not tag its origin, causing confusion among users about its whereabouts. --- .../main/java/org/apache/logging/log4j/util/StackLocator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java index bf285d14030..bacb0c18d8b 100644 --- a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java +++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java @@ -77,7 +77,6 @@ public final class StackLocator { } } } catch (final Exception | LinkageError e) { - System.out.println("WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance."); getCallerClassMethod = null; java7u25CompensationOffset = -1; } From c9ef4695afa097c56609cf5e84e9b820f88c4eeb Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Wed, 6 Sep 2023 15:37:29 +0200 Subject: [PATCH 2/2] Differentiate warning by Java version --- .../org/apache/logging/log4j/util/StackLocator.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java index bacb0c18d8b..2ee943185e5 100644 --- a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java +++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java @@ -72,11 +72,19 @@ public final class StackLocator { } else { o = getCallerClassMethod.invoke(null, 1); if (o == sunReflectionClass) { - System.out.println("WARNING: Unexpected result from sun.reflect.Reflection.getCallerClass(int), adjusting offset for future calls."); + LowLevelLogUtil.log( + "WARNING: Unexpected result from sun.reflect.Reflection.getCallerClass(int), adjusting offset for future calls."); java7u25CompensationOffset = 1; } } } catch (final Exception | LinkageError e) { + if (Constants.JAVA_MAJOR_VERSION > 8) { + LowLevelLogUtil.log( + "WARNING: Runtime environment does not support multi-release JARs. This will impact location-based features."); + } else { + LowLevelLogUtil.log( + "WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact location-based features."); + } getCallerClassMethod = null; java7u25CompensationOffset = -1; }