Add errorprone check and fix found errors

Adds gradle-errorprone-plugin 0.0.8, requires Gradle 2.6.
This commit is contained in:
Florian Schmaus 2015-09-13 18:12:33 +02:00
parent 8096da43e0
commit d728204890
23 changed files with 64 additions and 44 deletions

View File

@ -3,12 +3,14 @@ import org.gradle.plugins.signing.Sign
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'http://dl.bintray.com/content/aalmiray/kordamp' } maven { url 'http://dl.bintray.com/content/aalmiray/kordamp' }
} }
dependencies { dependencies {
classpath 'org.kordamp:markdown-gradle-plugin:1.0.0' classpath 'org.kordamp:markdown-gradle-plugin:1.0.0'
classpath 'org.kordamp.gradle:clirr-gradle-plugin:0.2.0' classpath 'org.kordamp.gradle:clirr-gradle-plugin:0.2.0'
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1" classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1"
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.8'
} }
} }
apply plugin: 'org.kordamp.gradle.markdown' apply plugin: 'org.kordamp.gradle.markdown'
@ -19,6 +21,7 @@ allprojects {
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'eclipse' apply plugin: 'eclipse'
apply plugin: 'jacoco' apply plugin: 'jacoco'
apply plugin: 'net.ltgt.errorprone'
ext { ext {
gitCommit = getGitCommit() gitCommit = getGitCommit()
@ -127,6 +130,11 @@ allprojects {
// e.g. JAVA7_HOME. See SMACK-651. // e.g. JAVA7_HOME. See SMACK-651.
'-Xlint:-options', '-Xlint:-options',
'-Werror', '-Werror',
// Needed because since adding gradle-errorprone-plugin
// See https://github.com/tbroyer/gradle-errorprone-plugin/issues/15
'-Xlint:-path',
// Disable errorprone checks
'-Xep:TypeParameterUnusedInFormals:OFF',
] ]
} }

View File

@ -100,6 +100,8 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
*/ */
protected String sessionID = null; protected String sessionID = null;
private boolean notified;
/** /**
* Create a HTTP Binding connection to an XMPP server. * Create a HTTP Binding connection to an XMPP server.
* *
@ -135,6 +137,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
@Override @Override
protected void connectInternal() throws SmackException, InterruptedException { protected void connectInternal() throws SmackException, InterruptedException {
done = false; done = false;
notified = false;
try { try {
// Ensure a clean starting state // Ensure a clean starting state
if (client != null) { if (client != null) {
@ -179,10 +182,12 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
// Wait for the response from the server // Wait for the response from the server
synchronized (this) { synchronized (this) {
if (!connected) { if (!connected) {
try { final long deadline = System.currentTimeMillis() + getPacketReplyTimeout();
wait(getPacketReplyTimeout()); while (!notified) {
final long now = System.currentTimeMillis();
if (now > deadline) break;
wait(deadline - now);
} }
catch (InterruptedException e) {}
} }
} }
@ -439,6 +444,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
} }
} }
finally { finally {
notified = true;
synchronized (XMPPBOSHConnection.this) { synchronized (XMPPBOSHConnection.this) {
XMPPBOSHConnection.this.notifyAll(); XMPPBOSHConnection.this.notifyAll();
} }

View File

@ -192,8 +192,13 @@ public final class SASLAuthentication {
else { else {
currentMechanism.authenticate(username, host, xmppServiceDomain, password); currentMechanism.authenticate(username, host, xmppServiceDomain, password);
} }
// Wait until SASL negotiation finishes final long deadline = System.currentTimeMillis() + connection.getPacketReplyTimeout();
wait(connection.getPacketReplyTimeout()); while (!authenticationSuccessful && saslException == null) {
final long now = System.currentTimeMillis();
if (now > deadline) break;
// Wait until SASL negotiation finishes
wait(deadline - now);
}
} }
if (saslException != null){ if (saslException != null){

View File

@ -71,7 +71,12 @@ class HTTPProxySocketConnection implements ProxySocketConnection {
while (true) while (true)
{ {
char c = (char) in.read(); int inByte = in.read();
if (inByte == -1)
{
throw new ProxyException(ProxyInfo.ProxyType.HTTP);
}
char c = (char) inByte;
got.append(c); got.append(c);
if (got.length() > 1024) if (got.length() > 1024)
{ {
@ -79,10 +84,6 @@ class HTTPProxySocketConnection implements ProxySocketConnection {
"header of >1024 characters from " "header of >1024 characters from "
+ proxyhost + ", cancelling connection"); + proxyhost + ", cancelling connection");
} }
if (c == -1)
{
throw new ProxyException(ProxyInfo.ProxyType.HTTP);
}
if ((nlchars == 0 || nlchars == 2) && c == '\r') if ((nlchars == 0 || nlchars == 2) && c == '\r')
{ {
nlchars++; nlchars++;

View File

@ -31,7 +31,7 @@ import java.util.List;
public class ObservableReader extends Reader { public class ObservableReader extends Reader {
Reader wrappedReader = null; Reader wrappedReader = null;
List<ReaderListener> listeners = new ArrayList<ReaderListener>(); final List<ReaderListener> listeners = new ArrayList<ReaderListener>();
public ObservableReader(Reader wrappedReader) { public ObservableReader(Reader wrappedReader) {
this.wrappedReader = wrappedReader; this.wrappedReader = wrappedReader;

View File

@ -31,7 +31,7 @@ public class ObservableWriter extends Writer {
private static final int MAX_STRING_BUILDER_SIZE = 4096; private static final int MAX_STRING_BUILDER_SIZE = 4096;
Writer wrappedWriter = null; Writer wrappedWriter = null;
List<WriterListener> listeners = new ArrayList<WriterListener>(); final List<WriterListener> listeners = new ArrayList<WriterListener>();
private final StringBuilder stringBuilder = new StringBuilder(MAX_STRING_BUILDER_SIZE); private final StringBuilder stringBuilder = new StringBuilder(MAX_STRING_BUILDER_SIZE);
public ObservableWriter(Writer wrappedWriter) { public ObservableWriter(Writer wrappedWriter) {

View File

@ -75,7 +75,6 @@ class Socks5Client {
*/ */
public Socket getSocket(int timeout) throws IOException, XMPPErrorException, InterruptedException, public Socket getSocket(int timeout) throws IOException, XMPPErrorException, InterruptedException,
TimeoutException, SmackException, XMPPException { TimeoutException, SmackException, XMPPException {
// wrap connecting in future for timeout // wrap connecting in future for timeout
FutureTask<Socket> futureTask = new FutureTask<Socket>(new Callable<Socket>() { FutureTask<Socket> futureTask = new FutureTask<Socket>(new Callable<Socket>() {

View File

@ -38,7 +38,7 @@ public class OfflineMessageRequest extends IQ {
public static final String ELEMENT = "offline"; public static final String ELEMENT = "offline";
public static final String NAMESPACE = "http://jabber.org/protocol/offline"; public static final String NAMESPACE = "http://jabber.org/protocol/offline";
private List<Item> items = new ArrayList<Item>(); private final List<Item> items = new ArrayList<>();
private boolean purge = false; private boolean purge = false;
private boolean fetch = false; private boolean fetch = false;

View File

@ -70,7 +70,7 @@ public class DataForm implements ExtensionElement {
private Type type; private Type type;
private String title; private String title;
private List<String> instructions = new ArrayList<String>(); private final List<String> instructions = new ArrayList<>();
private ReportedData reportedData; private ReportedData reportedData;
private final List<Item> items = new ArrayList<Item>(); private final List<Item> items = new ArrayList<Item>();
private final Map<String, FormField> fields = new LinkedHashMap<>(); private final Map<String, FormField> fields = new LinkedHashMap<>();
@ -197,7 +197,10 @@ public class DataForm implements ExtensionElement {
* @param instructions list of instructions that explain how to fill out the form. * @param instructions list of instructions that explain how to fill out the form.
*/ */
public void setInstructions(List<String> instructions) { public void setInstructions(List<String> instructions) {
this.instructions = instructions; synchronized (this.instructions) {
this.instructions.clear();
this.instructions.addAll(instructions);
}
} }
/** /**

View File

@ -40,7 +40,7 @@ public class XHTMLExtension implements ExtensionElement {
public static final String ELEMENT = "html"; public static final String ELEMENT = "html";
public static final String NAMESPACE = "http://jabber.org/protocol/xhtml-im"; public static final String NAMESPACE = "http://jabber.org/protocol/xhtml-im";
private List<CharSequence> bodies = new ArrayList<CharSequence>(); private final List<CharSequence> bodies = new ArrayList<>();
/** /**
* Returns the XML element name of the extension sub-packet root element. * Returns the XML element name of the extension sub-packet root element.

View File

@ -173,6 +173,7 @@ public final class Socks5TestProxy {
* @param digest identifying the connection * @param digest identifying the connection
* @return socket or null if there is no socket for the given digest * @return socket or null if there is no socket for the given digest
*/ */
@SuppressWarnings("WaitNotInLoop")
public Socket getSocket(String digest) { public Socket getSocket(String digest) {
synchronized(this) { synchronized(this) {
if (!startupComplete) { if (!startupComplete) {
@ -180,13 +181,12 @@ public final class Socks5TestProxy {
wait(5000); wait(5000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "exception", e); LOGGER.log(Level.SEVERE, "exception", e);
} finally {
if (!startupComplete) {
throw new IllegalStateException("Startup of Socks5TestProxy failed within 5 seconds");
}
} }
} }
} }
if (!startupComplete) {
throw new IllegalStateException("Startup of Socks5TestProxy failed within 5 seconds");
}
return this.connectionMap.get(digest); return this.connectionMap.get(digest);
} }

View File

@ -170,7 +170,7 @@ public class SmackIntegrationTestFramework {
return testRunResult; return testRunResult;
} }
@SuppressWarnings("unchecked") @SuppressWarnings({"unchecked", "Finally"})
private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes) private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes)
throws NoResponseException, NotConnectedException, InterruptedException { throws NoResponseException, NotConnectedException, InterruptedException {
for (Class<? extends AbstractSmackIntTest> testClass : classes) { for (Class<? extends AbstractSmackIntTest> testClass : classes) {

View File

@ -33,7 +33,12 @@ public class ResultSyncPoint<R, E extends Exception> {
if (exception != null) { if (exception != null) {
throw exception; throw exception;
} }
wait(timeout); final long deadline = System.currentTimeMillis() + timeout;
while (result == null && exception == null) {
final long now = System.currentTimeMillis();
if (now > deadline) break;
wait(deadline - now);
}
} }
if (result != null) { if (result != null) {
return result; return result;

View File

@ -184,8 +184,8 @@ public class XmppHostnameVerifier implements HostnameVerifier {
} }
private static boolean matchesPerRfc2818(String name, String template) { private static boolean matchesPerRfc2818(String name, String template) {
String[] nameParts = name.toLowerCase(Locale.US).split("."); String[] nameParts = name.toLowerCase(Locale.US).split("\\.");
String[] templateParts = template.toLowerCase(Locale.US).split("."); String[] templateParts = template.toLowerCase(Locale.US).split("\\.");
if (nameParts.length != templateParts.length) { if (nameParts.length != templateParts.length) {
return false; return false;

View File

@ -183,6 +183,7 @@ import org.jxmpp.jid.Jid;
* @see JingleMediaManager * @see JingleMediaManager
* @see BasicTransportManager , STUNTransportManager, BridgedTransportManager, TransportResolver, BridgedResolver, ICEResolver, STUNResolver and BasicResolver. * @see BasicTransportManager , STUNTransportManager, BridgedTransportManager, TransportResolver, BridgedResolver, ICEResolver, STUNResolver and BasicResolver.
*/ */
@SuppressWarnings("SynchronizeOnNonFinalField")
public class JingleManager implements JingleSessionListener { public class JingleManager implements JingleSessionListener {
private static final Logger LOGGER = Logger.getLogger(JingleManager.class.getName()); private static final Logger LOGGER = Logger.getLogger(JingleManager.class.getName());

View File

@ -51,7 +51,7 @@ public class AudioReceiver implements ReceiveStreamListener, SessionListener,
boolean dataReceived = false; boolean dataReceived = false;
Object dataSync; final Object dataSync;
JingleMediaSession jingleMediaSession; JingleMediaSession jingleMediaSession;
public AudioReceiver(final Object dataSync, final JingleMediaSession jingleMediaSession) { public AudioReceiver(final Object dataSync, final JingleMediaSession jingleMediaSession) {

View File

@ -44,6 +44,7 @@ import org.jxmpp.jid.Jid;
* @author Thiago Camargo * @author Thiago Camargo
* @author Alvaro Saurin * @author Alvaro Saurin
*/ */
@SuppressWarnings("EqualsHashCode")
public abstract class TransportCandidate { public abstract class TransportCandidate {
private static final Logger LOGGER = Logger.getLogger(TransportCandidate.class.getName()); private static final Logger LOGGER = Logger.getLogger(TransportCandidate.class.getName());

View File

@ -55,8 +55,8 @@ public class AgentRoster {
private XMPPConnection connection; private XMPPConnection connection;
private Jid workgroupJID; private Jid workgroupJID;
private List<String> entries; private final List<String> entries = new ArrayList<String>();
private List<AgentRosterListener> listeners; private final List<AgentRosterListener> listeners = new ArrayList<>();
private final Map<Jid, Map<Resourcepart, Presence>> presenceMap = new HashMap<>(); private final Map<Jid, Map<Resourcepart, Presence>> presenceMap = new HashMap<>();
// The roster is marked as initialized when at least a single roster packet // The roster is marked as initialized when at least a single roster packet
// has been recieved and processed. // has been recieved and processed.
@ -72,8 +72,6 @@ public class AgentRoster {
AgentRoster(XMPPConnection connection, Jid workgroupJID) throws NotConnectedException, InterruptedException { AgentRoster(XMPPConnection connection, Jid workgroupJID) throws NotConnectedException, InterruptedException {
this.connection = connection; this.connection = connection;
this.workgroupJID = workgroupJID; this.workgroupJID = workgroupJID;
entries = new ArrayList<String>();
listeners = new ArrayList<AgentRosterListener>();
// Listen for any roster packets. // Listen for any roster packets.
StanzaFilter rosterFilter = new StanzaTypeFilter(AgentStatusRequest.class); StanzaFilter rosterFilter = new StanzaTypeFilter(AgentStatusRequest.class);
connection.addAsyncStanzaListener(new AgentStatusListener(), rosterFilter); connection.addAsyncStanzaListener(new AgentStatusListener(), rosterFilter);

View File

@ -47,11 +47,10 @@ public class AgentStatusRequest extends IQ {
*/ */
public static final String NAMESPACE = "http://jabber.org/protocol/workgroup"; public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
private Set<Item> agents; private final Set<Item> agents = new HashSet<>();
public AgentStatusRequest() { public AgentStatusRequest() {
super(ELEMENT_NAME, NAMESPACE); super(ELEMENT_NAME, NAMESPACE);
agents = new HashSet<Item>();
} }
public int getAgentCount() { public int getAgentCount() {

View File

@ -132,7 +132,7 @@ public class OccupantsInfo extends IQ {
public static class Provider extends IQProvider<OccupantsInfo> { public static class Provider extends IQProvider<OccupantsInfo> {
@Override @Override
public OccupantsInfo parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { public OccupantsInfo parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
OccupantsInfo occupantsInfo = new OccupantsInfo(parser.getAttributeValue("", "roomID")); OccupantsInfo occupantsInfo = new OccupantsInfo(parser.getAttributeValue("", "roomID"));
boolean done = false; boolean done = false;
@ -149,7 +149,7 @@ public class OccupantsInfo extends IQ {
return occupantsInfo; return occupantsInfo;
} }
private OccupantInfo parseOccupantInfo(XmlPullParser parser) throws XmlPullParserException, IOException { private OccupantInfo parseOccupantInfo(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException {
boolean done = false; boolean done = false;
String jid = null; String jid = null;
@ -167,7 +167,7 @@ public class OccupantsInfo extends IQ {
try { try {
joined = UTC_FORMAT.parse(parser.nextText()); joined = UTC_FORMAT.parse(parser.nextText());
} catch (ParseException e) { } catch (ParseException e) {
new SmackException(e); throw new SmackException(e);
} }
} else if (eventType == XmlPullParser.END_TAG && } else if (eventType == XmlPullParser.END_TAG &&
"occupant".equals(parser.getName())) { "occupant".equals(parser.getName())) {

View File

@ -56,14 +56,7 @@ public final class QueueDetails implements ExtensionElement {
/** /**
* The list of users in the queue. * The list of users in the queue.
*/ */
private Set<QueueUser> users; private final Set<QueueUser> users = new HashSet<>();
/**
* Creates a new QueueDetails packet
*/
private QueueDetails() {
users = new HashSet<QueueUser>();
}
/** /**
* Returns the number of users currently in the queue that are waiting to * Returns the number of users currently in the queue that are waiting to

View File

@ -50,7 +50,7 @@ import java.util.List;
*/ */
public class RosterExchange implements ExtensionElement { public class RosterExchange implements ExtensionElement {
private List<RemoteRosterEntry> remoteRosterEntries = new ArrayList<RemoteRosterEntry>(); private final List<RemoteRosterEntry> remoteRosterEntries = new ArrayList<>();
/** /**
* Creates a new empty roster exchange package. * Creates a new empty roster exchange package.

View File

@ -105,6 +105,7 @@ public class PacketWriterTest {
public class BlockingStringWriter extends Writer { public class BlockingStringWriter extends Writer {
@Override @Override
@SuppressWarnings("WaitNotInLoop")
public void write(char[] cbuf, int off, int len) throws IOException { public void write(char[] cbuf, int off, int len) throws IOException {
try { try {
wait(); wait();