< prev index next >

test/jdk/java/lang/invoke/lambda/LambdaStackTrace.java

Print this page
@@ -22,34 +22,37 @@
   */
  
  /*
   * @test
   * @bug 8025636
-  * @summary Synthetic frames should be hidden in exceptions
+  * @library /test/lib/
   * @modules java.base/jdk.internal.org.objectweb.asm
   *          jdk.compiler
-  * @compile -XDignore.symbol.file LUtils.java LambdaStackTrace.java
+  * @compile LambdaStackTrace.java
   * @run main LambdaStackTrace
+  * @summary Synthetic frames should be hidden in exceptions
   */
  
  import jdk.internal.org.objectweb.asm.ClassWriter;
+ import jdk.test.lib.compiler.CompilerUtils;
  
- import java.io.File;
- import java.io.FileOutputStream;
  import java.io.IOException;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
+ import java.nio.charset.Charset;
+ import java.nio.file.Files;
+ import java.nio.file.Path;
  import java.util.ArrayList;
  
  import static jdk.internal.org.objectweb.asm.Opcodes.ACC_ABSTRACT;
  import static jdk.internal.org.objectweb.asm.Opcodes.ACC_INTERFACE;
  import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;
  import static jdk.internal.org.objectweb.asm.Opcodes.V1_7;
  
  public class LambdaStackTrace {
  
-     static File classes = new File(System.getProperty("test.classes"));
+     static Path CLASSES = Path.of(System.getProperty("test.classes", "."));
  
      public static void main(String[] args) throws Exception {
          testBasic();
          testBridgeMethods();
      }

@@ -119,16 +122,12 @@
  
      private static void generateInterfaces() throws IOException {
          // We can't let javac compile these interfaces because in > 1.8 it will insert
          // bridge methods into the interfaces - we want code that looks like <= 1.7,
          // so we generate it.
-         try (FileOutputStream fw = new FileOutputStream(new File(classes, "Maker.class"))) {
-             fw.write(generateMaker());
-         }
-         try (FileOutputStream fw = new FileOutputStream(new File(classes, "StringMaker.class"))) {
-             fw.write(generateStringMaker());
-         }
+         Files.write(CLASSES.resolve("Maker.class"), generateMaker());
+         Files.write(CLASSES.resolve("StringMaker.class"), generateStringMaker());
      }
  
      private static byte[] generateMaker() {
          // interface Maker {
          //   Object make();

@@ -152,11 +151,11 @@
          cw.visitEnd();
          return cw.toByteArray();
      }
  
  
-     static void emitCode(File f) {
+     static void emitCode(Path file) throws IOException {
          ArrayList<String> scratch = new ArrayList<>();
          scratch.add("public class Caller {");
          scratch.add("    public static void callStringMaker() {");
          scratch.add("        StringMaker sm = () -> { throw new RuntimeException(); };");
          scratch.add("        sm.make();");

@@ -164,17 +163,21 @@
          scratch.add("    public static void callMaker() {");
          scratch.add("        StringMaker sm = () -> { throw new RuntimeException(); };");
          scratch.add("        ((Maker) sm).make();");  // <-- This will call the bridge method
          scratch.add("    }");
          scratch.add("}");
-         LUtils.createFile(f, scratch);
+ 
+         Files.write(file, scratch, Charset.defaultCharset());
      }
  
-     static void compileCaller() {
-         File caller = new File(classes, "Caller.java");
+     static void compileCaller() throws IOException {
+         Path src = Path.of("src");
+         Files.createDirectories(src);
+ 
+         Path caller = src.resolve("Caller.java");
          emitCode(caller);
-         LUtils.compile("-cp", classes.getAbsolutePath(), "-d", classes.getAbsolutePath(), caller.getAbsolutePath());
+         CompilerUtils.compile(src, CLASSES, "-cp", CLASSES.toAbsolutePath().toString());
      }
  
      private static void verifyFrames(StackTraceElement[] stack, String... patterns) throws Exception {
          for (int i = 0; i < patterns.length; i++) {
              String cm = stack[i].getClassName() + "." + stack[i].getMethodName();
< prev index next >