From 228515e7783aecdb992258765554a530d6c831f3 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Sat, 14 Apr 2012 18:11:11 +0200 Subject: OfficeConnection: kill soffice process when Java bridge is disposed In the rare case that the soffice process outlives the Java side UNO bridge, ensure that soffice.bin doesn't continue running. --- .../java/org/openoffice/test/OfficeConnection.java | 39 +++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'unotest') diff --git a/unotest/source/java/org/openoffice/test/OfficeConnection.java b/unotest/source/java/org/openoffice/test/OfficeConnection.java index 5eb3afa88723..2b7e34fd307a 100644 --- a/unotest/source/java/org/openoffice/test/OfficeConnection.java +++ b/unotest/source/java/org/openoffice/test/OfficeConnection.java @@ -119,24 +119,33 @@ public final class OfficeConnection { boolean desktopTerminated = true; if (process != null) { if (context != null) { - XMultiComponentFactory factory = context.getServiceManager(); - assertNotNull(factory); - XDesktop desktop = UnoRuntime.queryInterface( - XDesktop.class, - factory.createInstanceWithContext( - "com.sun.star.frame.Desktop", context)); - context = null; + XDesktop desktop = null; try { - desktopTerminated = desktop.terminate(); - if (!desktopTerminated) { - // in case terminate() fails we would wait forever - // for the process to die, so kill it - process.destroy(); - } - assertTrue(desktopTerminated); - } catch (DisposedException e) {} + XMultiComponentFactory factory = + context.getServiceManager(); + assertNotNull(factory); + desktop = UnoRuntime.queryInterface(XDesktop.class, + factory.createInstanceWithContext( + "com.sun.star.frame.Desktop", context)); + } catch (DisposedException e) { + // it can happen that the Java bridge was disposed + // already, we want to ensure soffice.bin is killed + process.destroy(); + } + context = null; + if (desktop != null) { + try { + desktopTerminated = desktop.terminate(); + if (!desktopTerminated) { + // in case terminate() fails we would wait + // forever for the process to die, so kill it + process.destroy(); + } + assertTrue(desktopTerminated); + } catch (DisposedException e) {} // it appears that DisposedExceptions can already happen // while receiving the response of the terminate call + } desktop = null; } else { process.destroy(); -- cgit