From 60f324eb1b8db2b910cc952ef6accdad22d45afc Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 9 Feb 2019 13:59:06 +0100 Subject: [PATCH] Make writer/reader fields final in XMPPTCPConnection --- .../org/jivesoftware/smack/tcp/XMPPTCPConnection.java | 10 ++-------- .../org/jivesoftware/smack/tcp/PacketWriterTest.java | 8 +++----- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 0774e4375..af7ffdeeb 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -173,12 +173,12 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { /** * Protected access level because of unit test purposes */ - protected PacketWriter packetWriter; + protected final PacketWriter packetWriter = new PacketWriter(); /** * Protected access level because of unit test purposes */ - protected PacketReader packetReader; + protected final PacketReader packetReader = new PacketReader(); private final SynchronizationPoint initialOpenStreamSend = new SynchronizationPoint<>( this, "initial open stream element send to server"); @@ -642,17 +642,11 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { * @throws InterruptedException */ private void initConnection() throws IOException, InterruptedException { - boolean isFirstInitialization = packetReader == null || packetWriter == null; compressionHandler = null; // Set the reader and writer instance variables initReaderAndWriter(); - if (isFirstInitialization) { - packetWriter = new PacketWriter(); - packetReader = new PacketReader(); - } - int availableReaderWriterSemaphorePermits = readerWriterSemaphore.availablePermits(); if (availableReaderWriterSemaphorePermits < 2) { Object[] logObjects = new Object[] { diff --git a/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/PacketWriterTest.java b/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/PacketWriterTest.java index c72996783..c28ec85e4 100644 --- a/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/PacketWriterTest.java +++ b/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/PacketWriterTest.java @@ -1,6 +1,6 @@ /** * - * Copyright 2014 Florian Schmaus + * Copyright 2014-2019 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,11 +49,9 @@ public class PacketWriterTest { @Test public void shouldBlockAndUnblockTest() throws InterruptedException, BrokenBarrierException, NotConnectedException, XmppStringprepException { XMPPTCPConnection connection = new XMPPTCPConnection("user", "pass", "example.org"); - final PacketWriter pw = connection.new PacketWriter(); - connection.packetWriter = pw; - connection.packetReader = connection.new PacketReader(); + final PacketWriter pw = connection.packetWriter; connection.setWriter(new BlockingStringWriter()); - pw.init(); + connection.packetWriter.init(); for (int i = 0; i < XMPPTCPConnection.PacketWriter.QUEUE_SIZE; i++) { pw.sendStreamElement(new Message());