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

fix code analysis bug (#56)

上级 70f08583
......@@ -41,25 +41,32 @@ public class DocumentResourceAccess {
*/
public static DocumentResourceEntity loadConfig(String yamlFileName) throws IOException {
Yaml yaml = new Yaml();
InputStream inputStream = DocumentResourceAccess.class.getClassLoader().getResourceAsStream(yamlFileName);
if (inputStream == null) {
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(yamlFileName);
}
if (inputStream == null) {
File yamlFile = new File(yamlFileName);
if (yamlFile.exists()) {
try (FileInputStream fileInputStream = new FileInputStream(yamlFile)) {
return yaml.loadAs(fileInputStream, DocumentResourceEntity.class);
} catch (IOException e) {
throw new IOException(e);
InputStream inputStream = null;
try {
inputStream = DocumentResourceAccess.class.getClassLoader().getResourceAsStream(yamlFileName);
if (inputStream == null) {
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(yamlFileName);
}
if (inputStream == null) {
File yamlFile = new File(yamlFileName);
if (yamlFile.exists()) {
try (FileInputStream fileInputStream = new FileInputStream(yamlFile)) {
return yaml.loadAs(fileInputStream, DocumentResourceEntity.class);
} catch (IOException e) {
throw new IOException(e);
}
}
}
if (inputStream == null) {
throw new FileNotFoundException("sureness file: " + DEFAULT_FILE_NAME + " not found, " +
"please create the file if you need config resource");
}
return yaml.loadAs(inputStream, DocumentResourceEntity.class);
} finally {
if (inputStream != null) {
inputStream.close();
}
}
if (inputStream == null) {
throw new FileNotFoundException("sureness file: " + DEFAULT_FILE_NAME + " not found, " +
"please create the file if you need config resource");
}
return yaml.loadAs(inputStream, DocumentResourceEntity.class);
}
/**
......
......@@ -240,30 +240,30 @@ 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));
JarEntry entry = jin.getNextJarEntry();
while (entry != null) {
String name = entry.getName();
entry = jin.getNextJarEntry();
if (!name.contains(package2Path(pkg))) {
continue;
}
if (isClass(name)) {
if (isAnonymousInnerClass(name)) {
try (JarInputStream jin = new JarInputStream(new FileInputStream(jarPath))) {
JarEntry entry = jin.getNextJarEntry();
while (entry != null) {
String name = entry.getName();
entry = jin.getNextJarEntry();
if (!name.contains(package2Path(pkg))) {
continue;
}
String className = classFile2SimpleClass(path2Package(name));
try {
Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass(className);
classList.add(clz);
} catch (ClassNotFoundException | LinkageError e) {
log.error("Warning: Can not load class: {}", className);
if (isClass(name)) {
if (isAnonymousInnerClass(name)) {
continue;
}
String className = classFile2SimpleClass(path2Package(name));
try {
Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass(className);
classList.add(clz);
} catch (ClassNotFoundException | LinkageError e) {
log.error("Warning: Can not load class: {}", className);
}
}
}
}
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.
先完成此消息的编辑!
想要评论请 注册