未验证 提交 110e8dd7 编写于 作者: sinat_25235033's avatar sinat_25235033 提交者: GitHub

fix code analysis bug (#56)

上级 70f08583
......@@ -41,7 +41,9 @@ public class DocumentResourceAccess {
*/
public static DocumentResourceEntity loadConfig(String yamlFileName) throws IOException {
Yaml yaml = new Yaml();
InputStream inputStream = DocumentResourceAccess.class.getClassLoader().getResourceAsStream(yamlFileName);
InputStream inputStream = null;
try {
inputStream = DocumentResourceAccess.class.getClassLoader().getResourceAsStream(yamlFileName);
if (inputStream == null) {
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(yamlFileName);
}
......@@ -60,6 +62,11 @@ public class DocumentResourceAccess {
"please create the file if you need config resource");
}
return yaml.loadAs(inputStream, DocumentResourceEntity.class);
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
/**
......
......@@ -240,7 +240,7 @@ public enum ClassScanner {
private static List<Class<?>> recursiveScan4Jar(String pkg, String jarPath) throws IOException {
List<Class<?>> classList = new LinkedList<>();
JarInputStream jin = new JarInputStream(new FileInputStream(jarPath));
try (JarInputStream jin = new JarInputStream(new FileInputStream(jarPath))) {
JarEntry entry = jin.getNextJarEntry();
while (entry != null) {
String name = entry.getName();
......@@ -263,7 +263,7 @@ public enum ClassScanner {
}
}
}
}
return classList;
}
......
......@@ -21,6 +21,7 @@ public class SurenessCommonUtil {
private static final String PATH_SPLIT = "/";
private static final String RANDOM_CHAR = "abcdefghijklmnopqrstuvwxyz0123456789";
private static final Random RANDOM = new Random();
/**
* match the userAgent
......@@ -58,10 +59,9 @@ public class SurenessCommonUtil {
if (length < 1) {
length = 6;
}
Random random = new Random();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
int number = random.nextInt(RANDOM_CHAR.length());
int number = RANDOM.nextInt(RANDOM_CHAR.length());
sb.append(RANDOM_CHAR.charAt(number));
}
return sb.toString();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册