changeset 57054:7cbd8fae6c1a nestmates

[nestmates] clean up SelfReferenceDescriptor test
author mchung
date Mon, 16 Sep 2019 15:15:58 -0700
parents 065b91bb236b
children e25fcad6a2f1
files test/jdk/java/lang/invoke/defineHiddenClass/SelfReferenceDescriptor.java
diffstat 1 files changed, 10 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/java/lang/invoke/defineHiddenClass/SelfReferenceDescriptor.java	Mon Sep 16 12:05:46 2019 -0700
+++ b/test/jdk/java/lang/invoke/defineHiddenClass/SelfReferenceDescriptor.java	Mon Sep 16 15:15:58 2019 -0700
@@ -37,6 +37,7 @@
 import static java.lang.invoke.MethodHandles.Lookup.ClassOption.*;
 import static java.lang.invoke.MethodHandles.lookup;
 
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Arrays;
@@ -65,38 +66,29 @@
         }
     }
 
-    static byte[] readClassFile(String classFileName) throws IOException {
-        File classFile = new File(CLASSES_DIR + File.separator + classFileName);
-        try (FileInputStream in = new FileInputStream(classFile);
-             ByteArrayOutputStream out = new ByteArrayOutputStream())
-        {
-            int b;
-            while ((b = in.read()) != -1) {
-                out.write(b);
-            }
-            return out.toByteArray();
-        }
-    }
-
     // Test that a hidden class cannot use its own name in a field
     // signature.
     public static void hiddenClassInFieldDescriptor() throws Exception {
         compileSources(SRC_DIR.resolve("SelfRefField.java"));
-        byte[] bytes = readClassFile("SelfRefField.class");
+        Path path = CLASSES_DIR.resolve("SelfRefField.class");
+        byte[] bytes = Files.readAllBytes(path);
         try {
-            lookup().defineHiddenClass(bytes, false);
+            lookup().defineHiddenClass(bytes, false, NESTMATE);
+            throw new RuntimeException("expected NCDFE in defining SelfRefField hidden class");
         } catch (NoClassDefFoundError e) {
             if (!e.getMessage().contains("SelfRefField")) throw e;
         }
     }
 
-    // Test that a nonFindable class cannot use its own name in a method
+    // Test that a hidden class cannot use its own name in a method
     // signature.
     public static void hiddenClassInMethodDescriptor() throws Exception {
         compileSources(SRC_DIR.resolve("SelfRefMethod.java"));
-        byte[] bytes = readClassFile("SelfRefMethod.class");
+        Path path = CLASSES_DIR.resolve("SelfRefMethod.class");
+        byte[] bytes = Files.readAllBytes(path);
         try {
-            lookup().defineHiddenClass(bytes, false);
+            lookup().defineHiddenClass(bytes, false, NESTMATE);
+            throw new RuntimeException("expected NCDFE in defining SelfRefMethod hidden class");
         } catch (NoClassDefFoundError e) {
             if (!e.getMessage().contains("SelfRefMethod")) throw e;
         }