Repository: flink Updated Branches: refs/heads/master 2dfd463e2 -> 3cfd1053c
[FLINK-6080] Unclosed ObjectOutputStream in NFA#serialize() Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/3cfd1053 Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/3cfd1053 Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/3cfd1053 Branch: refs/heads/master Commit: 3cfd1053cdddc6a2cb8d2a41a28e894fa51084f4 Parents: 2dfd463 Author: Dawid Wysakowicz <[email protected]> Authored: Tue Mar 21 12:06:42 2017 +0100 Committer: kl0u <[email protected]> Committed: Wed Mar 22 13:41:38 2017 +0100 ---------------------------------------------------------------------- .../src/main/java/org/apache/flink/cep/nfa/NFA.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flink/blob/3cfd1053/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/NFA.java ---------------------------------------------------------------------- diff --git a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/NFA.java b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/NFA.java index 12afe4e..257418a 100644 --- a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/NFA.java +++ b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/NFA.java @@ -567,6 +567,8 @@ public class NFA<T> implements Serializable { @SuppressWarnings("unchecked") NFA<T> copy = (NFA<T>) ois.readObject(); + ois.close(); + bais.close(); return copy; } catch (IOException|ClassNotFoundException e) { throw new RuntimeException("Could not copy NFA.", e); @@ -585,16 +587,15 @@ public class NFA<T> implements Serializable { @Override public void serialize(NFA<T> record, DataOutputView target) throws IOException { - ObjectOutputStream oos = new ObjectOutputStream(new DataOutputViewStream(target)); - oos.writeObject(record); - oos.flush(); + try (ObjectOutputStream oos = new ObjectOutputStream(new DataOutputViewStream(target))) { + oos.writeObject(record); + oos.flush(); + } } @Override public NFA<T> deserialize(DataInputView source) throws IOException { - ObjectInputStream ois = new ObjectInputStream(new DataInputViewStream(source)); - - try { + try (ObjectInputStream ois = new ObjectInputStream(new DataInputViewStream(source))) { return (NFA<T>) ois.readObject(); } catch (ClassNotFoundException e) { throw new RuntimeException("Could not deserialize NFA.", e);
