private static ClassLoader getPlatformClassLoader ( ) { if ( JavaInfo . majorVersion ( ) >= 9 ) { return AccessController . doPrivileged ( new PrivilegedAction < ClassLoader > ( ) { @ Override public ClassLoader run ( ) { ClassLoader pcl = null ; try { Method getPlatformClassLoader = ClassLoader . class . getMethod ( "getPlatformClassLoader" ) ; pcl = ( ClassLoader ) getPlatformClassLoader . invoke ( null ) ; } catch ( Throwable t ) { // Log an FFDC. } return pcl ; } } ) ; } return null ; }
Returns the PlatformClassloader when running with java 9 and above ; otherwise returns null .