1.1 --- a/test/tools/javac/api/T6306137.java Tue Jun 25 20:08:52 2013 +0400 1.2 +++ b/test/tools/javac/api/T6306137.java Wed Jun 26 09:54:46 2013 -0700 1.3 @@ -31,8 +31,14 @@ 1.4 */ 1.5 1.6 import java.io.File; 1.7 +import java.io.IOException; 1.8 +import java.nio.charset.Charset; 1.9 +import java.nio.file.Files; 1.10 +import java.util.ArrayList; 1.11 import java.util.Arrays; 1.12 +import java.util.List; 1.13 import javax.tools.*; 1.14 +import static java.nio.file.StandardOpenOption.*; 1.15 1.16 public class T6306137 { 1.17 boolean error; 1.18 @@ -40,8 +46,9 @@ 1.19 final JavaCompiler compiler; 1.20 Iterable<? extends JavaFileObject> files; 1.21 DiagnosticListener<JavaFileObject> dl; 1.22 + final File testFile = new File("Utf8.java"); 1.23 1.24 - T6306137() { 1.25 + T6306137() throws IOException { 1.26 dl = new DiagnosticListener<JavaFileObject>() { 1.27 public void report(Diagnostic<? extends JavaFileObject> message) { 1.28 if (message.getKind() == Diagnostic.Kind.ERROR) 1.29 @@ -56,11 +63,17 @@ 1.30 }; 1.31 compiler = ToolProvider.getSystemJavaCompiler(); 1.32 fm = compiler.getStandardFileManager(dl, null, null); 1.33 - String srcdir = System.getProperty("test.src"); 1.34 files = 1.35 - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6306137.java"))); 1.36 + fm.getJavaFileObjectsFromFiles(Arrays.asList(testFile)); 1.37 + createTestFile(); 1.38 } 1.39 - 1.40 + final void createTestFile() throws IOException { 1.41 + List<String> scratch = new ArrayList<>(); 1.42 + scratch.add("// @author Peter von der Ah" + (char)0xe9); 1.43 + scratch.add("class Utf8{}"); 1.44 + Files.write(testFile.toPath(), scratch, Charset.forName("UTF-8"), 1.45 + CREATE, TRUNCATE_EXISTING); 1.46 + } 1.47 void test(String encoding, boolean good) { 1.48 error = false; 1.49 Iterable<String> args = Arrays.asList("-source", "6", "-encoding", encoding, "-d", "."); 1.50 @@ -74,7 +87,7 @@ 1.51 } 1.52 } 1.53 1.54 - public static void main(String[] args) { 1.55 + public static void main(String[] args) throws IOException { 1.56 T6306137 self = new T6306137(); 1.57 self.test("utf-8", true); 1.58 self.test("ascii", false);