Concurrent accessing allJars causes the plugin to fail to load (#5158)
Another thread could get the list which is still in the initialization stage, due to first element added. So we need a local variable to avoid this. Also, notice this happens only in concurrency class loader env.
This commit is contained in:
parent
1a373dac03
commit
1215a52d09
|
|
@ -174,22 +174,7 @@ public class AgentClassLoader extends ClassLoader {
|
||||||
jarScanLock.lock();
|
jarScanLock.lock();
|
||||||
try {
|
try {
|
||||||
if (allJars == null) {
|
if (allJars == null) {
|
||||||
allJars = new LinkedList<>();
|
allJars = doGetJars();
|
||||||
for (File path : classpath) {
|
|
||||||
if (path.exists() && path.isDirectory()) {
|
|
||||||
String[] jarFileNames = path.list((dir, name) -> name.endsWith(".jar"));
|
|
||||||
for (String fileName : jarFileNames) {
|
|
||||||
try {
|
|
||||||
File file = new File(path, fileName);
|
|
||||||
Jar jar = new Jar(new JarFile(file), file);
|
|
||||||
allJars.add(jar);
|
|
||||||
logger.info("{} loaded.", file.toString());
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e, "{} jar file can't be resolved", fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
jarScanLock.unlock();
|
jarScanLock.unlock();
|
||||||
|
|
@ -199,6 +184,26 @@ public class AgentClassLoader extends ClassLoader {
|
||||||
return allJars;
|
return allJars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LinkedList<Jar> doGetJars() {
|
||||||
|
LinkedList<Jar> jars = new LinkedList<>();
|
||||||
|
for (File path : classpath) {
|
||||||
|
if (path.exists() && path.isDirectory()) {
|
||||||
|
String[] jarFileNames = path.list((dir, name) -> name.endsWith(".jar"));
|
||||||
|
for (String fileName : jarFileNames) {
|
||||||
|
try {
|
||||||
|
File file = new File(path, fileName);
|
||||||
|
Jar jar = new Jar(new JarFile(file), file);
|
||||||
|
jars.add(jar);
|
||||||
|
logger.info("{} loaded.", file.toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error(e, "{} jar file can't be resolved", fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return jars;
|
||||||
|
}
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
private static class Jar {
|
private static class Jar {
|
||||||
private final JarFile jarFile;
|
private final JarFile jarFile;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue