Skip to content

Commit baec3f0

Browse files
committed
NET-264 Telnet spyStream NullPointerException
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/net/branches/NET_2_0@942955 13f79535-47bb-0310-9956-ffa450edef68
1 parent b60e513 commit baec3f0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/main/java/org/apache/commons/net/telnet/Telnet.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Telnet extends SocketClient
125125
/***
126126
* The stream on which to spy
127127
***/
128-
private OutputStream spyStream = null;
128+
private volatile OutputStream spyStream = null;
129129

130130
/***
131131
* The notification handler
@@ -1248,18 +1248,19 @@ void _stopSpyStream()
12481248
***/
12491249
void _spyRead(int ch)
12501250
{
1251-
if (spyStream != null)
1251+
OutputStream spy = spyStream;
1252+
if (spy != null)
12521253
{
12531254
try
12541255
{
12551256
if (ch != '\r')
12561257
{
1257-
spyStream.write(ch);
1258+
spy.write(ch);
12581259
if (ch == '\n')
12591260
{
1260-
spyStream.write('\r');
1261+
spy.write('\r');
12611262
}
1262-
spyStream.flush();
1263+
spy.flush();
12631264
}
12641265
}
12651266
catch (IOException e)
@@ -1279,12 +1280,13 @@ void _spyWrite(int ch)
12791280
if (!(_stateIsDo(TelnetOption.ECHO)
12801281
&& _requestedDo(TelnetOption.ECHO)))
12811282
{
1282-
if (spyStream != null)
1283+
OutputStream spy = spyStream;
1284+
if (spy != null)
12831285
{
12841286
try
12851287
{
1286-
spyStream.write(ch);
1287-
spyStream.flush();
1288+
spy.write(ch);
1289+
spy.flush();
12881290
}
12891291
catch (IOException e)
12901292
{

0 commit comments

Comments
 (0)