From c798cf3db806306f570561a5b2935dbc9aaf2fbb Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 18 Feb 2005 11:00:58 +0000 Subject: [PATCH] Don't close SocketClients if connect has failed, PR 33618 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277682 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 ++++ .../ant/taskdefs/optional/net/RExecTask.java | 20 +++++++++---------- .../ant/taskdefs/optional/net/TelnetTask.java | 4 ++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 8bc4caa29..8548f7be3 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -318,6 +318,10 @@ Fixed bugs: , , or tasks was always logged to System.out instead of to the managing Task. +* and would try to disconnect from servers they never + connetced to, potentially leading to exceptions in commons-net. + Bugzilla Report 33618. + Changes from Ant 1.6.1 to Ant 1.6.2 =================================== diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java index 3a15b7bcf..b47fbb87e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004 The Apache Software Foundation + * Copyright 2003-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -342,15 +342,15 @@ public class RExecTask extends Task { /** Keep reading input stream until end of it or time-out */ rexec.waitForEOF(defaultTimeout); } finally { - if (rexec != null) { - try { - rexec.disconnect(); - } catch (IOException e) { - throw new BuildException("Error disconnecting from " - + server); - } - } - } + if (rexec != null && rexec.isConnected()) { + try { + rexec.disconnect(); + } catch (IOException e) { + throw new BuildException("Error disconnecting from " + + server); + } + } + } } /** * Process a 'typical' login. If it differs, use the read diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java index b104e8a51..d89a35c50 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2000,2002-2004 The Apache Software Foundation + * Copyright 2000,2002-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -114,7 +114,7 @@ public class TelnetTask extends Task { task.execute(telnet); } } finally { - if (telnet != null) { + if (telnet != null && telnet.isConnected()) { try { telnet.disconnect(); } catch (IOException e) {