Skip to content

Commit

Permalink
Lint fixes: Remove dead code, etc.
Browse files Browse the repository at this point in the history
- make method static when possible
- remove never thrown Exception declarations
- other fixes
  • Loading branch information
Flowdalic committed Mar 24, 2015
1 parent 83b84c5 commit c6594ae
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public String getStreamId() {
}

protected void bindResourceAndEstablishSession(String resource) throws XMPPErrorException,
IOException, SmackException, InterruptedException {
SmackException, InterruptedException {

// Wait until either:
// - the servers last features stanza has been parsed
Expand Down Expand Up @@ -1392,6 +1392,7 @@ else if (eventType == XmlPullParser.END_TAG && parser.getDepth() == initialDepth
afterFeaturesReceived();
}

@SuppressWarnings("unused")
protected void afterFeaturesReceived() throws SecurityRequiredException, NotConnectedException, InterruptedException {
// Default implementation does nothing
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@
import java.util.List;
import java.util.ArrayList;

import javax.xml.parsers.ParserConfigurationException;

/**
*
*/
public class MessageTest {

@Test
public void setMessageTypeTest() throws IOException, SAXException, ParserConfigurationException {
public void setMessageTypeTest() throws IOException, SAXException {
Message.Type type = Message.Type.chat;
Message.Type type2 = Message.Type.headline;

Expand Down Expand Up @@ -76,7 +74,7 @@ public void setNullMessageBodyTest() {
}

@Test
public void setMessageSubjectTest() throws IOException, SAXException, ParserConfigurationException {
public void setMessageSubjectTest() throws IOException, SAXException {
final String messageSubject = "This is a test of the emergency broadcast system.";

StringBuilder controlBuilder = new StringBuilder();
Expand All @@ -95,7 +93,7 @@ public void setMessageSubjectTest() throws IOException, SAXException, ParserConf
}

@Test
public void oneMessageBodyTest() throws IOException, SAXException, ParserConfigurationException {
public void oneMessageBodyTest() throws IOException, SAXException {
final String messageBody = "This is a test of the emergency broadcast system.";

StringBuilder controlBuilder = new StringBuilder();
Expand All @@ -114,7 +112,7 @@ public void oneMessageBodyTest() throws IOException, SAXException, ParserConfigu
}

@Test
public void multipleMessageBodiesTest() throws IOException, SAXException, ParserConfigurationException {
public void multipleMessageBodiesTest() throws IOException, SAXException {
final String messageBody1 = "This is a test of the emergency broadcast system, 1.";
final String lang2 = "ru";
final String messageBody2 = "This is a test of the emergency broadcast system, 2.";
Expand Down Expand Up @@ -172,7 +170,7 @@ public void removeMessageBodyTest() {
}

@Test
public void setMessageThreadTest() throws IOException, SAXException, ParserConfigurationException {
public void setMessageThreadTest() throws IOException, SAXException {
final String messageThread = "1234";

StringBuilder controlBuilder = new StringBuilder();
Expand All @@ -191,7 +189,7 @@ public void setMessageThreadTest() throws IOException, SAXException, ParserConfi
}

@Test
public void messageXmlLangTest() throws IOException, SAXException, ParserConfigurationException {
public void messageXmlLangTest() throws IOException, SAXException {
final String lang = "sp";

StringBuilder controlBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

/**
*
*/
public class PresenceTest {
@Test
public void setPresenceTypeTest() throws IOException, SAXException, ParserConfigurationException {
public void setPresenceTypeTest() throws IOException, SAXException {
Presence.Type type = Presence.Type.unavailable;
Presence.Type type2 = Presence.Type.subscribe;

Expand Down Expand Up @@ -81,7 +79,7 @@ public void isPresenceAvailableTest() {
}

@Test
public void setPresenceStatusTest() throws IOException, SAXException, ParserConfigurationException {
public void setPresenceStatusTest() throws IOException, SAXException {
final String status = "This is a test of the emergency broadcast system.";

StringBuilder controlBuilder = new StringBuilder();
Expand All @@ -100,7 +98,7 @@ public void setPresenceStatusTest() throws IOException, SAXException, ParserConf
}

@Test
public void setPresencePriorityTest() throws IOException, SAXException, ParserConfigurationException {
public void setPresencePriorityTest() throws IOException, SAXException {
final int priority = 10;

StringBuilder controlBuilder = new StringBuilder();
Expand All @@ -124,7 +122,7 @@ public void setIllegalPriorityTest() {
}

@Test
public void setPresenceModeTest() throws IOException, SAXException, ParserConfigurationException {
public void setPresenceModeTest() throws IOException, SAXException {
Presence.Mode mode1 = Presence.Mode.dnd;
final int priority = 10;
final String status = "This is a test of the emergency broadcast system.";
Expand Down Expand Up @@ -175,7 +173,7 @@ public void isModeAwayTest() {
}

@Test
public void presenceXmlLangTest() throws IOException, SAXException, ParserConfigurationException {
public void presenceXmlLangTest() throws IOException, SAXException {
final String lang = "sp";

StringBuilder controlBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ public synchronized static BookmarkManager getBookmarkManager(XMPPConnection con
BookmarkManager manager = bookmarkManagerMap.get(connection);
if (manager == null) {
manager = new BookmarkManager(connection);
bookmarkManagerMap.put(connection, manager);
}
return manager;
}

private PrivateDataManager privateDataManager;
private final PrivateDataManager privateDataManager;
private Bookmarks bookmarks;
private final Object bookmarkLock = new Object();

Expand All @@ -80,9 +81,8 @@ public synchronized static BookmarkManager getBookmarkManager(XMPPConnection con
*
* @param connection the connection for persisting and retrieving bookmarks.
*/
private BookmarkManager(XMPPConnection connection) throws XMPPException, SmackException {
private BookmarkManager(XMPPConnection connection) {
privateDataManager = PrivateDataManager.getInstanceFor(connection);
bookmarkManagerMap.put(connection, this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private synchronized boolean updateChatState(Chat chat, ChatState newState) {
return false;
}

private void fireNewChatState(Chat chat, ChatState state) {
private static void fireNewChatState(Chat chat, ChatState state) {
for (ChatMessageListener listener : chat.getListeners()) {
if (listener instanceof ChatStateListener) {
((ChatStateListener) listener).stateChanged(chat, state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ else if (Action.cancel.equals(action)) {
* @param condition the condition of the error.
* @throws NotConnectedException
*/
private IQ respondError(AdHocCommandData response,
private static IQ respondError(AdHocCommandData response,
XMPPError.Condition condition) {
return respondError(response, new XMPPError(condition));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.logging.Logger;

import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;


Expand Down Expand Up @@ -193,10 +194,20 @@ public InputStream call() throws Exception {
try {
inputStream = streamNegotiatorTask.get(15, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
throw new SmackException("Interruption while executing", e);
}
catch (ExecutionException e) {
final Throwable cause = e.getCause();
if (cause instanceof XMPPErrorException) {
throw (XMPPErrorException) cause;
}
if (cause instanceof InterruptedException) {
throw (InterruptedException) cause;
}
if (cause instanceof NoResponseException) {
throw (NoResponseException) cause;
}
if (cause instanceof SmackException) {
throw (SmackException) cause;
}
throw new SmackException("Error in execution", e);
}
catch (TimeoutException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ protected static StreamInitiation createInitiationAccept(
}

protected final IQ initiateIncomingStream(final XMPPConnection connection, StreamInitiation initiation)
// CHECKSTYLE:OFF
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// CHECKSTYLE:ON
throws NoResponseException, XMPPErrorException, NotConnectedException {
final StreamInitiation response = createInitiationAccept(initiation,
getNamespaces());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ public PubSub(Jid to, Type type, PubSubNamespace ns) {
setType(type);
}

/**
* Returns the XML element name of the extension sub-packet root element.
*
* @return the XML element name of the stanza(/packet) extension.
*/
@SuppressWarnings("static-method")
public String getElementName() {
return ELEMENT;
}

@SuppressWarnings("unchecked")
public <PE extends ExtensionElement> PE getExtension(PubSubElementType elem)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.IOException;
import java.util.List;

import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smackx.xdatalayout.packet.DataLayout;
import org.jivesoftware.smackx.xdatalayout.packet.DataLayout.DataFormLayoutElement;
import org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Fieldref;
Expand All @@ -37,8 +36,7 @@
*/
public class DataLayoutProvider {

public static DataLayout parse(XmlPullParser parser) throws XmlPullParserException, IOException,
SmackException {
public static DataLayout parse(XmlPullParser parser) throws XmlPullParserException, IOException {
DataLayout dataLayout = new DataLayout(parser.getAttributeValue("", "label"));
parseLayout(dataLayout.getPageLayout(), parser);
return dataLayout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public Set<ChatManagerListener> getChatListeners() {
return Collections.unmodifiableSet(chatManagerListeners);
}

private void deliverMessage(Chat chat, Message message) {
private static void deliverMessage(Chat chat, Message message) {
// Here we will run any interceptors
chat.deliver(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public boolean resetEntries(Collection<Item> items, String version) {
return setRosterVersion(version);
}

private Item readEntry(File file) {
private static Item readEntry(File file) {
String s = FileUtils.readFile(file);
if (s == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void chatNotMatchedWithTypeNormal() {
assertNull(listener.getNewChat());
}

private Message createChatPacket(final String threadId, final boolean isFullJid) {
private static Message createChatPacket(final String threadId, final boolean isFullJid) {
Message chatMsg = new Message(JidTestUtil.BARE_JID_1, Message.Type.chat);
chatMsg.setBody("the body message - " + System.currentTimeMillis());
Jid jid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -37,7 +36,7 @@ public class RosterOfflineTest {
Roster roster;

@Before
public void setup() throws XMPPException, SmackException {
public void setup() {
this.connection = new DummyConnection();
assertFalse(connection.isConnected());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.im.InitSmackIm;
import org.jivesoftware.smack.packet.ErrorIQ;
import org.jivesoftware.smack.packet.IQ;
Expand Down Expand Up @@ -511,8 +510,7 @@ public void testEmptyGroupRosterPush() throws Throwable {
* @param connection the dummy connection of which the provided roster belongs to.
* @param roster the roster (or buddy list) which should be initialized.
*/
public static void removeAllRosterEntries(DummyConnection connection, Roster roster)
throws InterruptedException, XMPPException {
public static void removeAllRosterEntries(DummyConnection connection, Roster roster) {
for(RosterEntry entry : roster.getEntries()) {
// prepare the roster push packet
final RosterPacket rosterPush= new RosterPacket();
Expand All @@ -539,7 +537,7 @@ public static void removeAllRosterEntries(DummyConnection connection, Roster ros
* @throws SmackException
* @throws XmppStringprepException
*/
private void initRoster() throws InterruptedException, XMPPException, SmackException, XmppStringprepException {
private void initRoster() throws InterruptedException, SmackException, XmppStringprepException {
roster.reload();
while (true) {
final Stanza sentPacket = connection.getSentPacket();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void testEqualVersionStored() throws InterruptedException, IOException, X
* @throws XmppStringprepException
*/
@Test(timeout = 5000)
public void testOtherVersionStored() throws InterruptedException, XMPPException, SmackException, XmppStringprepException {
public void testOtherVersionStored() throws XMPPException, SmackException, XmppStringprepException {
Item vaglafItem = vaglafItem();

// We expect that the roster request is the only packet sent. This is not part of the specification,
Expand Down Expand Up @@ -226,7 +226,7 @@ public void testRosterVersioningWithCachedRosterAndPushes() throws Throwable {
}
}

private Item vaglafItem() throws XmppStringprepException {
private static Item vaglafItem() throws XmppStringprepException {
Item item = new Item(JidCreate.from("vaglaf@example.com"), "vaglaf the only");
item.setItemType(ItemType.both);
item.addGroupName("all");
Expand All @@ -235,7 +235,7 @@ private Item vaglafItem() throws XmppStringprepException {
return item;
}

private void populateStore(RosterStore store) throws IOException {
private static void populateStore(RosterStore store) throws IOException {
store.addEntry(new RosterPacket.Item(JidCreate.from("geoff@example.com"), "geoff hurley"), "");

RosterPacket.Item item = new RosterPacket.Item(JidCreate.from("joe@example.com"), "joe stevens");
Expand All @@ -249,7 +249,7 @@ private void populateStore(RosterStore store) throws IOException {
store.addEntry(item, "v96");
}

private void answerWithEmptyRosterResult() throws InterruptedException {
private void answerWithEmptyRosterResult() {
// We expect that the roster request is the only packet sent. This is not part of the specification,
// but a shortcut in the test implementation.
Stanza sentPacket = connection.getSentPacket();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ public static byte[] decode( String s, int options )
if( bytes != null && bytes.length >= 4 )
{

int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
int head = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head )
{
java.io.ByteArrayInputStream bais = null;
Expand Down Expand Up @@ -969,12 +969,10 @@ public static Object decodeToObject( String encodedObject )
catch( java.io.IOException e )
{
LOGGER.log(Level.SEVERE, "Error reading object", e);
obj = null;
} // end catch
catch( java.lang.ClassNotFoundException e )
{
LOGGER.log(Level.SEVERE, "Class not found for encoded object", e);
obj = null;
} // end catch
finally
{
Expand Down
Loading

0 comments on commit c6594ae

Please sign in to comment.