mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-12 05:51:08 +01:00
Bump "Error Prone" to 2.0.15
and fix a few things :)
This commit is contained in:
parent
ef0af66b21
commit
4c646436a5
246 changed files with 1122 additions and 124 deletions
|
|
@ -34,6 +34,7 @@ public abstract class InBandBytestreamListener implements BytestreamListener {
|
|||
|
||||
|
||||
|
||||
@Override
|
||||
public void incomingBytestreamRequest(BytestreamRequest request) {
|
||||
incomingBytestreamRequest((InBandBytestreamRequest) request);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
|
|||
*/
|
||||
static {
|
||||
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||
@Override
|
||||
public void connectionCreated(final XMPPConnection connection) {
|
||||
// create the manager for this connection
|
||||
InBandBytestreamManager.getByteStreamManager(connection);
|
||||
|
|
@ -236,6 +237,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
|
|||
*
|
||||
* @param listener the listener to register
|
||||
*/
|
||||
@Override
|
||||
public void addIncomingBytestreamListener(BytestreamListener listener) {
|
||||
this.allRequestListeners.add(listener);
|
||||
}
|
||||
|
|
@ -246,6 +248,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
|
|||
*
|
||||
* @param listener the listener to remove
|
||||
*/
|
||||
@Override
|
||||
public void removeIncomingBytestreamListener(BytestreamListener listener) {
|
||||
this.allRequestListeners.remove(listener);
|
||||
}
|
||||
|
|
@ -268,6 +271,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
|
|||
* @param listener the listener to register
|
||||
* @param initiatorJID the JID of the user that wants to establish an In-Band Bytestream
|
||||
*/
|
||||
@Override
|
||||
public void addIncomingBytestreamListener(BytestreamListener listener, Jid initiatorJID) {
|
||||
this.userListeners.put(initiatorJID, listener);
|
||||
}
|
||||
|
|
@ -277,6 +281,9 @@ public final class InBandBytestreamManager implements BytestreamManager {
|
|||
*
|
||||
* @param initiatorJID the JID of the user the listener should be removed
|
||||
*/
|
||||
@Override
|
||||
// TODO: Change argument to Jid in Smack 4.3.
|
||||
@SuppressWarnings("CollectionIncompatibleType")
|
||||
public void removeIncomingBytestreamListener(String initiatorJID) {
|
||||
this.userListeners.remove(initiatorJID);
|
||||
}
|
||||
|
|
@ -402,6 +409,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
|
|||
* @throws SmackException if there was no response from the server.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Override
|
||||
public InBandBytestreamSession establishSession(Jid targetJID) throws XMPPException, SmackException, InterruptedException {
|
||||
String sessionID = getNextSessionID();
|
||||
return establishSession(targetJID, sessionID);
|
||||
|
|
@ -420,6 +428,7 @@ public final class InBandBytestreamManager implements BytestreamManager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Override
|
||||
public InBandBytestreamSession establishSession(Jid targetJID, String sessionID)
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
Open byteStreamRequest = new Open(sessionID, this.defaultBlockSize, this.stanza);
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ public class InBandBytestreamRequest implements BytestreamRequest {
|
|||
*
|
||||
* @return the sender of the In-Band Bytestream open request
|
||||
*/
|
||||
@Override
|
||||
public Jid getFrom() {
|
||||
return this.byteStreamRequest.getFrom();
|
||||
}
|
||||
|
|
@ -59,6 +60,7 @@ public class InBandBytestreamRequest implements BytestreamRequest {
|
|||
*
|
||||
* @return the session ID of the In-Band Bytestream open request
|
||||
*/
|
||||
@Override
|
||||
public String getSessionID() {
|
||||
return this.byteStreamRequest.getSessionID();
|
||||
}
|
||||
|
|
@ -71,6 +73,7 @@ public class InBandBytestreamRequest implements BytestreamRequest {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Override
|
||||
public InBandBytestreamSession accept() throws NotConnectedException, InterruptedException {
|
||||
XMPPConnection connection = this.manager.getConnection();
|
||||
|
||||
|
|
@ -92,6 +95,7 @@ public class InBandBytestreamRequest implements BytestreamRequest {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Override
|
||||
public void reject() throws NotConnectedException, InterruptedException {
|
||||
this.manager.replyRejectPacket(this.byteStreamRequest);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,18 +109,22 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
return this.inputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream() {
|
||||
return this.outputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReadTimeout() {
|
||||
return this.inputStream.readTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadTimeout(int timeout) {
|
||||
if (timeout < 0) {
|
||||
throw new IllegalArgumentException("Timeout must be >= 0");
|
||||
|
|
@ -151,6 +155,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
this.closeBothStreamsEnabled = closeBothStreamsEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
closeByLocal(true); // close input stream
|
||||
closeByLocal(false); // close output stream
|
||||
|
|
@ -224,7 +229,9 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
this.inputStream.cleanup();
|
||||
|
||||
// remove session from manager
|
||||
InBandBytestreamManager.getByteStreamManager(this.connection).getSessions().remove(this);
|
||||
// Thanks Google Error Prone for finding the bug where remove() was called with 'this' as argument. Changed
|
||||
// now to remove(byteStreamRequest.getSessionID).
|
||||
InBandBytestreamManager.getByteStreamManager(this.connection).getSessions().remove(byteStreamRequest.getSessionID());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -283,6 +290,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
*/
|
||||
protected abstract StanzaFilter getDataPacketFilter();
|
||||
|
||||
@Override
|
||||
public synchronized int read() throws IOException {
|
||||
checkClosed();
|
||||
|
||||
|
|
@ -298,6 +306,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
return buffer[bufferPointer++] & 0xff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int read(byte[] b, int off, int len) throws IOException {
|
||||
if (b == null) {
|
||||
throw new NullPointerException();
|
||||
|
|
@ -331,6 +340,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
return len;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int read(byte[] b) throws IOException {
|
||||
return read(b, 0, b.length);
|
||||
}
|
||||
|
|
@ -405,10 +415,12 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (closeInvoked) {
|
||||
return;
|
||||
|
|
@ -444,11 +456,13 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
*/
|
||||
private class IQIBBInputStream extends IBBInputStream {
|
||||
|
||||
@Override
|
||||
protected StanzaListener getDataPacketListener() {
|
||||
return new StanzaListener() {
|
||||
|
||||
private long lastSequence = -1;
|
||||
|
||||
@Override
|
||||
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException {
|
||||
// get data packet extension
|
||||
DataPacketExtension data = ((Data) packet).getDataPacketExtension();
|
||||
|
|
@ -491,6 +505,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StanzaFilter getDataPacketFilter() {
|
||||
/*
|
||||
* filter all IQ stanzas having type 'SET' (represented by Data class), containing a
|
||||
|
|
@ -507,9 +522,11 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
*/
|
||||
private class MessageIBBInputStream extends IBBInputStream {
|
||||
|
||||
@Override
|
||||
protected StanzaListener getDataPacketListener() {
|
||||
return new StanzaListener() {
|
||||
|
||||
@Override
|
||||
public void processStanza(Stanza packet) {
|
||||
// get data packet extension
|
||||
DataPacketExtension data = (DataPacketExtension) packet.getExtension(
|
||||
|
|
@ -555,6 +572,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
*/
|
||||
private class IBBDataPacketFilter implements StanzaFilter {
|
||||
|
||||
@Override
|
||||
public boolean accept(Stanza packet) {
|
||||
// sender equals remote peer
|
||||
if (!packet.getFrom().equals(remoteJID)) {
|
||||
|
|
@ -619,6 +637,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
*/
|
||||
protected abstract void writeToXML(DataPacketExtension data) throws IOException, NotConnectedException, InterruptedException;
|
||||
|
||||
@Override
|
||||
public synchronized void write(int b) throws IOException {
|
||||
if (this.isClosed) {
|
||||
throw new IOException("Stream is closed");
|
||||
|
|
@ -632,6 +651,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
buffer[bufferPointer++] = (byte) b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void write(byte[] b, int off, int len) throws IOException {
|
||||
if (b == null) {
|
||||
throw new NullPointerException();
|
||||
|
|
@ -662,6 +682,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void write(byte[] b) throws IOException {
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
|
@ -698,6 +719,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
bufferPointer += len - available;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void flush() throws IOException {
|
||||
if (this.isClosed) {
|
||||
throw new IOException("Stream is closed");
|
||||
|
|
@ -735,6 +757,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (isClosed) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ class InitiationListener extends AbstractIqRequestHandler {
|
|||
public IQ handleIQRequest(final IQ packet) {
|
||||
initiationListenerExecutor.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
processRequest(packet);
|
||||
|
|
|
|||
|
|
@ -126,10 +126,12 @@ public class DataPacketExtension implements ExtensionElement {
|
|||
return this.decodedData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ final class InitiationListener extends AbstractIqRequestHandler {
|
|||
public IQ handleIQRequest(final IQ packet) {
|
||||
initiationListenerExecutor.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
processRequest(packet);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
|
|||
*/
|
||||
public abstract class Socks5BytestreamListener implements BytestreamListener {
|
||||
|
||||
@Override
|
||||
public void incomingBytestreamRequest(BytestreamRequest request) {
|
||||
incomingBytestreamRequest((Socks5BytestreamRequest) request);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
|||
static {
|
||||
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||
|
||||
@Override
|
||||
public void connectionCreated(final XMPPConnection connection) {
|
||||
// create the manager for this connection
|
||||
Socks5BytestreamManager.getBytestreamManager(connection);
|
||||
|
|
@ -198,6 +199,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
|||
*
|
||||
* @param listener the listener to register
|
||||
*/
|
||||
@Override
|
||||
public void addIncomingBytestreamListener(BytestreamListener listener) {
|
||||
this.allRequestListeners.add(listener);
|
||||
}
|
||||
|
|
@ -208,6 +210,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
|||
*
|
||||
* @param listener the listener to remove
|
||||
*/
|
||||
@Override
|
||||
public void removeIncomingBytestreamListener(BytestreamListener listener) {
|
||||
this.allRequestListeners.remove(listener);
|
||||
}
|
||||
|
|
@ -230,6 +233,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
|||
* @param listener the listener to register
|
||||
* @param initiatorJID the JID of the user that wants to establish a SOCKS5 Bytestream
|
||||
*/
|
||||
@Override
|
||||
public void addIncomingBytestreamListener(BytestreamListener listener, Jid initiatorJID) {
|
||||
this.userListeners.put(initiatorJID, listener);
|
||||
}
|
||||
|
|
@ -239,6 +243,9 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
|||
*
|
||||
* @param initiatorJID the JID of the user the listener should be removed
|
||||
*/
|
||||
// TODO: Change parameter to Jid in Smack 4.3.
|
||||
@Override
|
||||
@SuppressWarnings("CollectionIncompatibleType")
|
||||
public void removeIncomingBytestreamListener(String initiatorJID) {
|
||||
this.userListeners.remove(initiatorJID);
|
||||
}
|
||||
|
|
@ -386,6 +393,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
|||
* @throws InterruptedException if the current thread was interrupted while waiting
|
||||
* @throws SmackException if there was no response from the server.
|
||||
*/
|
||||
@Override
|
||||
public Socks5BytestreamSession establishSession(Jid targetJID) throws XMPPException,
|
||||
IOException, InterruptedException, SmackException {
|
||||
String sessionID = getNextSessionID();
|
||||
|
|
@ -405,6 +413,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
|||
* @throws SmackException if the target does not support SOCKS5.
|
||||
* @throws XMPPException
|
||||
*/
|
||||
@Override
|
||||
public Socks5BytestreamSession establishSession(Jid targetJID, String sessionID)
|
||||
throws IOException, InterruptedException, NoResponseException, SmackException, XMPPException{
|
||||
XMPPConnection connection = connection();
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
|
|||
*
|
||||
* @return the sender of the SOCKS5 Bytestream initialization request.
|
||||
*/
|
||||
@Override
|
||||
public Jid getFrom() {
|
||||
return this.bytestreamRequest.getFrom();
|
||||
}
|
||||
|
|
@ -179,6 +180,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
|
|||
*
|
||||
* @return the session ID of the SOCKS5 Bytestream initialization request.
|
||||
*/
|
||||
@Override
|
||||
public String getSessionID() {
|
||||
return this.bytestreamRequest.getSessionID();
|
||||
}
|
||||
|
|
@ -195,6 +197,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
|
|||
* @throws XMPPErrorException
|
||||
* @throws SmackException
|
||||
*/
|
||||
@Override
|
||||
public Socks5BytestreamSession accept() throws InterruptedException, XMPPErrorException, SmackException {
|
||||
Collection<StreamHost> streamHosts = this.bytestreamRequest.getStreamHosts();
|
||||
|
||||
|
|
@ -264,6 +267,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Override
|
||||
public void reject() throws NotConnectedException, InterruptedException {
|
||||
this.manager.replyRejectPacket(this.bytestreamRequest);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,14 +64,17 @@ public class Socks5BytestreamSession implements BytestreamSession {
|
|||
return !this.isDirect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return this.socket.getInputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return this.socket.getOutputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReadTimeout() throws IOException {
|
||||
try {
|
||||
return this.socket.getSoTimeout();
|
||||
|
|
@ -81,6 +84,7 @@ public class Socks5BytestreamSession implements BytestreamSession {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadTimeout(int timeout) throws IOException {
|
||||
try {
|
||||
this.socket.setSoTimeout(timeout);
|
||||
|
|
@ -90,6 +94,7 @@ public class Socks5BytestreamSession implements BytestreamSession {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.socket.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.bytestreams.socks5;
|
|||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
|
|
@ -34,6 +35,7 @@ import java.util.logging.Logger;
|
|||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
|
||||
|
||||
/**
|
||||
|
|
@ -82,6 +84,7 @@ class Socks5Client {
|
|||
// wrap connecting in future for timeout
|
||||
FutureTask<Socket> futureTask = new FutureTask<Socket>(new Callable<Socket>() {
|
||||
|
||||
@Override
|
||||
public Socket call() throws IOException, SmackException {
|
||||
|
||||
// initialize socket
|
||||
|
|
@ -199,7 +202,13 @@ class Socks5Client {
|
|||
* @return SOCKS5 connection request message
|
||||
*/
|
||||
private byte[] createSocks5ConnectRequest() {
|
||||
byte[] addr = this.digest.getBytes();
|
||||
byte[] addr;
|
||||
try {
|
||||
addr = digest.getBytes(StringUtils.UTF8);
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
|
||||
byte[] data = new byte[7 + addr.length];
|
||||
data[0] = (byte) 0x05; // version (SOCKS5)
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ class Socks5ClientForInitiator extends Socks5Client {
|
|||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket getSocket(int timeout) throws IOException, InterruptedException,
|
||||
TimeoutException, XMPPException, SmackException {
|
||||
Socket socket = null;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The Socks5Proxy class represents a local SOCKS5 proxy server. It can be enabled/disabled by
|
||||
|
|
@ -381,6 +382,7 @@ public final class Socks5Proxy {
|
|||
*/
|
||||
private class Socks5ServerProcess implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
Socket socket = null;
|
||||
|
|
@ -470,7 +472,7 @@ public final class Socks5Proxy {
|
|||
byte[] connectionRequest = Socks5Utils.receiveSocks5Message(in);
|
||||
|
||||
// extract digest
|
||||
String responseDigest = new String(connectionRequest, 5, connectionRequest[4]);
|
||||
String responseDigest = new String(connectionRequest, 5, connectionRequest[4], StringUtils.UTF8);
|
||||
|
||||
// return error if digest is not allowed
|
||||
if (!Socks5Proxy.this.allowedConnections.contains(responseDigest)) {
|
||||
|
|
|
|||
|
|
@ -317,6 +317,7 @@ public class Bytestream extends IQ {
|
|||
return port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENTNAME;
|
||||
}
|
||||
|
|
@ -366,6 +367,7 @@ public class Bytestream extends IQ {
|
|||
return JID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENTNAME;
|
||||
}
|
||||
|
|
@ -408,6 +410,7 @@ public class Bytestream extends IQ {
|
|||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENTNAME;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue