Updated to java 8+ version of getting calling class
This commit is contained in:
parent
16019270c8
commit
ec8d5d1926
|
@ -20,7 +20,6 @@ import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import dorkbox.util.OS;
|
|
||||||
import dorkbox.util.exceptions.SecurityException;
|
import dorkbox.util.exceptions.SecurityException;
|
||||||
import dorkbox.util.serialization.SerializationManager;
|
import dorkbox.util.serialization.SerializationManager;
|
||||||
import dorkbox.util.storage.Storage;
|
import dorkbox.util.storage.Storage;
|
||||||
|
@ -42,29 +41,17 @@ class SettingsStore {
|
||||||
|
|
||||||
|
|
||||||
private static String getCallingClass() {
|
private static String getCallingClass() {
|
||||||
// java < 8, it is SIGNIFICANTLY faster to call sun.reflect.Reflection.getCallerClass
|
StackTraceElement[] cause = Thread.currentThread().getStackTrace();
|
||||||
// java >= 8, Thread.stackTrace was fixed, so it is the now preferred method
|
if (cause == null || cause.length < 4) {
|
||||||
if (OS.javaVersion < 8) {
|
return null;
|
||||||
Class<?> callerClass = sun.reflect.Reflection.getCallerClass(4);
|
|
||||||
|
|
||||||
if (callerClass == null) {
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
return callerClass.getName();
|
|
||||||
} else {
|
|
||||||
StackTraceElement[] cause = Thread.currentThread().getStackTrace();
|
|
||||||
if (cause == null || cause.length < 4) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
StackTraceElement stackTraceElement = cause[4];
|
|
||||||
if (stackTraceElement == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return stackTraceElement.getClassName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StackTraceElement stackTraceElement = cause[4];
|
||||||
|
if (stackTraceElement == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return stackTraceElement.getClassName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user