From 3132d9a22488d5f70759af01b87774e65fc86d73 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 28 Mar 2018 15:56:04 +0200 Subject: [PATCH] Bump errorprone to 2.2.0 --- build.gradle | 19 +++--- .../smack/bosh/XMPPBOSHConnection.java | 1 + .../smack/SmackConfigurationTest.java | 10 ++- .../smackx/filetransfer/FileTransfer.java | 1 + .../ibb/InBandBytestreamManagerTest.java | 12 ++-- .../smackx/pubsub/ConfigureFormTest.java | 2 + .../DataValidationHelperTest.java | 7 +-- .../smack/chat/ChatConnectionTest.java | 3 +- .../jivesoftware/smack/roster/RosterTest.java | 6 +- .../roster/SubscriptionPreApprovalTest.java | 6 +- .../smackx/omemo/OmemoKeyTransportTest.java | 9 +-- .../smackx/workgroup/packet/AgentStatus.java | 2 +- .../workgroup/packet/OccupantsInfo.java | 2 +- .../smackx/workgroup/packet/Transcripts.java | 2 +- .../workgroup/packet/TranscriptsProvider.java | 2 +- .../smack/omemo/SignalOmemoKeyUtilTest.java | 61 ++++++------------- .../smack/tcp/XMPPTCPConnection.java | 1 + 17 files changed, 59 insertions(+), 87 deletions(-) diff --git a/build.gradle b/build.gradle index 0ea9f68bd..44eb037af 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { classpath 'org.kordamp:markdown-gradle-plugin:1.0.0' classpath 'org.kordamp.gradle:clirr-gradle-plugin:0.2.2' classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1" - classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.10' + classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.13' } } @@ -160,7 +160,15 @@ allprojects { '-Xlint:-path', // Disable errorprone checks '-Xep:TypeParameterUnusedInFormals:OFF', - '-Xep:TopLevel:OFF', + // Disable errorpone StringSplitter check, as it + // recommends using Splitter from Guava, which we don't + // have (nor want to use in Smack). + '-Xep:StringSplitter:OFF', + '-Xep:JdkObsolete:OFF', + // Disabled because sinttest re-uses BeforeClass from junit. + // TODO: change sinttest so that it has it's own + // BeforeClass and re-enable this check. + '-Xep:JUnit4ClassAnnotationNonStatic:OFF', ] } @@ -191,11 +199,8 @@ allprojects { options.encoding = 'UTF-8' } - // Pin the errorprone version to prevent "unsupported major.minor - // version 52.0" error messages caused by the errorprone javac. - // See https://github.com/tbroyer/gradle-errorprone-plugin/issues/18 for more information. - configurations.errorprone { - resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.18' + dependencies { + errorprone 'com.google.errorprone:error_prone_core:2.2.0' } // Make all project's 'test' target depend on javadoc, so that diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java index 03c180a15..6049a76ab 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java @@ -88,6 +88,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { /** * Holds the initial configuration used while creating the connection. */ + @SuppressWarnings("HidingField") private final BOSHConfiguration config; // Some flags which provides some info about the current state. diff --git a/smack-core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java b/smack-core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java index a863d44dd..2d9de46c1 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java @@ -18,20 +18,18 @@ package org.jivesoftware.smack; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.junit.Ignore; import org.junit.Test; public class SmackConfigurationTest { + /** + * Test is Smack is able to initialize itself without throwing a Throwable. + */ @Test public void testSmackConfiguration() { - try { - SmackConfiguration.getDefaultReplyTimeout(); - } catch (Throwable t) { - fail("SmackConfiguration threw Throwable"); - } + SmackConfiguration.getDefaultReplyTimeout(); } // As there is currently no annotation/way to run a testclass/single test in a separate VM, diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java index 796b989f1..a4dcf9231 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java @@ -312,6 +312,7 @@ public abstract class FileTransfer { return amountWritten; } + @SuppressWarnings("JavaLangClash") public enum Error { /** * No error. diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java index 888476a4f..ff9997f89 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java @@ -160,7 +160,7 @@ public class InBandBytestreamManagerTest extends InitExtensions { } @Test - public void shouldUseConfiguredStanzaType() throws SmackException, InterruptedException { + public void shouldUseConfiguredStanzaType() throws SmackException, InterruptedException, XMPPException { InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection); byteStreamManager.setStanza(StanzaType.MESSAGE); @@ -173,14 +173,10 @@ public class InBandBytestreamManagerTest extends InitExtensions { }); - try { - // start In-Band Bytestream - byteStreamManager.establishSession(targetJID); - } - catch (XMPPException e) { - protocol.verifyAll(); - } + // start In-Band Bytestream + byteStreamManager.establishSession(targetJID); + protocol.verifyAll(); } @Test diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java index 461ce7e8a..5cfe0b302 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java @@ -17,6 +17,7 @@ package org.jivesoftware.smackx.pubsub; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import java.io.IOException; @@ -77,6 +78,7 @@ public class ConfigureFormTest extends InitExtensions try { node.getNodeConfiguration(); + fail(); } catch (XMPPErrorException e) { diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/xdatavalidation/DataValidationHelperTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/xdatavalidation/DataValidationHelperTest.java index a1ac22160..84ee4117e 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/xdatavalidation/DataValidationHelperTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/xdatavalidation/DataValidationHelperTest.java @@ -67,12 +67,7 @@ public class DataValidationHelperTest { } field.setType(FormField.Type.list_multi); - try { - element.checkConsistency(field); - } - catch (ValidationConsistencyException e) { - fail("No correct check on consistency"); - } + element.checkConsistency(field); } 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 da562aae6..c2f7bf049 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 @@ -21,7 +21,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.jivesoftware.smack.DummyConnection; import org.jivesoftware.smack.packet.Message; @@ -343,7 +342,7 @@ public class ChatConnectionTest { try { chatServer.join(); } catch (InterruptedException e) { - fail(); + throw new AssertionError(e); } waitListener.waitAndReset(); } 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 a52d9566e..6372e28d8 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 @@ -683,9 +683,9 @@ public class RosterTest extends InitSmackIm { connection.processStanza(response); // Verify the roster update request - assertSame("A roster set MUST contain one and only one element.", - 1, - rosterRequest.getRosterItemCount()); + if (rosterRequest.getRosterItemCount() != 1) { + throw new AssertionError("A roster set MUST contain one and only one element."); + } verifyUpdateRequest(rosterRequest); break; } diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java index 129e4fe2e..c434460b1 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java @@ -180,9 +180,9 @@ public class SubscriptionPreApprovalTest extends InitSmackIm { connection.processStanza(response); // Verify the roster update request - assertSame("A roster set MUST contain one and only one element.", - 1, - rosterRequest.getRosterItemCount()); + if (rosterRequest.getRosterItemCount() != 1) { + throw new AssertionError("A roster set MUST contain one and only one element."); + } verifyRosterUpdateRequest(rosterRequest); break; } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoKeyTransportTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoKeyTransportTest.java index 90cabb88b..dde41eb15 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoKeyTransportTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoKeyTransportTest.java @@ -23,7 +23,6 @@ import static org.jivesoftware.smackx.omemo.OmemoIntegrationTestHelper.unidirect import static org.junit.Assert.assertTrue; import java.util.Arrays; -import java.util.concurrent.TimeoutException; import java.util.logging.Level; import org.jivesoftware.smack.SmackException; @@ -37,7 +36,6 @@ import org.jivesoftware.smackx.omemo.internal.OmemoMessageInformation; import org.jivesoftware.smackx.omemo.listener.OmemoMessageListener; import org.jivesoftware.smackx.omemo.util.OmemoMessageBuilder; -import junit.framework.TestCase; import org.igniterealtime.smack.inttest.SmackIntegrationTest; import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment; import org.igniterealtime.smack.inttest.TestNotPossibleException; @@ -97,11 +95,8 @@ public class OmemoKeyTransportTest extends AbstractOmemoIntegrationTest { ChatManager.getInstanceFor(alice.getConnection()).chatWith(bob.getOwnJid().asEntityBareJidIfPossible()) .send(message); - try { - syncPoint.waitForResult(10 * 1000); - } catch (TimeoutException e) { - TestCase.fail("We MUST have received the keyTransportMessage within 10 seconds."); - } + // TODO: Should use 'timeout' field instead of hardcoded '10 * 1000'. + syncPoint.waitForResult(10 * 1000); } @Override diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/AgentStatus.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/AgentStatus.java index 6ee9a0a9b..b90fb0010 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/AgentStatus.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/AgentStatus.java @@ -39,7 +39,7 @@ import org.xmlpull.v1.XmlPullParserException; */ public class AgentStatus implements ExtensionElement { - @SuppressWarnings("SimpleDateFormatConstant") + @SuppressWarnings("DateFormatConstant") private static final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); static { diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OccupantsInfo.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OccupantsInfo.java index a84eb23a6..224b7fd80 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OccupantsInfo.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OccupantsInfo.java @@ -41,7 +41,7 @@ import org.xmlpull.v1.XmlPullParserException; */ public class OccupantsInfo extends IQ { - @SuppressWarnings("SimpleDateFormatConstant") + @SuppressWarnings("DateFormatConstant") private static final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); static { diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/Transcripts.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/Transcripts.java index 9077d9723..6f0ea313b 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/Transcripts.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/Transcripts.java @@ -37,7 +37,7 @@ import org.jxmpp.jid.Jid; */ public class Transcripts extends IQ { - @SuppressWarnings("SimpleDateFormatConstant") + @SuppressWarnings("DateFormatConstant") private static final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); static { UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0")); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java index 147e65056..0909a4859 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java @@ -39,7 +39,7 @@ import org.xmlpull.v1.XmlPullParserException; */ public class TranscriptsProvider extends IQProvider { - @SuppressWarnings("SimpleDateFormatConstant") + @SuppressWarnings("DateFormatConstant") private static final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); static { UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0")); diff --git a/smack-omemo-signal/src/test/java/org/jivesoftware/smack/omemo/SignalOmemoKeyUtilTest.java b/smack-omemo-signal/src/test/java/org/jivesoftware/smack/omemo/SignalOmemoKeyUtilTest.java index 935d3c9bb..ecd322e97 100644 --- a/smack-omemo-signal/src/test/java/org/jivesoftware/smack/omemo/SignalOmemoKeyUtilTest.java +++ b/smack-omemo-signal/src/test/java/org/jivesoftware/smack/omemo/SignalOmemoKeyUtilTest.java @@ -24,7 +24,6 @@ import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertNotNull; import static junit.framework.TestCase.assertNotSame; import static junit.framework.TestCase.assertTrue; -import static junit.framework.TestCase.fail; import java.util.HashMap; import java.util.Iterator; @@ -66,32 +65,24 @@ public class SignalOmemoKeyUtilTest extends SmackTestSuite { } @Test - public void omemoIdentityKeyPairSerializationTest() { + public void omemoIdentityKeyPairSerializationTest() throws CorruptedOmemoKeyException { IdentityKeyPair ikp = keyUtil.generateOmemoIdentityKeyPair(); byte[] bytes = keyUtil.identityKeyPairToBytes(ikp); assertNotNull("serialized identityKeyPair must not be null.", bytes); assertNotSame("serialized identityKeyPair must not be of length 0.", 0, bytes.length); - try { - IdentityKeyPair ikp2 = keyUtil.identityKeyPairFromBytes(bytes); - assertTrue("Deserialized IdentityKeyPairs PublicKey must equal the originals one.", + + IdentityKeyPair ikp2 = keyUtil.identityKeyPairFromBytes(bytes); + assertTrue("Deserialized IdentityKeyPairs PublicKey must equal the originals one.", ikp.getPublicKey().equals(ikp2.getPublicKey())); - } catch (CorruptedOmemoKeyException e) { - fail("Caught exception while deserializing IdentityKeyPair."); - } } @Test - public void omemoIdentityKeySerializationTest() { + public void omemoIdentityKeySerializationTest() throws CorruptedOmemoKeyException { IdentityKey k = keyUtil.generateOmemoIdentityKeyPair().getPublicKey(); - - try { - assertEquals("Deserialized IdentityKey must equal the original one.", - k, keyUtil.identityKeyFromBytes(keyUtil.identityKeyToBytes(k))); - } catch (CorruptedOmemoKeyException e) { - fail("Caught exception while serializing and deserializing identityKey (" + e + "): " + e.getMessage()); - } + assertEquals("Deserialized IdentityKey must equal the original one.", k, + keyUtil.identityKeyFromBytes(keyUtil.identityKeyToBytes(k))); } @Test @@ -103,16 +94,12 @@ public class SignalOmemoKeyUtilTest extends SmackTestSuite { } @Test - public void generateOmemoSignedPreKeyTest() { + public void generateOmemoSignedPreKeyTest() throws CorruptedOmemoKeyException { IdentityKeyPair ikp = keyUtil.generateOmemoIdentityKeyPair(); - try { - SignedPreKeyRecord spk = keyUtil.generateOmemoSignedPreKey(ikp, 1); - assertNotNull("SignedPreKey must not be null.", spk); - assertEquals("SignedPreKeyId must match.", 1, spk.getId()); - assertEquals("singedPreKeyId must match here also.", 1, keyUtil.signedPreKeyIdFromKey(spk)); - } catch (CorruptedOmemoKeyException e) { - fail("Caught an exception while generating signedPreKey (" + e + "): " + e.getMessage()); - } + SignedPreKeyRecord spk = keyUtil.generateOmemoSignedPreKey(ikp, 1); + assertNotNull("SignedPreKey must not be null.", spk); + assertEquals("SignedPreKeyId must match.", 1, spk.getId()); + assertEquals("singedPreKeyId must match here also.", 1, keyUtil.signedPreKeyIdFromKey(spk)); } @Test @@ -124,25 +111,17 @@ public class SignalOmemoKeyUtilTest extends SmackTestSuite { } @Test - public void addressToDeviceTest() { - SignalProtocolAddress address = new SignalProtocolAddress("test@server.tld",1337); - try { - OmemoDevice device = keyUtil.addressAsOmemoDevice(address); - assertEquals(device, new OmemoDevice(JidCreate.bareFrom("test@server.tld"), 1337)); - } catch (XmppStringprepException e) { - fail("Could not convert address to device: " + e + " " + e.getMessage()); - } + public void addressToDeviceTest() throws XmppStringprepException { + SignalProtocolAddress address = new SignalProtocolAddress("test@server.tld", 1337); + OmemoDevice device = keyUtil.addressAsOmemoDevice(address); + assertEquals(device, new OmemoDevice(JidCreate.bareFrom("test@server.tld"), 1337)); } @Test - public void deviceToAddressTest() { - try { - OmemoDevice device = new OmemoDevice(JidCreate.bareFrom("test@server.tld"), 1337); - SignalProtocolAddress address = keyUtil.omemoDeviceAsAddress(device); - assertEquals(address, new SignalProtocolAddress("test@server.tld", 1337)); - } catch (XmppStringprepException e) { - fail("Could not convert device to address: " + e + " " + e.getMessage()); - } + public void deviceToAddressTest() throws XmppStringprepException { + OmemoDevice device = new OmemoDevice(JidCreate.bareFrom("test@server.tld"), 1337); + SignalProtocolAddress address = keyUtil.omemoDeviceAsAddress(device); + assertEquals(address, new SignalProtocolAddress("test@server.tld", 1337)); } @Test 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 b49a673ed..df9bba343 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 @@ -293,6 +293,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { */ private final Set requestAckPredicates = new LinkedHashSet<>(); + @SuppressWarnings("HidingField") private final XMPPTCPConnectionConfiguration config; /**