Package org.apache.flink.util
Class ClassLoaderUtil
- java.lang.Object
-
- org.apache.flink.util.ClassLoaderUtil
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
formatURL(URL url)
Returns the interpretation of URL in string format.static String
getUserCodeClassLoaderInfo(ClassLoader loader)
Gets information about URL class loaders.static boolean
validateClassLoadable(ClassNotFoundException cnfe, ClassLoader cl)
Checks, whether the class that was not found in the given exception, can be resolved through the given class loader.
-
-
-
Method Detail
-
getUserCodeClassLoaderInfo
public static String getUserCodeClassLoaderInfo(ClassLoader loader)
Gets information about URL class loaders. The returned info string contains all URLs of the class loader. For file URLs, it contains in addition whether the referenced file exists, is a valid JAR file, or is a directory.NOTE: This method makes a best effort to provide information about the classloader, and never throws an exception.
NOTE: Passing
ClassLoader.getSystemClassLoader()
on Java 9+ will not return anything interesting.- Parameters:
loader
- The classloader to get the info string for.- Returns:
- The classloader information string.
-
formatURL
public static String formatURL(URL url) throws IOException
Returns the interpretation of URL in string format.If the URL is null, it returns '(null)'.
If the URL protocol is file, prepend 'file:' flag before the formatted URL. Otherwise, use 'url: ' as the prefix instead.
Also, it checks whether the object that the URL directs to exists or not. If the object exists, some additional checks should be performed in order to determine that the object is a directory or a valid/invalid jar file. If the object does not exist, a missing flag should be appended.
- Parameters:
url
- URL that should be formatted- Returns:
- The formatted URL
- Throws:
IOException
- When JarFile cannot be closed
-
validateClassLoadable
public static boolean validateClassLoadable(ClassNotFoundException cnfe, ClassLoader cl)
Checks, whether the class that was not found in the given exception, can be resolved through the given class loader.- Parameters:
cnfe
- The ClassNotFoundException that defines the name of the class.cl
- The class loader to use for the class resolution.- Returns:
- True, if the class can be resolved with the given class loader, false if not.
-
-