You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2022/12/07 08:51:32 UTC

[uima-uimaj] 01/01: #267 - UIMA Log4jLogger_impl not compatible with log4j 2.18.0+

This is an automated email from the ASF dual-hosted git repository.

rec pushed a commit to branch bugfix/267-UIMA-Log4jLogger_impl-not-compatible-with-log4j-2.18.0
in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git

commit c98e9c4c425e6f47de110d8b635156a40f6f24d7
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Wed Dec 7 09:51:24 2022 +0100

    #267 - UIMA Log4jLogger_impl not compatible with log4j 2.18.0+
    
    - Use reflection to pry-open a protected class that was previously public - frankly, this is not a good solution...
---
 .../org/apache/uima/util/impl/Log4jLogger_impl.java   | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/uimaj-core/src/main/java/org/apache/uima/util/impl/Log4jLogger_impl.java b/uimaj-core/src/main/java/org/apache/uima/util/impl/Log4jLogger_impl.java
index 1881df81a..7b6dd09c0 100644
--- a/uimaj-core/src/main/java/org/apache/uima/util/impl/Log4jLogger_impl.java
+++ b/uimaj-core/src/main/java/org/apache/uima/util/impl/Log4jLogger_impl.java
@@ -18,6 +18,7 @@
  */
 package org.apache.uima.util.impl;
 
+import java.lang.reflect.Field;
 import java.text.MessageFormat;
 
 import org.apache.logging.log4j.LogManager;
@@ -241,7 +242,23 @@ public class Log4jLogger_impl extends Logger_common_impl {
   }
 
   private static org.apache.logging.log4j.Marker m(Marker m) {
-    return (m == null) ? null : ((org.apache.logging.slf4j.Log4jMarker) m).getLog4jMarker();
+    if (m == null) {
+      return null;
+    }
+
+    Field markerField = null;
+    try {
+      markerField = m.getClass().getDeclaredField("marker");
+      markerField.setAccessible(true);
+      return (org.apache.logging.log4j.Marker) markerField.get(m);
+    } catch (Exception e) {
+      // Well, best effort...
+      return null;
+    } finally {
+      if (markerField != null) {
+        markerField.setAccessible(false);
+      }
+    }
   }
 
   /*