Commit e5ebd115 by Jason Song

class loader util npe hot fix

parent f4b036fb
package com.ctrip.framework.apollo.core.utils;
import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -25,16 +27,18 @@ public class ClassLoaderUtil {
try {
URL url = loader.getResource("");
// get class path
classPath = url.getPath();
classPath = URLDecoder.decode(classPath, "utf-8");
if (url != null) {
classPath = url.getPath();
classPath = URLDecoder.decode(classPath, "utf-8");
}
// 如果是jar包内的,则返回当前路径
if (classPath.contains(".jar!")) {
logger.warn("using config file inline jar!");
if (Strings.isNullOrEmpty(classPath) || classPath.contains(".jar!")) {
classPath = System.getProperty("user.dir");
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (Throwable ex) {
classPath = System.getProperty("user.dir");
ex.printStackTrace();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment