In preparation for the imminent arrival of 15 to jdk/jdk, this change
replaces the hardcoded source version, used to invoke the compiler
programmatically, with the runtime feature version, similar to
JDK-8235514.

I tested this change along side the changes for 8225361 - "Start of
release updates for JDK 15" - and the record serialization migration
tests pass successfully.

--- a/test/jdk/java/io/Serializable/records/migration/AbstractTest.java
+++ b/test/jdk/java/io/Serializable/records/migration/AbstractTest.java
@@ -32,48 +32,50 @@
 import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.nio.file.Path;
 import jdk.test.lib.compiler.CompilerUtils;
 import org.testng.annotations.BeforeTest;
 import static org.testng.Assert.*;

 /**
  * An abstract superclass for tests that require to serialize and deserialize
  * record-like and record classes. Can be used for determining migration and
  * interop between record-like and record classes.
  */
 public class AbstractTest {

+    private static final String VERSION = 
Integer.toString(Runtime.version().feature());
+
     static final String TEST_SRC = System.getProperty("test.src", ".");
     static final String TEST_CLASSES = System.getProperty("test.classes", ".");
     static final Path TEST_CLASSES_DIR = Path.of(TEST_CLASSES);

     static final Path PLAIN_SRC_DIR = Path.of(TEST_SRC, "plain");
     static final Path PLAIN_DEST_DIR = Path.of("plain");

     static final Path RECORD_SRC_DIR = Path.of(TEST_SRC, "record");
     static final Path RECORD_DEST_DIR = Path.of("record");

     @BeforeTest
     public void setup() throws IOException {
         assertTrue(CompilerUtils.compile(PLAIN_SRC_DIR, PLAIN_DEST_DIR,
-                   "--enable-preview", "-source", "14",
+                   "--enable-preview", "-source", VERSION,
                    "--class-path", TEST_CLASSES_DIR.toString()));

         assertTrue(CompilerUtils.compile(RECORD_SRC_DIR, RECORD_DEST_DIR,
-                   "--enable-preview", "-source", "14",
+                   "--enable-preview", "-source", VERSION,
                    "--class-path", TEST_CLASSES_DIR.toString()));
     }

     static <T> byte[] serialize(T obj) throws IOException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream oos = new ObjectOutputStream(baos);
         oos.writeObject(obj);
         oos.close();
         return baos.toByteArray();
     }

     @SuppressWarnings("unchecked")
     static <T> T deserializeAsPlain(byte[] streamBytes)
         throws IOException, ClassNotFoundException
     {


-Chris.

Reply via email to