File logback-1.2.3-getCallerClass.patch of Package logback.28016

--- logback-1.2.3/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java	2019-11-29 12:40:38.797022563 +0100
+++ logback-1.2.3/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java	2019-11-29 13:11:30.783272712 +0100
@@ -17,7 +17,8 @@
 import java.security.CodeSource;
 import java.util.HashMap;
 
-import sun.reflect.Reflection;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
 
 // import java.security.AccessControlException; import java.security.AccessController;import java.security.PrivilegedAction;
 /**
@@ -32,27 +33,6 @@
 
     HashMap<String, ClassPackagingData> cache = new HashMap<String, ClassPackagingData>();
 
-    private static boolean GET_CALLER_CLASS_METHOD_AVAILABLE = false; // private static boolean
-                                                                      // HAS_GET_CLASS_LOADER_PERMISSION = false;
-
-    static {
-        // if either the Reflection class or the getCallerClass method
-        // are unavailable, then we won't invoke Reflection.getCallerClass()
-        // This approach ensures that this class will *run* on JDK's lacking
-        // sun.reflect.Reflection class. However, this class will *not compile*
-        // on JDKs lacking sun.reflect.Reflection.
-        try {
-            Reflection.getCallerClass(2);
-            GET_CALLER_CLASS_METHOD_AVAILABLE = true;
-        } catch (NoClassDefFoundError e) {
-        } catch (NoSuchMethodError e) {
-        } catch (UnsupportedOperationException e) {
-        } catch (Throwable e) {
-            System.err.println("Unexpected exception");
-            e.printStackTrace();
-        }
-    }
-
     public void calculate(IThrowableProxy tp) {
         while (tp != null) {
             populateFrames(tp.getStackTraceElementProxyArray());
@@ -81,8 +61,16 @@
         int missfireCount = 0;
         for (int i = 0; i < commonFrames; i++) {
             Class callerClass = null;
-            if (GET_CALLER_CLASS_METHOD_AVAILABLE) {
-                callerClass = Reflection.getCallerClass(localFirstCommon + i - missfireCount + 1);
+            try {
+	            Class<?> reflect = Class.forName("sun.reflect.Reflection");
+	            Method getCallerClass = reflect.getMethod("getCallerClass",Integer.TYPE);
+                callerClass = (Class<?>)(getCallerClass.invoke(null, localFirstCommon + i - missfireCount + 1));
+            } catch (ClassNotFoundException e) {
+            } catch (NoSuchMethodException e) {
+            } catch (IllegalAccessException e) {
+            } catch (InvocationTargetException e) {
+	            System.err.println("Unexpected exception");
+	            e.printStackTrace();
             }
             StackTraceElementProxy step = stepArray[stepFirstCommon + i];
             String stepClassname = step.ste.getClassName();
openSUSE Build Service is sponsored by