Unverified 提交 28b45c48 authored 作者: Andrei Tokar's avatar Andrei Tokar 提交者: GitHub

Merge pull request #780 from crafty78/master

Close JavaFileManager after use.
...@@ -326,21 +326,20 @@ public class SourceCompiler { ...@@ -326,21 +326,20 @@ public class SourceCompiler {
Class<?> javaxToolsJavac(String packageName, String className, String source) { Class<?> javaxToolsJavac(String packageName, String className, String source) {
String fullClassName = packageName + "." + className; String fullClassName = packageName + "." + className;
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
JavaFileManager fileManager = new try (JavaFileManager fileManager = new
ClassFileManager(JAVA_COMPILER ClassFileManager(JAVA_COMPILER
.getStandardFileManager(null, null, null)); .getStandardFileManager(null, null, null))) {
ArrayList<JavaFileObject> compilationUnits = new ArrayList<>(); ArrayList<JavaFileObject> compilationUnits = new ArrayList<>();
compilationUnits.add(new StringJavaFileObject(fullClassName, source)); compilationUnits.add(new StringJavaFileObject(fullClassName, source));
// cannot concurrently compile // cannot concurrently compile
synchronized (JAVA_COMPILER) { synchronized (JAVA_COMPILER) {
JAVA_COMPILER.getTask(writer, fileManager, null, null, JAVA_COMPILER.getTask(writer, fileManager, null, null,
null, compilationUnits).call(); null, compilationUnits).call();
} }
String output = writer.toString(); String output = writer.toString();
handleSyntaxError(output); handleSyntaxError(output);
try {
return fileManager.getClassLoader(null).loadClass(fullClassName); return fileManager.getClassLoader(null).loadClass(fullClassName);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException | IOException e) {
throw DbException.convert(e); throw DbException.convert(e);
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论