From 80eaaf2d71e29979f8f7b732a8624a201d99f065 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 16 Aug 2017 14:10:00 +0200 Subject: [PATCH] Fix warnings --- .../smack/packet/ToStringTest.java | 5 +- .../smackx/hashes/HashManager.java | 21 ++--- .../smackx/hashes/element/HashElement.java | 9 +- .../smackx/httpfileupload/UploadService.java | 2 +- .../smackx/muclight/MultiUserChatLight.java | 1 + .../provider/MUCLightBlockingIQProvider.java | 2 +- .../provider/MUCLightInfoIQProvider.java | 2 +- .../smackx/jingle/JingleSession.java | 84 ++++++++----------- .../jingle/JingleTransportMethodManager.java | 2 +- .../smackx/jingle/JingleUtil.java | 22 +---- .../smackx/muc/MultiUserChat.java | 4 +- .../org/jivesoftware/smackx/pubsub/Item.java | 6 +- .../smackx/pubsub/PayloadItem.java | 2 +- .../receipts/DeliveryReceiptManager.java | 4 +- .../jingle_s5b/JingleS5BTransportTest.java | 2 + 15 files changed, 73 insertions(+), 95 deletions(-) diff --git a/smack-core/src/test/java/org/jivesoftware/smack/packet/ToStringTest.java b/smack-core/src/test/java/org/jivesoftware/smack/packet/ToStringTest.java index c15b3052b..a591585f9 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/packet/ToStringTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/packet/ToStringTest.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2016 Florian Schmaus + * Copyright © 2016-2017 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import org.jivesoftware.smack.packet.Presence.Mode; import org.junit.Test; import org.jxmpp.jid.JidTestUtil; -import org.jxmpp.stringprep.XmppStringprepException; public class ToStringTest { @@ -43,7 +42,7 @@ public class ToStringTest { } @Test - public void iqTest() throws XmppStringprepException { + public void iqTest() { Bind bindIq = Bind.newResult(JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE); bindIq.setStanzaId("bind-id"); String string = bindIq.toString(); diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hashes/HashManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hashes/HashManager.java index 9236dca83..707ae68ae 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hashes/HashManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hashes/HashManager.java @@ -52,7 +52,10 @@ import org.jivesoftware.smackx.hashes.element.HashElement; import org.bouncycastle.jce.provider.BouncyCastleProvider; /** - * Manager that can be used to determine support for hash functions. + * Manager that can be used to determine support for hash functions. By default the Manager announces support for + * XEP-0300, as well as for the recommended set of hash algorithms. Those contain SHA256, SHA384, SHA512, SHA3-256, + * SHA3-384, SHA3-512, BLAKE2B256, BLAKE2B384 and BLAKE2B512. Those algorithms got recommended here: + * https://xmpp.org/extensions/xep-0300.html#recommendations. */ public final class HashManager extends Manager { @@ -88,9 +91,7 @@ public final class HashManager extends Manager { /** * Constructor of the HashManager. - * By default the Manager announces support for XEP-0300, as well as for the RECOMMENDED set of hash algorithms. - * Those contain SHA256, SHA384, SHA512, SHA3-256, SHA3-384, SHA3-512, BLAKE2B256, BLAKE2B384 and BLAKE2B512. - * Those algorithms got recommended here: https://xmpp.org/extensions/xep-0300.html#recommendations + * * @param connection connection */ private HashManager(XMPPConnection connection) { @@ -122,9 +123,9 @@ public final class HashManager extends Manager { /** * Get an instance of the HashManager for the given connection. * @param connection - * @return + * @return the manager for the given connection. */ - public HashManager getInstanceFor(XMPPConnection connection) { + public static synchronized HashManager getInstanceFor(XMPPConnection connection) { HashManager hashManager = INSTANCES.get(connection); if (hashManager == null) { hashManager = new HashManager(connection); @@ -457,11 +458,11 @@ public final class HashManager extends Manager { return blake2b384(utf8(data)); } - public String blake2b384HexString(byte[] data) { + public static String blake2b384HexString(byte[] data) { return hex(blake2b384(data)); } - public String blake2b384HexString(String data) { + public static String blake2b384HexString(String data) { return hex(blake2b384(data)); } @@ -473,11 +474,11 @@ public final class HashManager extends Manager { return blake2b512(utf8(data)); } - public String blake2b512HexString(byte[] data) { + public static String blake2b512HexString(byte[] data) { return hex(blake2b512(data)); } - public String blake2b512HexString(String data) { + public static String blake2b512HexString(String data) { return hex(blake2b512(data)); } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hashes/element/HashElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hashes/element/HashElement.java index 5dc8317cd..d2d858875 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hashes/element/HashElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hashes/element/HashElement.java @@ -62,7 +62,8 @@ public class HashElement implements ExtensionElement { /** * Return the hash algorithm used in this HashElement. - * @return algorithm + * + * @return algorithm the algorithm. */ public HashManager.ALGORITHM getAlgorithm() { return algorithm; @@ -70,7 +71,8 @@ public class HashElement implements ExtensionElement { /** * Return the checksum as a byte array. - * @return + * + * @return the hash. */ public byte[] getHash() { return hash; @@ -78,7 +80,8 @@ public class HashElement implements ExtensionElement { /** * Return the checksum as a base16 (hex) string. - * @return + * + * @return the hash. */ public String getHashB64() { return hashB64; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/UploadService.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/UploadService.java index ae9f90cbb..e2627629f 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/UploadService.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/UploadService.java @@ -25,7 +25,7 @@ public class UploadService { enum Version { v0_2, v0_3, - }; + } private final DomainBareJid address; private final Version version; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLight.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLight.java index 41f13b8e3..9e854bf48 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLight.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLight.java @@ -146,6 +146,7 @@ public class MultiUserChatLight { * for the newly created chat. * @return new Chat for sending private messages to a given room occupant. */ + @SuppressWarnings("deprecation") @Deprecated // Do not re-use Chat API, which was designed for XMPP-IM 1:1 chats and not MUClight private chats. public org.jivesoftware.smack.chat.Chat createPrivateChat(EntityJid occupant, ChatMessageListener listener) { diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/provider/MUCLightBlockingIQProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/provider/MUCLightBlockingIQProvider.java index 576dd59e1..89b058ae7 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/provider/MUCLightBlockingIQProvider.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/provider/MUCLightBlockingIQProvider.java @@ -68,7 +68,7 @@ public class MUCLightBlockingIQProvider extends IQProvider { return mucLightBlockingIQ; } - private HashMap parseBlocking(XmlPullParser parser, HashMap map) + private static HashMap parseBlocking(XmlPullParser parser, HashMap map) throws XmppStringprepException, XmlPullParserException, IOException { if (map == null) { map = new HashMap<>(); diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/provider/MUCLightInfoIQProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/provider/MUCLightInfoIQProvider.java index b76274424..c58c73043 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/provider/MUCLightInfoIQProvider.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/provider/MUCLightInfoIQProvider.java @@ -93,7 +93,7 @@ public class MUCLightInfoIQProvider extends IQProvider { return new MUCLightInfoIQ(version, new MUCLightRoomConfiguration(roomName, subject, customConfigs), occupants); } - private HashMap iterateOccupants(XmlPullParser parser) throws Exception { + private static HashMap iterateOccupants(XmlPullParser parser) throws Exception { HashMap occupants = new HashMap<>(); int depth = parser.getDepth(); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java index 9bd71d81e..1ae4ac650 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java @@ -20,11 +20,8 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.concurrent.Future; -import java.util.logging.Logger; -import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.jingle.element.Jingle; import org.jivesoftware.smackx.jingle.element.JingleContent; @@ -33,7 +30,6 @@ import org.jivesoftware.smackx.jingle.transports.JingleTransportSession; import org.jxmpp.jid.FullJid; public abstract class JingleSession implements JingleSessionHandler { - private static final Logger LOGGER = Logger.getLogger(JingleSession.class.getName()); protected HashSet failedTransportMethods = new HashSet<>(); protected final FullJid local; @@ -135,47 +131,43 @@ public abstract class JingleSession implements JingleSessionHandler { @Override public IQ handleJingleSessionRequest(Jingle jingle) { - try { - switch (jingle.getAction()) { - case content_accept: - return handleContentAccept(jingle); - case content_add: - return handleContentAdd(jingle); - case content_modify: - return handleContentModify(jingle); - case content_reject: - return handleContentReject(jingle); - case content_remove: - return handleContentRemove(jingle); - case description_info: - return handleDescriptionInfo(jingle); - case session_info: - return handleSessionInfo(jingle); - case security_info: - return handleSecurityInfo(jingle); - case session_accept: - return handleSessionAccept(jingle); - case transport_accept: - return handleTransportAccept(jingle); - case transport_info: - return transportSession.handleTransportInfo(jingle); - case session_initiate: - return handleSessionInitiate(jingle); - case transport_reject: - return handleTransportReject(jingle); - case session_terminate: - return handleSessionTerminate(jingle); - case transport_replace: - return handleTransportReplace(jingle); - default: - return IQ.createResultIQ(jingle); - } - } catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) { - return null; //TODO: + switch (jingle.getAction()) { + case content_accept: + return handleContentAccept(jingle); + case content_add: + return handleContentAdd(jingle); + case content_modify: + return handleContentModify(jingle); + case content_reject: + return handleContentReject(jingle); + case content_remove: + return handleContentRemove(jingle); + case description_info: + return handleDescriptionInfo(jingle); + case session_info: + return handleSessionInfo(jingle); + case security_info: + return handleSecurityInfo(jingle); + case session_accept: + return handleSessionAccept(jingle); + case transport_accept: + return handleTransportAccept(jingle); + case transport_info: + return transportSession.handleTransportInfo(jingle); + case session_initiate: + return handleSessionInitiate(jingle); + case transport_reject: + return handleTransportReject(jingle); + case session_terminate: + return handleSessionTerminate(jingle); + case transport_replace: + return handleTransportReplace(jingle); + default: + return IQ.createResultIQ(jingle); } } - protected IQ handleSessionInitiate(Jingle sessionInitiate) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { + protected IQ handleSessionInitiate(Jingle sessionInitiate) { return IQ.createResultIQ(sessionInitiate); } @@ -187,7 +179,7 @@ public abstract class JingleSession implements JingleSessionHandler { return IQ.createResultIQ(sessionInfo); } - protected IQ handleSessionAccept(Jingle sessionAccept) throws SmackException.NotConnectedException, InterruptedException { + protected IQ handleSessionAccept(Jingle sessionAccept) { return IQ.createResultIQ(sessionAccept); } @@ -219,13 +211,11 @@ public abstract class JingleSession implements JingleSessionHandler { return IQ.createResultIQ(securityInfo); } - protected IQ handleTransportAccept(Jingle transportAccept) throws SmackException.NotConnectedException, InterruptedException { + protected IQ handleTransportAccept(Jingle transportAccept) { return IQ.createResultIQ(transportAccept); } - protected IQ handleTransportReplace(Jingle transportReplace) - throws InterruptedException, XMPPException.XMPPErrorException, - SmackException.NotConnectedException, SmackException.NoResponseException { + protected IQ handleTransportReplace(Jingle transportReplace) { return IQ.createResultIQ(transportReplace); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleTransportMethodManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleTransportMethodManager.java index 32c9648df..848dc1671 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleTransportMethodManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleTransportMethodManager.java @@ -87,7 +87,7 @@ public final class JingleTransportMethodManager extends Manager { return getTransportManager(transport.getNamespace()); } - public JingleTransportManager getBestAvailableTransportManager(XMPPConnection connection) { + public static JingleTransportManager getBestAvailableTransportManager(XMPPConnection connection) { return getInstanceFor(connection).getBestAvailableTransportManager(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java index 8f47fea94..9cad9a9da 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java @@ -99,8 +99,7 @@ public class JingleUtil { JingleContent.Senders contentSenders, JingleContentDescription description, JingleContentTransport transport) - throws SmackException.NotConnectedException, InterruptedException, - XMPPException.XMPPErrorException, SmackException.NoResponseException { + throws SmackException.NotConnectedException, InterruptedException { Jingle jingle = createSessionInitiate(recipient, sessionId, contentCreator, contentName, contentSenders, description, transport); @@ -142,8 +141,7 @@ public class JingleUtil { JingleContent.Senders contentSenders, JingleContentDescription description, JingleContentTransport transport) - throws SmackException.NotConnectedException, InterruptedException, - XMPPException.XMPPErrorException, SmackException.NoResponseException { + throws SmackException.NotConnectedException, InterruptedException { Jingle jingle = createSessionAccept(recipient, sessionId, contentCreator, contentName, contentSenders, description, transport); @@ -168,22 +166,6 @@ public class JingleUtil { return createSessionTerminate(recipient, sessionId, new JingleReason(reason)); } - private IQ sendSessionTerminate(FullJid recipient, String sessionId, JingleReason.Reason reason) - throws SmackException.NotConnectedException, InterruptedException, - XMPPException.XMPPErrorException, SmackException.NoResponseException { - - return sendSessionTerminate(recipient, sessionId, new JingleReason(reason)); - } - - private IQ sendSessionTerminate(FullJid recipient, String sessionId, JingleReason reason) - throws SmackException.NotConnectedException, InterruptedException, - XMPPException.XMPPErrorException, SmackException.NoResponseException { - - Jingle jingle = createSessionTerminate(recipient, sessionId, reason); - - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); - } - public Jingle createSessionTerminateDecline(FullJid recipient, String sessionId) { return createSessionTerminate(recipient, sessionId, JingleReason.Reason.decline); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java index 5d95069ce..d3f6dda29 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -465,7 +465,7 @@ public class MultiUserChat { * @deprecated use {@link #createOrJoin(MucEnterConfiguration)} instead. */ @Deprecated - public MucCreateConfigFormHandle createOrJoin(Resourcepart nickname, String password, DiscussionHistory history, long timeout) + public MucCreateConfigFormHandle createOrJoin(Resourcepart nickname, String password, @SuppressWarnings("deprecation") DiscussionHistory history, long timeout) throws NoResponseException, XMPPErrorException, InterruptedException, MucAlreadyJoinedException, NotConnectedException, NotAMucServiceException { MucEnterConfiguration.Builder builder = getEnterConfigurationBuilder(nickname).withPassword( password).timeoutAfter(timeout); @@ -666,7 +666,7 @@ public class MultiUserChat { public void join( Resourcepart nickname, String password, - DiscussionHistory history, + @SuppressWarnings("deprecation") DiscussionHistory history, long timeout) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException, NotAMucServiceException { MucEnterConfiguration.Builder builder = getEnterConfigurationBuilder(nickname).withPassword( diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Item.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Item.java index 72b67600c..9f2d881fc 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Item.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Item.java @@ -33,7 +33,7 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider; * to true, otherwise it will be null. * * - *

An Item created to send to a node (via {@link LeafNode#send()} or {@link LeafNode#publish()}

+ *

An Item created to send to a node (via {@link LeafNode#publish()} or {@link LeafNode#publish()}

*
    *
  • The id is optional, since the server will generate one if necessary, but should be used if it is * meaningful in the context of the node. This value must be unique within the node that it is sent to, since @@ -57,8 +57,8 @@ public class Item extends NodeExtension * Create an empty Item with no id. This is a valid item for nodes which are configured * so that {@link ConfigureForm#isDeliverPayloads()} is false. In most cases an id will be generated by the server. * For nodes configured with {@link ConfigureForm#isDeliverPayloads()} and {@link ConfigureForm#isPersistItems()} - * set to false, no Item is sent to the node, you have to use {@link LeafNode#send()} or {@link LeafNode#publish()} - * methods in this case. + * set to false, no Item is sent to the node, you have to use the {@link LeafNode#publish()} + * method in this case. */ public Item() { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PayloadItem.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PayloadItem.java index bba15fe96..1ed80671d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PayloadItem.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PayloadItem.java @@ -34,7 +34,7 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider; * to true, otherwise it will be null.
  • *
* - *

An Item created to send to a node (via {@link LeafNode#send()} or {@link LeafNode#publish()}

+ *

An Item created to send to a node (via {@link LeafNode#publish()}

*
    *
  • The id is optional, since the server will generate one if necessary, but should be used if it is * meaningful in the context of the node. This value must be unique within the node that it is sent to, since diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java index b95ebf834..7ea921cd7 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java @@ -272,8 +272,8 @@ public final class DeliveryReceiptManager extends Manager { /** * Enables automatic requests of delivery receipts for outgoing messages of - * {@link Message.Type#normal}, {@link Message.Type#chat} or {@link Message.Type#headline}, and - * with a {@link Message.Body} extension. + * {@link org.jivesoftware.smack.packet.Message.Type#normal}, {@link org.jivesoftware.smack.packet.Message.Type#chat} or {@link org.jivesoftware.smack.packet.Message.Type#headline}, and + * with a {@link org.jivesoftware.smack.packet.Message.Body} extension. * * @since 4.1 * @see #dontAutoAddDeliveryReceiptRequests() diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportTest.java index f7fc1b320..68ca37f06 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportTest.java @@ -189,6 +189,7 @@ public class JingleS5BTransportTest extends SmackTestSuite { @Test(expected = IllegalArgumentException.class) public void transportCandidateIllegalPriorityTest() throws XmppStringprepException { FullJid jid = JidCreate.fullFrom("test@test.test/test"); + @SuppressWarnings("unused") JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate( "cid", "host", jid, 5555, -30, JingleS5BTransportCandidate.Type.proxy); } @@ -196,6 +197,7 @@ public class JingleS5BTransportTest extends SmackTestSuite { @Test(expected = IllegalArgumentException.class) public void transportCandidateIllegalPortTest() throws XmppStringprepException { FullJid jid = JidCreate.fullFrom("test@test.test/test"); + @SuppressWarnings("unused") JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate( "cid", "host", jid, -5555, 30, JingleS5BTransportCandidate.Type.proxy); }