diff options
author | 2018-07-09 13:18:37 -0700 | |
---|---|---|
committer | 2018-07-09 13:23:17 -0700 | |
commit | d4c3d3f8d7ce94ad7569feead442fa08b6dfe96c (patch) | |
tree | 0dee4319f595bacbcd771f369f3c59c06b0c08f9 /tensorflow/contrib | |
parent | 8464b4d6c44d19ebde7b84ed43debc2362d8eff3 (diff) |
Avoid exceptions in the Interpreter finalizer
PiperOrigin-RevId: 203817866
Diffstat (limited to 'tensorflow/contrib')
-rw-r--r-- | tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java | 6 | ||||
-rw-r--r-- | tensorflow/contrib/lite/java/src/test/java/org/tensorflow/lite/InterpreterTest.java | 7 |
2 files changed, 11 insertions, 2 deletions
diff --git a/tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java b/tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java index 4e22a68bf2..589fd6426f 100644 --- a/tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java +++ b/tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java @@ -251,8 +251,10 @@ public final class Interpreter implements AutoCloseable { /** Release resources associated with the {@code Interpreter}. */ @Override public void close() { - wrapper.close(); - wrapper = null; + if (wrapper != null) { + wrapper.close(); + wrapper = null; + } } @Override diff --git a/tensorflow/contrib/lite/java/src/test/java/org/tensorflow/lite/InterpreterTest.java b/tensorflow/contrib/lite/java/src/test/java/org/tensorflow/lite/InterpreterTest.java index e6deadffe2..42096ef9a3 100644 --- a/tensorflow/contrib/lite/java/src/test/java/org/tensorflow/lite/InterpreterTest.java +++ b/tensorflow/contrib/lite/java/src/test/java/org/tensorflow/lite/InterpreterTest.java @@ -329,4 +329,11 @@ public final class InterpreterTest { interpreter.close(); fileChannel.close(); } + + @Test + public void testRedundantClose() throws Exception { + Interpreter interpreter = new Interpreter(MODEL_FILE); + interpreter.close(); + interpreter.close(); + } } |