You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2018/10/19 13:48:43 UTC

[GitHub] asfgit closed pull request #6755: [FLINK-10412] toString field in AbstractID should be transient to avoid been serialized

asfgit closed pull request #6755: [FLINK-10412] toString field in AbstractID should be transient to avoid been serialized
URL: https://github.com/apache/flink/pull/6755
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/flink-core/src/main/java/org/apache/flink/util/AbstractID.java b/flink-core/src/main/java/org/apache/flink/util/AbstractID.java
index 41083c60783..b7be21a3a57 100644
--- a/flink-core/src/main/java/org/apache/flink/util/AbstractID.java
+++ b/flink-core/src/main/java/org/apache/flink/util/AbstractID.java
@@ -47,7 +47,7 @@
 	protected final long lowerPart;
 
 	/** The memoized value returned by toString(). */
-	private String toString;
+	private transient String toString;
 
 	// --------------------------------------------------------------------------------------------
 
diff --git a/flink-core/src/test/java/org/apache/flink/util/AbstractIDTest.java b/flink-core/src/test/java/org/apache/flink/util/AbstractIDTest.java
index 93def48a28d..65bd6b22093 100644
--- a/flink-core/src/test/java/org/apache/flink/util/AbstractIDTest.java
+++ b/flink-core/src/test/java/org/apache/flink/util/AbstractIDTest.java
@@ -22,7 +22,12 @@
 
 import org.junit.Test;
 
+import java.io.InputStream;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 /**
@@ -101,6 +106,35 @@ public void testCompare() throws Exception {
 		assertCompare(id8, id10, -1);
 	}
 
+	/**
+	 * FLINK-10412 marks the {@link AbstractID#toString} field as transient. This tests ensures
+	 * that {@link AbstractID} which have been serialized with the toString field can still
+	 * be deserialized. For that purpose the files abstractID-with-toString-field and
+	 * abstractID-with-toString-field-set have been created with the serialized data.
+	 */
+	@Test
+	public void testOldAbstractIDDeserialization() throws Exception {
+		final long lowerPart = 42L;
+		final long upperPart = 1337L;
+		final AbstractID expectedAbstractId = new AbstractID(lowerPart, upperPart);
+
+		final String resourceName1 = "abstractID-with-toString-field";
+		try (final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(resourceName1)) {
+			final AbstractID deserializedAbstractId = InstantiationUtil.deserializeObject(
+				resourceAsStream,
+				getClass().getClassLoader());
+			assertThat(deserializedAbstractId, is(equalTo(expectedAbstractId)));
+		}
+
+		final String resourceName2 = "abstractID-with-toString-field-set";
+		try (final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(resourceName2)) {
+			final AbstractID deserializedAbstractId = InstantiationUtil.deserializeObject(
+				resourceAsStream,
+				getClass().getClassLoader());
+			assertThat(deserializedAbstractId, is(equalTo(expectedAbstractId)));
+		}
+	}
+
 	private static void assertCompare(AbstractID a, AbstractID b, int signum) {
 		int cmpAB = a.compareTo(b);
 		int cmpBA = b.compareTo(a);
diff --git a/flink-core/src/test/resources/abstractID-with-toString-field b/flink-core/src/test/resources/abstractID-with-toString-field
new file mode 100644
index 00000000000..92564b487ce
Binary files /dev/null and b/flink-core/src/test/resources/abstractID-with-toString-field differ
diff --git a/flink-core/src/test/resources/abstractID-with-toString-field-set b/flink-core/src/test/resources/abstractID-with-toString-field-set
new file mode 100644
index 00000000000..bdf9b81b33d
Binary files /dev/null and b/flink-core/src/test/resources/abstractID-with-toString-field-set differ


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services