Fix warnings

This commit is contained in:
Florian Schmaus 2017-08-16 14:10:00 +02:00
parent 6203d163c4
commit 80eaaf2d71
15 changed files with 73 additions and 95 deletions

View File

@ -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();

View File

@ -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:
* <a href="https://xmpp.org/extensions/xep-0300.html#recommendations">https://xmpp.org/extensions/xep-0300.html#recommendations</a>.
*/
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));
}

View File

@ -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;

View File

@ -25,7 +25,7 @@ public class UploadService {
enum Version {
v0_2,
v0_3,
};
}
private final DomainBareJid address;
private final Version version;

View File

@ -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) {

View File

@ -68,7 +68,7 @@ public class MUCLightBlockingIQProvider extends IQProvider<MUCLightBlockingIQ> {
return mucLightBlockingIQ;
}
private HashMap<Jid, Boolean> parseBlocking(XmlPullParser parser, HashMap<Jid, Boolean> map)
private static HashMap<Jid, Boolean> parseBlocking(XmlPullParser parser, HashMap<Jid, Boolean> map)
throws XmppStringprepException, XmlPullParserException, IOException {
if (map == null) {
map = new HashMap<>();

View File

@ -93,7 +93,7 @@ public class MUCLightInfoIQProvider extends IQProvider<MUCLightInfoIQ> {
return new MUCLightInfoIQ(version, new MUCLightRoomConfiguration(roomName, subject, customConfigs), occupants);
}
private HashMap<Jid, MUCLightAffiliation> iterateOccupants(XmlPullParser parser) throws Exception {
private static HashMap<Jid, MUCLightAffiliation> iterateOccupants(XmlPullParser parser) throws Exception {
HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>();
int depth = parser.getDepth();

View File

@ -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<String> 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);
}

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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(

View File

@ -33,7 +33,7 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
* to true, otherwise it will be null.
* </ul>
*
* <h3>An Item created to send to a node (via {@link LeafNode#send()} or {@link LeafNode#publish()}</h3>
* <h3>An Item created to send to a node (via {@link LeafNode#publish()} or {@link LeafNode#publish()}</h3>
* <ul>
* <li>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 <tt>Item</tt> 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 <tt>Item</tt> is sent to the node, you have to use {@link LeafNode#send()} or {@link LeafNode#publish()}
* methods in this case.
* set to false, no <tt>Item</tt> is sent to the node, you have to use the {@link LeafNode#publish()}
* method in this case.
*/
public Item()
{

View File

@ -34,7 +34,7 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
* to true, otherwise it will be null.</li>
* </ul>
*
* <h3>An Item created to send to a node (via {@link LeafNode#send()} or {@link LeafNode#publish()}</h3>
* <h3>An Item created to send to a node (via {@link LeafNode#publish()}</h3>
* <ul>
* <li>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

View File

@ -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()

View File

@ -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);
}