提交 2cebc247 authored 作者: Thomas Mueller's avatar Thomas Mueller

SourceCompiler throws syntax error on javac warning

上级 383aa317
...@@ -287,8 +287,8 @@ public class SourceCompiler { ...@@ -287,8 +287,8 @@ public class SourceCompiler {
JAVA_COMPILER.getTask(writer, fileManager, null, null, JAVA_COMPILER.getTask(writer, fileManager, null, null,
null, compilationUnits).call(); null, compilationUnits).call();
} }
String err = writer.toString(); String output = writer.toString();
throwSyntaxError(err); handleSyntaxError(output);
try { try {
return fileManager.getClassLoader(null).loadClass(fullClassName); return fileManager.getClassLoader(null).loadClass(fullClassName);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
...@@ -319,8 +319,8 @@ public class SourceCompiler { ...@@ -319,8 +319,8 @@ public class SourceCompiler {
copyInThread(p.getInputStream(), buff); copyInThread(p.getInputStream(), buff);
copyInThread(p.getErrorStream(), buff); copyInThread(p.getErrorStream(), buff);
p.waitFor(); p.waitFor();
String err = new String(buff.toByteArray(), Constants.UTF8); String output = new String(buff.toByteArray(), Constants.UTF8);
throwSyntaxError(err); handleSyntaxError(output);
return p.exitValue(); return p.exitValue();
} catch (Exception e) { } catch (Exception e) {
throw DbException.convert(e); throw DbException.convert(e);
...@@ -351,8 +351,8 @@ public class SourceCompiler { ...@@ -351,8 +351,8 @@ public class SourceCompiler {
"-d", COMPILE_DIR, "-d", COMPILE_DIR,
"-encoding", "UTF-8", "-encoding", "UTF-8",
javaFile.getAbsolutePath() }); javaFile.getAbsolutePath() });
String err = new String(buff.toByteArray(), Constants.UTF8); String output = new String(buff.toByteArray(), Constants.UTF8);
throwSyntaxError(err); handleSyntaxError(output);
} catch (Exception e) { } catch (Exception e) {
throw DbException.convert(e); throw DbException.convert(e);
} finally { } finally {
...@@ -360,12 +360,12 @@ public class SourceCompiler { ...@@ -360,12 +360,12 @@ public class SourceCompiler {
} }
} }
private static void throwSyntaxError(String err) { private static void handleSyntaxError(String output) {
if (err.startsWith("Note:")) { if (output.startsWith("Note:") || output.startsWith("warning:")) {
// unchecked or unsafe operations - just a warning // just a warning (e.g. unchecked or unsafe operations)
} else if (err.length() > 0) { } else if (output.length() > 0) {
err = StringUtils.replaceAll(err, COMPILE_DIR, ""); output = StringUtils.replaceAll(output, COMPILE_DIR, "");
throw DbException.get(ErrorCode.SYNTAX_ERROR_1, err); throw DbException.get(ErrorCode.SYNTAX_ERROR_1, output);
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论