8235514: Update record serialization tests to not use hard coded source versions
Reviewed-by: lancea
This commit is contained in:
parent
fa21d57760
commit
e1921502c5
@ -59,6 +59,7 @@ import static org.testng.Assert.expectThrows;
|
||||
* constructor cannot be found during deserialization.
|
||||
*/
|
||||
public class BadCanonicalCtrTest {
|
||||
private static final String VERSION = Integer.toString(Runtime.version().feature());
|
||||
|
||||
// ClassLoader for creating instances of the records to test with.
|
||||
ClassLoader goodRecordClassLoader;
|
||||
@ -79,7 +80,7 @@ public class BadCanonicalCtrTest {
|
||||
{
|
||||
byte[] byteCode = InMemoryJavaCompiler.compile("R1",
|
||||
"public record R1 () implements java.io.Serializable { }",
|
||||
"--enable-preview", "-source", "14");
|
||||
"--enable-preview", "-source", VERSION);
|
||||
goodRecordClassLoader = new ByteCodeLoader("R1", byteCode, BadCanonicalCtrTest.class.getClassLoader());
|
||||
byte[] bc1 = removeConstructor(byteCode);
|
||||
missingCtrClassLoader = new ByteCodeLoader("R1", bc1, BadCanonicalCtrTest.class.getClassLoader());
|
||||
@ -89,7 +90,7 @@ public class BadCanonicalCtrTest {
|
||||
{
|
||||
byte[] byteCode = InMemoryJavaCompiler.compile("R2",
|
||||
"public record R2 (int x, int y) implements java.io.Serializable { }",
|
||||
"--enable-preview", "-source", "14");
|
||||
"--enable-preview", "-source", VERSION);
|
||||
goodRecordClassLoader = new ByteCodeLoader("R2", byteCode, goodRecordClassLoader);
|
||||
byte[] bc1 = removeConstructor(byteCode);
|
||||
missingCtrClassLoader = new ByteCodeLoader("R2", bc1, missingCtrClassLoader);
|
||||
@ -101,7 +102,7 @@ public class BadCanonicalCtrTest {
|
||||
"public record R3 (long l) implements java.io.Externalizable {" +
|
||||
" public void writeExternal(java.io.ObjectOutput out) { }" +
|
||||
" public void readExternal(java.io.ObjectInput in) { } }",
|
||||
"--enable-preview", "-source", "14");
|
||||
"--enable-preview", "-source", VERSION);
|
||||
goodRecordClassLoader = new ByteCodeLoader("R3", byteCode, goodRecordClassLoader);
|
||||
byte[] bc1 = removeConstructor(byteCode);
|
||||
missingCtrClassLoader = new ByteCodeLoader("R3", bc1, missingCtrClassLoader);
|
||||
|
@ -69,6 +69,7 @@ import static org.testng.Assert.fail;
|
||||
* record objects.
|
||||
*/
|
||||
public class ProhibitedMethods {
|
||||
private static final String VERSION = Integer.toString(Runtime.version().feature());
|
||||
|
||||
public interface ThrowingExternalizable extends Externalizable {
|
||||
default void writeExternal(ObjectOutput out) {
|
||||
@ -106,7 +107,7 @@ public class ProhibitedMethods {
|
||||
{
|
||||
byte[] byteCode = InMemoryJavaCompiler.compile("Foo",
|
||||
"public record Foo () implements java.io.Serializable { }",
|
||||
"--enable-preview", "-source", "14");
|
||||
"--enable-preview", "-source", VERSION);
|
||||
byteCode = addWriteObject(byteCode);
|
||||
byteCode = addReadObject(byteCode);
|
||||
byteCode = addReadObjectNoData(byteCode);
|
||||
@ -115,7 +116,7 @@ public class ProhibitedMethods {
|
||||
{
|
||||
byte[] byteCode = InMemoryJavaCompiler.compile("Bar",
|
||||
"public record Bar (int x, int y) implements java.io.Serializable { }",
|
||||
"--enable-preview", "-source", "14");
|
||||
"--enable-preview", "-source", VERSION);
|
||||
byteCode = addWriteObject(byteCode);
|
||||
byteCode = addReadObject(byteCode);
|
||||
byteCode = addReadObjectNoData(byteCode);
|
||||
@ -125,7 +126,7 @@ public class ProhibitedMethods {
|
||||
byte[] byteCode = InMemoryJavaCompiler.compile("Baz",
|
||||
"import java.io.Serializable;" +
|
||||
"public record Baz<U extends Serializable,V extends Serializable>(U u, V v) implements Serializable { }",
|
||||
"--enable-preview", "-source", "14");
|
||||
"--enable-preview", "-source", VERSION);
|
||||
byteCode = addWriteObject(byteCode);
|
||||
byteCode = addReadObject(byteCode);
|
||||
byteCode = addReadObjectNoData(byteCode);
|
||||
|
@ -64,6 +64,7 @@ import static org.testng.Assert.assertTrue;
|
||||
* Checks that the serialPersistentFields declaration is effectively ignored.
|
||||
*/
|
||||
public class SerialPersistentFieldsTest {
|
||||
private static final String VERSION = Integer.toString(Runtime.version().feature());
|
||||
|
||||
ClassLoader serializableRecordLoader;
|
||||
|
||||
@ -85,7 +86,7 @@ public class SerialPersistentFieldsTest {
|
||||
{ // R1
|
||||
byte[] byteCode = InMemoryJavaCompiler.compile("R1",
|
||||
"public record R1 () implements java.io.Serializable { }",
|
||||
"--enable-preview", "-source", "14");
|
||||
"--enable-preview", "-source", VERSION);
|
||||
ObjectStreamField[] serialPersistentFields = {
|
||||
new ObjectStreamField("s", String.class),
|
||||
new ObjectStreamField("i", int.class),
|
||||
@ -98,7 +99,7 @@ public class SerialPersistentFieldsTest {
|
||||
{ // R2
|
||||
byte[] byteCode = InMemoryJavaCompiler.compile("R2",
|
||||
"public record R2 (int x) implements java.io.Serializable { }",
|
||||
"--enable-preview", "-source", "14");
|
||||
"--enable-preview", "-source", VERSION);
|
||||
ObjectStreamField[] serialPersistentFields = {
|
||||
new ObjectStreamField("s", String.class)
|
||||
};
|
||||
@ -108,7 +109,7 @@ public class SerialPersistentFieldsTest {
|
||||
{ // R3
|
||||
byte[] byteCode = InMemoryJavaCompiler.compile("R3",
|
||||
"public record R3 (int x, int y) implements java.io.Serializable { }",
|
||||
"--enable-preview", "-source", "14");
|
||||
"--enable-preview", "-source", VERSION);
|
||||
ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0];
|
||||
byteCode = addSerialPersistentFields(byteCode, serialPersistentFields);
|
||||
serializableRecordLoader = new ByteCodeLoader("R3", byteCode, serializableRecordLoader);
|
||||
@ -117,7 +118,7 @@ public class SerialPersistentFieldsTest {
|
||||
byte[] byteCode = InMemoryJavaCompiler.compile("R4",
|
||||
"import java.io.Serializable;" +
|
||||
"public record R4<U extends Serializable,V extends Serializable>(U u, V v) implements Serializable { }",
|
||||
"--enable-preview", "-source", "14");
|
||||
"--enable-preview", "-source", VERSION);
|
||||
ObjectStreamField[] serialPersistentFields = {
|
||||
new ObjectStreamField("v", String.class)
|
||||
};
|
||||
@ -134,7 +135,7 @@ public class SerialPersistentFieldsTest {
|
||||
" @Override public void readExternal(ObjectInput in) {\n" +
|
||||
" throw new AssertionError(\"should not reach here\");\n" +
|
||||
" } }",
|
||||
"--enable-preview", "-source", "14");
|
||||
"--enable-preview", "-source", VERSION);
|
||||
ObjectStreamField[] serialPersistentFields = {
|
||||
new ObjectStreamField("v", String.class)
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user