提交 c3ce4860 authored 作者: Uncle-pan's avatar Uncle-pan

Bugfix - check javac compile() exit status instead of parsing it's

output text
上级 16459470
......@@ -339,12 +339,13 @@ public class SourceCompiler {
ArrayList<JavaFileObject> compilationUnits = new ArrayList<>();
compilationUnits.add(new StringJavaFileObject(fullClassName, source));
// cannot concurrently compile
final boolean ok;
synchronized (JAVA_COMPILER) {
JAVA_COMPILER.getTask(writer, fileManager, null, null,
ok = JAVA_COMPILER.getTask(writer, fileManager, null, null,
null, compilationUnits).call();
}
String output = writer.toString();
handleSyntaxError(output);
handleSyntaxError(output, (ok? 0: 1));
return fileManager.getClassLoader(null).loadClass(fullClassName);
} catch (ClassNotFoundException | IOException e) {
throw DbException.convert(e);
......@@ -375,7 +376,7 @@ public class SourceCompiler {
copyInThread(p.getErrorStream(), buff);
p.waitFor();
String output = new String(buff.toByteArray(), StandardCharsets.UTF_8);
handleSyntaxError(output);
handleSyntaxError(output, p.exitValue());
return p.exitValue();
} catch (Exception e) {
throw DbException.convert(e);
......@@ -400,14 +401,17 @@ public class SourceCompiler {
Method compile;
compile = JAVAC_SUN.getMethod("compile", String[].class);
Object javac = JAVAC_SUN.getDeclaredConstructor().newInstance();
compile.invoke(javac, (Object) new String[] {
// Bugfix: Here we should check exit status value instead of parsing javac output text.
// Because of the output text is different in different locale environment.
// @since 2018-07-20 little-pan
final Integer status = (Integer)compile.invoke(javac, (Object) new String[] {
"-sourcepath", COMPILE_DIR,
// "-Xlint:unchecked",
"-d", COMPILE_DIR,
"-encoding", "UTF-8",
javaFile.getAbsolutePath() });
String output = new String(buff.toByteArray(), StandardCharsets.UTF_8);
handleSyntaxError(output);
handleSyntaxError(output, status);
} catch (Exception e) {
throw DbException.convert(e);
} finally {
......@@ -415,7 +419,10 @@ public class SourceCompiler {
}
}
private static void handleSyntaxError(String output) {
private static void handleSyntaxError(String output, int exitStatus) {
if(0 == exitStatus){
return;
}
boolean syntaxError = false;
final BufferedReader reader = new BufferedReader(new StringReader(output));
try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论