diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 4a7af6505..f0061dd2c 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -485,7 +485,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } protected void bindResourceAndEstablishSession(String resource) throws XMPPErrorException, - IOException, SmackException, InterruptedException { + SmackException, InterruptedException { // Wait until either: // - the servers last features stanza has been parsed @@ -1392,6 +1392,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { afterFeaturesReceived(); } + @SuppressWarnings("unused") protected void afterFeaturesReceived() throws SecurityRequiredException, NotConnectedException, InterruptedException { // Default implementation does nothing } diff --git a/smack-core/src/test/java/org/jivesoftware/smack/packet/MessageTest.java b/smack-core/src/test/java/org/jivesoftware/smack/packet/MessageTest.java index 1b5e74b54..51799454e 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/packet/MessageTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/packet/MessageTest.java @@ -30,15 +30,13 @@ import java.util.Collection; import java.util.List; import java.util.ArrayList; -import javax.xml.parsers.ParserConfigurationException; - /** * */ public class MessageTest { @Test - public void setMessageTypeTest() throws IOException, SAXException, ParserConfigurationException { + public void setMessageTypeTest() throws IOException, SAXException { Message.Type type = Message.Type.chat; Message.Type type2 = Message.Type.headline; @@ -76,7 +74,7 @@ public class MessageTest { } @Test - public void setMessageSubjectTest() throws IOException, SAXException, ParserConfigurationException { + public void setMessageSubjectTest() throws IOException, SAXException { final String messageSubject = "This is a test of the emergency broadcast system."; StringBuilder controlBuilder = new StringBuilder(); @@ -95,7 +93,7 @@ public class MessageTest { } @Test - public void oneMessageBodyTest() throws IOException, SAXException, ParserConfigurationException { + public void oneMessageBodyTest() throws IOException, SAXException { final String messageBody = "This is a test of the emergency broadcast system."; StringBuilder controlBuilder = new StringBuilder(); @@ -114,7 +112,7 @@ public class MessageTest { } @Test - public void multipleMessageBodiesTest() throws IOException, SAXException, ParserConfigurationException { + public void multipleMessageBodiesTest() throws IOException, SAXException { final String messageBody1 = "This is a test of the emergency broadcast system, 1."; final String lang2 = "ru"; final String messageBody2 = "This is a test of the emergency broadcast system, 2."; @@ -172,7 +170,7 @@ public class MessageTest { } @Test - public void setMessageThreadTest() throws IOException, SAXException, ParserConfigurationException { + public void setMessageThreadTest() throws IOException, SAXException { final String messageThread = "1234"; StringBuilder controlBuilder = new StringBuilder(); @@ -191,7 +189,7 @@ public class MessageTest { } @Test - public void messageXmlLangTest() throws IOException, SAXException, ParserConfigurationException { + public void messageXmlLangTest() throws IOException, SAXException { final String lang = "sp"; StringBuilder controlBuilder = new StringBuilder(); diff --git a/smack-core/src/test/java/org/jivesoftware/smack/packet/PresenceTest.java b/smack-core/src/test/java/org/jivesoftware/smack/packet/PresenceTest.java index 047f37d6b..fbd8083ae 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/packet/PresenceTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/packet/PresenceTest.java @@ -27,14 +27,12 @@ import org.xml.sax.SAXException; import java.io.IOException; -import javax.xml.parsers.ParserConfigurationException; - /** * */ public class PresenceTest { @Test - public void setPresenceTypeTest() throws IOException, SAXException, ParserConfigurationException { + public void setPresenceTypeTest() throws IOException, SAXException { Presence.Type type = Presence.Type.unavailable; Presence.Type type2 = Presence.Type.subscribe; @@ -81,7 +79,7 @@ public class PresenceTest { } @Test - public void setPresenceStatusTest() throws IOException, SAXException, ParserConfigurationException { + public void setPresenceStatusTest() throws IOException, SAXException { final String status = "This is a test of the emergency broadcast system."; StringBuilder controlBuilder = new StringBuilder(); @@ -100,7 +98,7 @@ public class PresenceTest { } @Test - public void setPresencePriorityTest() throws IOException, SAXException, ParserConfigurationException { + public void setPresencePriorityTest() throws IOException, SAXException { final int priority = 10; StringBuilder controlBuilder = new StringBuilder(); @@ -124,7 +122,7 @@ public class PresenceTest { } @Test - public void setPresenceModeTest() throws IOException, SAXException, ParserConfigurationException { + public void setPresenceModeTest() throws IOException, SAXException { Presence.Mode mode1 = Presence.Mode.dnd; final int priority = 10; final String status = "This is a test of the emergency broadcast system."; @@ -175,7 +173,7 @@ public class PresenceTest { } @Test - public void presenceXmlLangTest() throws IOException, SAXException, ParserConfigurationException { + public void presenceXmlLangTest() throws IOException, SAXException { final String lang = "sp"; StringBuilder controlBuilder = new StringBuilder(); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bookmarks/BookmarkManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bookmarks/BookmarkManager.java index 54ec74a61..772d54469 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bookmarks/BookmarkManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bookmarks/BookmarkManager.java @@ -66,11 +66,12 @@ public class BookmarkManager { BookmarkManager manager = bookmarkManagerMap.get(connection); if (manager == null) { manager = new BookmarkManager(connection); + bookmarkManagerMap.put(connection, manager); } return manager; } - private PrivateDataManager privateDataManager; + private final PrivateDataManager privateDataManager; private Bookmarks bookmarks; private final Object bookmarkLock = new Object(); @@ -80,9 +81,8 @@ public class BookmarkManager { * * @param connection the connection for persisting and retrieving bookmarks. */ - private BookmarkManager(XMPPConnection connection) throws XMPPException, SmackException { + private BookmarkManager(XMPPConnection connection) { privateDataManager = PrivateDataManager.getInstanceFor(connection); - bookmarkManagerMap.put(connection, this); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateManager.java index 629d7004e..84d07fbee 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateManager.java @@ -142,7 +142,7 @@ public class ChatStateManager extends Manager { return false; } - private void fireNewChatState(Chat chat, ChatState state) { + private static void fireNewChatState(Chat chat, ChatState state) { for (ChatMessageListener listener : chat.getListeners()) { if (listener instanceof ChatStateListener) { ((ChatStateListener) listener).stateChanged(chat, state); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java index cd2350203..23e8d41c9 100755 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java @@ -574,7 +574,7 @@ public class AdHocCommandManager extends Manager { * @param condition the condition of the error. * @throws NotConnectedException */ - private IQ respondError(AdHocCommandData response, + private static IQ respondError(AdHocCommandData response, XMPPError.Condition condition) { return respondError(response, new XMPPError(condition)); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IncomingFileTransfer.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IncomingFileTransfer.java index d8e63d3db..2783e6910 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IncomingFileTransfer.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IncomingFileTransfer.java @@ -31,6 +31,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; @@ -193,10 +194,20 @@ public class IncomingFileTransfer extends FileTransfer { try { inputStream = streamNegotiatorTask.get(15, TimeUnit.SECONDS); } - catch (InterruptedException e) { - throw new SmackException("Interruption while executing", e); - } catch (ExecutionException e) { + final Throwable cause = e.getCause(); + if (cause instanceof XMPPErrorException) { + throw (XMPPErrorException) cause; + } + if (cause instanceof InterruptedException) { + throw (InterruptedException) cause; + } + if (cause instanceof NoResponseException) { + throw (NoResponseException) cause; + } + if (cause instanceof SmackException) { + throw (SmackException) cause; + } throw new SmackException("Error in execution", e); } catch (TimeoutException e) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java index d08a74403..6883afe8f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java @@ -87,9 +87,7 @@ public abstract class StreamNegotiator { } protected final IQ initiateIncomingStream(final XMPPConnection connection, StreamInitiation initiation) - // CHECKSTYLE:OFF - throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - // CHECKSTYLE:ON + throws NoResponseException, XMPPErrorException, NotConnectedException { final StreamInitiation response = createInitiationAccept(initiation, getNamespaces()); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java index 484bfedfb..cf6e97efc 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java @@ -47,16 +47,6 @@ public class PubSub extends IQ setType(type); } - /** - * Returns the XML element name of the extension sub-packet root element. - * - * @return the XML element name of the stanza(/packet) extension. - */ - @SuppressWarnings("static-method") - public String getElementName() { - return ELEMENT; - } - @SuppressWarnings("unchecked") public PE getExtension(PubSubElementType elem) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdatalayout/provider/DataLayoutProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdatalayout/provider/DataLayoutProvider.java index 80b5a0101..22972035a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdatalayout/provider/DataLayoutProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdatalayout/provider/DataLayoutProvider.java @@ -19,7 +19,6 @@ package org.jivesoftware.smackx.xdatalayout.provider; import java.io.IOException; import java.util.List; -import org.jivesoftware.smack.SmackException; import org.jivesoftware.smackx.xdatalayout.packet.DataLayout; import org.jivesoftware.smackx.xdatalayout.packet.DataLayout.DataFormLayoutElement; import org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Fieldref; @@ -37,8 +36,7 @@ import org.xmlpull.v1.XmlPullParserException; */ public class DataLayoutProvider { - public static DataLayout parse(XmlPullParser parser) throws XmlPullParserException, IOException, - SmackException { + public static DataLayout parse(XmlPullParser parser) throws XmlPullParserException, IOException { DataLayout dataLayout = new DataLayout(parser.getAttributeValue("", "label")); parseLayout(dataLayout.getPageLayout(), parser); return dataLayout; diff --git a/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java index dd0be407f..cec5af577 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java @@ -360,7 +360,7 @@ public class ChatManager extends Manager{ return Collections.unmodifiableSet(chatManagerListeners); } - private void deliverMessage(Chat chat, Message message) { + private static void deliverMessage(Chat chat, Message message) { // Here we will run any interceptors chat.deliver(message); } diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java index a826f6db6..ab42aedf7 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java @@ -177,7 +177,7 @@ public class DirectoryRosterStore implements RosterStore { return setRosterVersion(version); } - private Item readEntry(File file) { + private static Item readEntry(File file) { String s = FileUtils.readFile(file); if (s == null) { return null; diff --git a/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java b/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java index e7fcee880..e23df76b8 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java @@ -322,7 +322,7 @@ public class ChatConnectionTest { assertNull(listener.getNewChat()); } - private Message createChatPacket(final String threadId, final boolean isFullJid) { + private static Message createChatPacket(final String threadId, final boolean isFullJid) { Message chatMsg = new Message(JidTestUtil.BARE_JID_1, Message.Type.chat); chatMsg.setBody("the body message - " + System.currentTimeMillis()); Jid jid; diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java index 930c6b919..d4b12481b 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java @@ -21,7 +21,6 @@ import static org.junit.Assert.assertNotNull; import org.jivesoftware.smack.DummyConnection; import org.jivesoftware.smack.SmackException; -import org.jivesoftware.smack.XMPPException; import org.junit.Before; import org.junit.Test; @@ -37,7 +36,7 @@ public class RosterOfflineTest { Roster roster; @Before - public void setup() throws XMPPException, SmackException { + public void setup() { this.connection = new DummyConnection(); assertFalse(connection.isConnected()); diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java index b4210a2fa..4f7732fb2 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java @@ -32,7 +32,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import org.jivesoftware.smack.DummyConnection; import org.jivesoftware.smack.SmackException; -import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.im.InitSmackIm; import org.jivesoftware.smack.packet.ErrorIQ; import org.jivesoftware.smack.packet.IQ; @@ -511,8 +510,7 @@ public class RosterTest extends InitSmackIm { * @param connection the dummy connection of which the provided roster belongs to. * @param roster the roster (or buddy list) which should be initialized. */ - public static void removeAllRosterEntries(DummyConnection connection, Roster roster) - throws InterruptedException, XMPPException { + public static void removeAllRosterEntries(DummyConnection connection, Roster roster) { for(RosterEntry entry : roster.getEntries()) { // prepare the roster push packet final RosterPacket rosterPush= new RosterPacket(); @@ -539,7 +537,7 @@ public class RosterTest extends InitSmackIm { * @throws SmackException * @throws XmppStringprepException */ - private void initRoster() throws InterruptedException, XMPPException, SmackException, XmppStringprepException { + private void initRoster() throws InterruptedException, SmackException, XmppStringprepException { roster.reload(); while (true) { final Stanza sentPacket = connection.getSentPacket(); diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java index 5ccf8c999..ab968816e 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java @@ -135,7 +135,7 @@ public class RosterVersioningTest { * @throws XmppStringprepException */ @Test(timeout = 5000) - public void testOtherVersionStored() throws InterruptedException, XMPPException, SmackException, XmppStringprepException { + public void testOtherVersionStored() throws XMPPException, SmackException, XmppStringprepException { Item vaglafItem = vaglafItem(); // We expect that the roster request is the only packet sent. This is not part of the specification, @@ -226,7 +226,7 @@ public class RosterVersioningTest { } } - private Item vaglafItem() throws XmppStringprepException { + private static Item vaglafItem() throws XmppStringprepException { Item item = new Item(JidCreate.from("vaglaf@example.com"), "vaglaf the only"); item.setItemType(ItemType.both); item.addGroupName("all"); @@ -235,7 +235,7 @@ public class RosterVersioningTest { return item; } - private void populateStore(RosterStore store) throws IOException { + private static void populateStore(RosterStore store) throws IOException { store.addEntry(new RosterPacket.Item(JidCreate.from("geoff@example.com"), "geoff hurley"), ""); RosterPacket.Item item = new RosterPacket.Item(JidCreate.from("joe@example.com"), "joe stevens"); @@ -249,7 +249,7 @@ public class RosterVersioningTest { store.addEntry(item, "v96"); } - private void answerWithEmptyRosterResult() throws InterruptedException { + private void answerWithEmptyRosterResult() { // We expect that the roster request is the only packet sent. This is not part of the specification, // but a shortcut in the test implementation. Stanza sentPacket = connection.getSentPacket(); diff --git a/smack-java7/src/main/java/org/jivesoftware/smack/util/stringencoder/java7/Base64.java b/smack-java7/src/main/java/org/jivesoftware/smack/util/stringencoder/java7/Base64.java index 1427ac17c..ca2f92fa1 100644 --- a/smack-java7/src/main/java/org/jivesoftware/smack/util/stringencoder/java7/Base64.java +++ b/smack-java7/src/main/java/org/jivesoftware/smack/util/stringencoder/java7/Base64.java @@ -898,7 +898,7 @@ public class Base64 if( bytes != null && bytes.length >= 4 ) { - int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); + int head = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head ) { java.io.ByteArrayInputStream bais = null; @@ -969,12 +969,10 @@ public class Base64 catch( java.io.IOException e ) { LOGGER.log(Level.SEVERE, "Error reading object", e); - obj = null; } // end catch catch( java.lang.ClassNotFoundException e ) { LOGGER.log(Level.SEVERE, "Class not found for encoded object", e); - obj = null; } // end catch finally { 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 3ef6ce677..cf5d56414 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 @@ -669,14 +669,8 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { KeyManager[] kms = null; PasswordCallback pcb = null; - if(config.getCallbackHandler() == null) { - ks = null; - } else if (context == null) { - if(config.getKeystoreType().equals("NONE")) { - ks = null; - pcb = null; - } - else if(config.getKeystoreType().equals("PKCS11")) { + if (context == null) { + if(config.getKeystoreType().equals("PKCS11")) { try { Constructor c = Class.forName("sun.security.pkcs11.SunPKCS11").getConstructor(InputStream.class); String pkcs11Config = "name = SmartCard\nlibrary = "+config.getPKCS11Library(); @@ -1710,7 +1704,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { return Math.min(clientResumptionTime, serverResumptionTime); } - private void processHandledCount(long handledCount) throws NotConnectedException, StreamManagementCounterError { + private void processHandledCount(long handledCount) throws StreamManagementCounterError { long ackedStanzasCount = SMUtils.calculateDelta(handledCount, serverHandledStanzasCount); final List ackedStanzas = new ArrayList( handledCount <= Integer.MAX_VALUE ? (int) handledCount