Unverified 提交 47ee04dc authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #1313 from little-pan/clean-test-master

Bugfix - using default locale encoding issue in conversion between varchar and varbinary value, and checking javac output text issue in SourceCompiler
......@@ -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 {
......
......@@ -960,7 +960,10 @@ public abstract class Value {
case STRING: {
String s;
if (getType() == BYTES && mode != null && mode.charToBinaryInUtf8) {
s = new String(getBytesNoCopy());
// Bugfix - Can't use the locale encoding when enabling charToBinaryInUtf8 in mode.
// The following two target types also are the same issue.
// @since 2018-07-19 little-pan
s = new String(getBytesNoCopy(), StandardCharsets.UTF_8);
} else {
s = getString();
}
......@@ -969,7 +972,7 @@ public abstract class Value {
case STRING_IGNORECASE: {
String s;
if (getType() == BYTES && mode != null && mode.charToBinaryInUtf8) {
s = new String(getBytesNoCopy());
s = new String(getBytesNoCopy(), StandardCharsets.UTF_8);
} else {
s = getString();
}
......@@ -978,7 +981,7 @@ public abstract class Value {
case STRING_FIXED: {
String s;
if (getType() == BYTES && mode != null && mode.charToBinaryInUtf8) {
s = new String(getBytesNoCopy());
s = new String(getBytesNoCopy(), StandardCharsets.UTF_8);
} else {
s = getString();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论