PlatformDependent static initialization ExceptionInInitializerError
Motivation: PlatformDependent allows some exceptions to escape during static initialization. If an exception escapes it will be translated into a java.lang.ExceptionInInitializerError and render the application unable to run. Modifications: - Make sure to catch Throwable during static initialization. Result: PlatformDependent static initialization doesn't result in java.lang.ExceptionInInitializerError.
This commit is contained in:
parent
ef2cf4625d
commit
92896bd7bd
@ -88,7 +88,6 @@ public final class PlatformDependent {
|
|||||||
private static final int BIT_MODE = bitMode0();
|
private static final int BIT_MODE = bitMode0();
|
||||||
|
|
||||||
private static final int ADDRESS_SIZE = addressSize0();
|
private static final int ADDRESS_SIZE = addressSize0();
|
||||||
private static final boolean NATIVE_ORDER = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
@ -518,7 +517,7 @@ public final class PlatformDependent {
|
|||||||
try {
|
try {
|
||||||
Class.forName("android.app.Application", false, getSystemClassLoader());
|
Class.forName("android.app.Application", false, getSystemClassLoader());
|
||||||
android = true;
|
android = true;
|
||||||
} catch (Exception e) {
|
} catch (Throwable ignored) {
|
||||||
// Failed to load the class uniquely available in Android.
|
// Failed to load the class uniquely available in Android.
|
||||||
android = false;
|
android = false;
|
||||||
}
|
}
|
||||||
@ -565,7 +564,7 @@ public final class PlatformDependent {
|
|||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Throwable ignored) {
|
||||||
// Failed to run the command.
|
// Failed to run the command.
|
||||||
uid = null;
|
uid = null;
|
||||||
} finally {
|
} finally {
|
||||||
@ -646,7 +645,7 @@ public final class PlatformDependent {
|
|||||||
Class.forName("java.time.Clock", false, getClassLoader(Object.class));
|
Class.forName("java.time.Clock", false, getClassLoader(Object.class));
|
||||||
javaVersion = 8;
|
javaVersion = 8;
|
||||||
break;
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Throwable ignored) {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -654,7 +653,7 @@ public final class PlatformDependent {
|
|||||||
Class.forName("java.util.concurrent.LinkedTransferQueue", false, getClassLoader(BlockingQueue.class));
|
Class.forName("java.util.concurrent.LinkedTransferQueue", false, getClassLoader(BlockingQueue.class));
|
||||||
javaVersion = 7;
|
javaVersion = 7;
|
||||||
break;
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Throwable ignored) {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -699,7 +698,7 @@ public final class PlatformDependent {
|
|||||||
boolean hasUnsafe = PlatformDependent0.hasUnsafe();
|
boolean hasUnsafe = PlatformDependent0.hasUnsafe();
|
||||||
logger.debug("sun.misc.Unsafe: {}", hasUnsafe ? "available" : "unavailable");
|
logger.debug("sun.misc.Unsafe: {}", hasUnsafe ? "available" : "unavailable");
|
||||||
return hasUnsafe;
|
return hasUnsafe;
|
||||||
} catch (Throwable t) {
|
} catch (Throwable ignored) {
|
||||||
// Probably failed to initialize PlatformDependent0.
|
// Probably failed to initialize PlatformDependent0.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -720,7 +719,7 @@ public final class PlatformDependent {
|
|||||||
Class<?> vmClass = Class.forName("sun.misc.VM", true, getSystemClassLoader());
|
Class<?> vmClass = Class.forName("sun.misc.VM", true, getSystemClassLoader());
|
||||||
Method m = vmClass.getDeclaredMethod("maxDirectMemory");
|
Method m = vmClass.getDeclaredMethod("maxDirectMemory");
|
||||||
maxDirectMemory = ((Number) m.invoke(null)).longValue();
|
maxDirectMemory = ((Number) m.invoke(null)).longValue();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable ignored) {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -760,7 +759,7 @@ public final class PlatformDependent {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable ignored) {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -845,7 +844,7 @@ public final class PlatformDependent {
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Throwable ignored) {
|
||||||
// Environment variable inaccessible
|
// Environment variable inaccessible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user