This is an automated email from the ASF dual-hosted git repository. paulk pushed a commit to branch GROOVY_2_4_X in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 00e4d903330b707dc3ce44b2aa2a33095d1f4720 Author: Paul King <[email protected]> AuthorDate: Thu Nov 26 14:26:49 2020 +1000 GROOVY-9826: Better propagation of InterruptedException (port to 2_4_X) --- .../groovy/runtime/ProcessGroovyMethods.java | 26 ++-- .../org/codehaus/groovy/util/ReferenceManager.java | 1 + .../groovy/jmx/builder/JmxConnectorHelper.java | 132 ++++++++++----------- 3 files changed, 85 insertions(+), 74 deletions(-) diff --git a/src/main/org/codehaus/groovy/runtime/ProcessGroovyMethods.java b/src/main/org/codehaus/groovy/runtime/ProcessGroovyMethods.java index 02204c5..7327a52 100644 --- a/src/main/org/codehaus/groovy/runtime/ProcessGroovyMethods.java +++ b/src/main/org/codehaus/groovy/runtime/ProcessGroovyMethods.java @@ -241,10 +241,15 @@ public class ProcessGroovyMethods extends DefaultGroovyMethodsSupport { public static void waitForProcessOutput(Process self, Appendable output, Appendable error) { Thread tout = consumeProcessOutputStream(self, output); Thread terr = consumeProcessErrorStream(self, error); - try { tout.join(); } catch (InterruptedException ignore) {} - try { terr.join(); } catch (InterruptedException ignore) {} - try { self.waitFor(); } catch (InterruptedException ignore) {} - closeStreams(self); + boolean interrupted = false; + try { + try { tout.join(); } catch (InterruptedException ignore) { interrupted = true; } + try { terr.join(); } catch (InterruptedException ignore) { interrupted = true; } + try { self.waitFor(); } catch (InterruptedException ignore) { interrupted = true; } + closeStreams(self); + } finally { + if (interrupted) Thread.currentThread().interrupt(); + } } /** @@ -263,10 +268,15 @@ public class ProcessGroovyMethods extends DefaultGroovyMethodsSupport { public static void waitForProcessOutput(Process self, OutputStream output, OutputStream error) { Thread tout = consumeProcessOutputStream(self, output); Thread terr = consumeProcessErrorStream(self, error); - try { tout.join(); } catch (InterruptedException ignore) {} - try { terr.join(); } catch (InterruptedException ignore) {} - try { self.waitFor(); } catch (InterruptedException ignore) {} - closeStreams(self); + boolean interrupted = false; + try { + try { tout.join(); } catch (InterruptedException ignore) { interrupted = true; } + try { terr.join(); } catch (InterruptedException ignore) { interrupted = true; } + try { self.waitFor(); } catch (InterruptedException ignore) { interrupted = true; } + closeStreams(self); + } finally { + if (interrupted) Thread.currentThread().interrupt(); + } } /** diff --git a/src/main/org/codehaus/groovy/util/ReferenceManager.java b/src/main/org/codehaus/groovy/util/ReferenceManager.java index 6ab6d56..00ef8b3 100644 --- a/src/main/org/codehaus/groovy/util/ReferenceManager.java +++ b/src/main/org/codehaus/groovy/util/ReferenceManager.java @@ -36,6 +36,7 @@ public class ReferenceManager { try { r = queue.remove(1000); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); break; } if (r==null) continue; diff --git a/subprojects/groovy-jmx/src/test/java/groovy/jmx/builder/JmxConnectorHelper.java b/subprojects/groovy-jmx/src/test/java/groovy/jmx/builder/JmxConnectorHelper.java index e3fe10c..4e6f904 100644 --- a/subprojects/groovy-jmx/src/test/java/groovy/jmx/builder/JmxConnectorHelper.java +++ b/subprojects/groovy-jmx/src/test/java/groovy/jmx/builder/JmxConnectorHelper.java @@ -1,66 +1,66 @@ -/* - * 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 groovy.jmx.builder; - -import java.rmi.NoSuchObjectException; -import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; -import java.util.HashMap; -import java.util.Map; - -/** - * Helper class to help with RMI - */ -public class JmxConnectorHelper { - public static Map createRmiRegistry(int initPort) { - Map<String, Object> result = new HashMap<String, Object>(2); - int counter = 0; - int port = initPort; - Registry reg = null; - while (reg == null && counter <= 4) { - try { - reg = LocateRegistry.createRegistry(port); - result.put("registry", reg); - result.put("port", port); - break; - } catch (RemoteException ex) { - counter++; - port = port + 1; - System.out.println("JmxBuilder - *** FAILED *** to create RMI Registry - Will Retry on port [" + port + "]."); - try { - Thread.currentThread().sleep(500); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - } - return result; - } - - public static void destroyRmiRegistry(Registry reg) { - try { - if (reg != null) { - java.rmi.server.UnicastRemoteObject.unexportObject(reg, true); - } - } catch (NoSuchObjectException e) { - throw new RuntimeException(e); - } - } -} +/* + * 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 groovy.jmx.builder; + +import java.rmi.NoSuchObjectException; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.util.HashMap; +import java.util.Map; + +/** + * Helper class to help with RMI + */ +public class JmxConnectorHelper { + public static Map createRmiRegistry(int initPort) { + Map<String, Object> result = new HashMap<String, Object>(2); + int counter = 0; + int port = initPort; + Registry reg = null; + while (reg == null && counter <= 4) { + try { + reg = LocateRegistry.createRegistry(port); + result.put("registry", reg); + result.put("port", port); + break; + } catch (RemoteException ex) { + counter++; + port = port + 1; + System.out.println("JmxBuilder - *** FAILED *** to create RMI Registry - Will Retry on port [" + port + "]."); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + return result; + } + + public static void destroyRmiRegistry(Registry reg) { + try { + if (reg != null) { + java.rmi.server.UnicastRemoteObject.unexportObject(reg, true); + } + } catch (NoSuchObjectException e) { + throw new RuntimeException(e); + } + } +}
