flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trohrm...@apache.org
Subject flink git commit: [FLINK-5643] Fix NPE in StateUtil
Date Wed, 25 Jan 2017 14:23:03 GMT
Repository: flink
Updated Branches:
  refs/heads/release-1.2 887c074a7 -> f61f331ff


[FLINK-5643] Fix NPE in StateUtil

Introduces a null check to deal with state futures which have a null value.

This closes #3213.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/f61f331f
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/f61f331f
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/f61f331f

Branch: refs/heads/release-1.2
Commit: f61f331ff04426e8b07117e2a568749fb036e1cc
Parents: 887c074
Author: Till Rohrmann <trohrmann@apache.org>
Authored: Wed Jan 25 14:39:51 2017 +0100
Committer: Till Rohrmann <trohrmann@apache.org>
Committed: Wed Jan 25 15:22:23 2017 +0100

----------------------------------------------------------------------
 .../apache/flink/runtime/state/StateUtil.java   |  4 ++-
 .../flink/runtime/state/StateUtilTest.java      | 36 ++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/f61f331f/flink-runtime/src/main/java/org/apache/flink/runtime/state/StateUtil.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/state/StateUtil.java b/flink-runtime/src/main/java/org/apache/flink/runtime/state/StateUtil.java
index 19afdec..c6f5c86 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/state/StateUtil.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/state/StateUtil.java
@@ -78,7 +78,9 @@ public class StateUtil {
 			if (!stateFuture.cancel(true)) {
 				StateObject stateObject = FutureUtil.runIfNotDoneAndGet(stateFuture);
 
-				stateObject.discardState();
+				if (null != stateObject) {
+					stateObject.discardState();
+				}
 			}
 		}
 	}

http://git-wip-us.apache.org/repos/asf/flink/blob/f61f331f/flink-runtime/src/test/java/org/apache/flink/runtime/state/StateUtilTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/state/StateUtilTest.java
b/flink-runtime/src/test/java/org/apache/flink/runtime/state/StateUtilTest.java
new file mode 100644
index 0000000..e59d027
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/state/StateUtilTest.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.state;
+
+import org.apache.flink.util.TestLogger;
+import org.junit.Test;
+
+import java.util.concurrent.RunnableFuture;
+
+public class StateUtilTest extends TestLogger {
+
+	/**
+	 * Tests that {@link StateUtil#discardStateFuture} can handle state futures with null value.
+	 */
+	@Test
+	public void testDiscardRunnableFutureWithNullValue() throws Exception {
+		RunnableFuture<StateHandle<?>> stateFuture = new DoneFuture<>(null);
+		StateUtil.discardStateFuture(stateFuture);
+	}
+}


Mime
View raw message