SPARK-1469: Code cleanup: Fix probable bugs: Remove unused assignment and redundant initializers

This commit is contained in:
arthur 2020-11-13 23:00:43 +03:00
parent f6f273307d
commit 506e744fbd
34 changed files with 118 additions and 170 deletions

View File

@ -59,17 +59,15 @@ public class ButtonFactory {
return new RolloverButton(SparkRes.getImageIcon(SparkRes.BUZZ_IMAGE));
}
public RolloverButton createEmoticonButton() {
final EmoticonManager emoticonManager = EmoticonManager.getInstance();
final String activeEmoticonSetName = emoticonManager.getActiveEmoticonSetName();
final Emoticon smileEmoticon = emoticonManager.getEmoticon(activeEmoticonSetName, ":)");
Emoticon firstEmoticon=(smileEmoticon == null) ? firstEmoticon=emoticonManager.getFirstEmotion(activeEmoticonSetName) : smileEmoticon;
URL emotionURL = emoticonManager.getEmoticonURL(firstEmoticon);
ImageIcon icon = new ImageIcon(emotionURL);
firstEmoticon=null;
return new RolloverButton(icon);
}
public RolloverButton createEmoticonButton() {
final EmoticonManager emoticonManager = EmoticonManager.getInstance();
final String activeEmoticonSetName = emoticonManager.getActiveEmoticonSetName();
final Emoticon smileEmoticon = emoticonManager.getEmoticon(activeEmoticonSetName, ":)");
Emoticon firstEmoticon = (smileEmoticon == null) ? emoticonManager.getFirstEmotion(activeEmoticonSetName) : smileEmoticon;
URL emotionURL = emoticonManager.getEmoticonURL(firstEmoticon);
ImageIcon icon = new ImageIcon(emotionURL);
return new RolloverButton(icon);
}
public JLabel createDivider() {
return new JLabel(SparkRes.getImageIcon("DIVIDER_IMAGE"));

View File

@ -247,7 +247,7 @@ public abstract class JiveSortableTable extends Table {
private static final long serialVersionUID = 8670248883432881619L;
Border unselectedBorder;
Border selectedBorder;
boolean isBordered = true;
boolean isBordered;
/**
* JLabelConstructor to build ui.

View File

@ -276,7 +276,7 @@ public abstract class Table extends JXTable {
private static final long serialVersionUID = 4433780600297455731L;
Border unselectedBorder;
Border selectedBorder;
boolean isBordered = true;
boolean isBordered;
/**
* JLabelConstructor to build ui.

View File

@ -26,8 +26,8 @@ import javax.swing.JPanel;
public class SparkTab extends JPanel
{
private static final long serialVersionUID = 2027267184472260195L;
private SparkTabbedPane pane = null;
private Component component = null;
private SparkTabbedPane pane;
private Component component;
public SparkTab(SparkTabbedPane pane, Component comp)
{

View File

@ -42,7 +42,7 @@ public class SparkTabbedPane extends JPanel {
private static final long serialVersionUID = -9007068462231539973L;
private static final String NAME = "SparkTabbedPane";
private List<SparkTabbedPaneListener> listeners = new ArrayList<>();
private JTabbedPane pane = null;
private JTabbedPane pane;
private Icon closeInactiveButtonIcon;
private Icon closeActiveButtonIcon;
private boolean closeEnabled = false;

View File

@ -40,24 +40,20 @@ public class BroadcastHistoryFrame extends javax.swing.JFrame {
BroadcastHistoryArea.setWrapStyleWord(true);
initComponents();
}
public void readFromFile(String date) throws FileNotFoundException, IOException {
//String fileName = Spark.getSparkUserHome()+File.separator+"broadcast_history."+date+".txt";
String fileLocation=Spark.getSparkUserHome()+File.separator+"user"+File.separator+SparkManager.getSessionManager().getUsername()+"@"+SparkManager.getSessionManager().getServerAddress()+File.separator+"transcripts"+File.separator+"broadcast_history."+date+".txt";
String fileLocation = Spark.getSparkUserHome() + File.separator + "user" + File.separator + SparkManager.getSessionManager().getUsername() + "@" + SparkManager.getSessionManager().getServerAddress() + File.separator + "transcripts" + File.separator + "broadcast_history." + date + ".txt";
File myfile = new File(fileLocation);
FileInputStream fis = new FileInputStream(myfile);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line = null;
String line;
while ((line = br.readLine()) != null) {
BroadcastHistoryArea.append(line+"\n");
}
br.close();
BroadcastHistoryArea.append(line + "\n");
}
br.close();
}
private void initComponents() {

View File

@ -239,14 +239,8 @@ public class ContactInfoWindow extends JPanel {
//If user is offline or away, try to see last activity
try {
Jid client = null;
if (!status.equals(Res.getString("offline"))) {
//If user is away (not offline), last activity request is sent to client
client = contactItem.getPresence().getFrom();
} else {
client = contactItem.getJid();
}
//If user is away (not offline), last activity request is sent to client
Jid client = status.equals(Res.getString("offline")) ? contactItem.getJid() : contactItem.getPresence().getFrom();
LastActivity activity = LastActivityManager.getInstanceFor( SparkManager.getConnection() ).getLastActivity(client);
long idleTime = (activity.getIdleTime() * 1000);

View File

@ -660,28 +660,25 @@ public class RosterDialog implements ActionListener {
nicknameField.setText(nickname);
}
ContactGroup contactGroup = contactList.getContactGroup(group);
boolean isSharedGroup = contactGroup != null
&& contactGroup.isSharedGroup();
ContactGroup contactGroup = contactList.getContactGroup(group);
boolean isSharedGroup = contactGroup != null && contactGroup.isSharedGroup();
if (isSharedGroup) {
errorMessage = Res
.getString("message.cannot.add.contact.to.shared.group");
} else if (!ModelUtil.hasLength(contact)) {
errorMessage = Res.getString("message.specify.contact.jid");
} else if (!XmppStringUtils.parseBareJid(contact).contains("@")) {
errorMessage = Res.getString("message.invalid.jid.error");
} else if (!ModelUtil.hasLength(group)) {
errorMessage = Res.getString("message.specify.group");
} else if (ModelUtil.hasLength(contact) && ModelUtil.hasLength(group)
&& !isSharedGroup) {
addEntry();
dialog.setVisible(false);
} else {
if (isSharedGroup) {
errorMessage = Res.getString("message.cannot.add.contact.to.shared.group");
} else if (!ModelUtil.hasLength(contact)) {
errorMessage = Res.getString("message.specify.contact.jid");
} else if (!XmppStringUtils.parseBareJid(contact).contains("@")) {
errorMessage = Res.getString("message.invalid.jid.error");
} else if (!ModelUtil.hasLength(group)) {
errorMessage = Res.getString("message.specify.group");
}
JOptionPane.showMessageDialog(dialog, errorMessage,
Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
}
if (ModelUtil.hasLength(contact) && ModelUtil.hasLength(group) && !isSharedGroup) {
addEntry();
dialog.setVisible(false);
} else {
JOptionPane.showMessageDialog(dialog, errorMessage,Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
}
}
static class AccountItem extends JPanel {

View File

@ -50,7 +50,7 @@ import org.jivesoftware.spark.util.ResourceUtils;
public class AnswerFormDialog {
private static final long serialVersionUID = 3637412110943006392L;
private JDialog dialog = null;
private JDialog dialog;
private JPanel centerpanel;
HashMap<String, JComponent> _map = new HashMap<>();

View File

@ -65,8 +65,7 @@ public class DataFormDialog extends JPanel {
private static final long serialVersionUID = -1536217028590811636L;
private final Map<String,JComponent> valueMap = new HashMap<>();
private int row = 0;
JDialog dialog = null;
JDialog dialog;
public DataFormDialog(JFrame parent, final MultiUserChat chat, final Form submitForm) {
dialog = new JDialog(parent, true);

View File

@ -81,7 +81,7 @@ final class InvitationDialog extends JPanel {
private JDialog dlg;
public InvitationDialog(boolean adhoc) {
JComponent roomsField = new JTextField();
JComponent roomsField;
if (adhoc) {
roomsField = new JTextField();
textRoomsField = (JTextField) roomsField;
@ -91,7 +91,7 @@ final class InvitationDialog extends JPanel {
comboRoomsField.setEditable(true);
comboRoomsField.addActionListener( e -> {
// get selected bookmark and persist it:
BookmarkedConference bookmarkedConf = null;
BookmarkedConference bookmarkedConf;
Object bookmarkedConfItem = comboRoomsField.getSelectedItem();
if (bookmarkedConfItem instanceof ConferenceItem) {
bookmarkedConf = ((ConferenceItem) bookmarkedConfItem).getBookmarkedConf();

View File

@ -159,57 +159,53 @@ public class UriManager {
* @throws Exception
*/
public void handleRoster(URI uri) throws Exception {
// xmpp:romeo@montague.net?roster
// xmpp:romeo@montague.net?roster;name=Romeo%20Montague
// xmpp:romeo@montague.net?roster;group=Friends
// xmpp:romeo@montague.net?roster;name=Romeo%20Montague;group=Friends
BareJid jid;
try {
jid = JidCreate.bareFrom(retrieveJID(uri));
} catch (XmppStringprepException e) {
throw new IllegalStateException(e);
}
// xmpp:romeo@montague.net?roster
// xmpp:romeo@montague.net?roster;name=Romeo%20Montague
// xmpp:romeo@montague.net?roster;group=Friends
// xmpp:romeo@montague.net?roster;name=Romeo%20Montague;group=Friends
BareJid jid;
try {
jid = JidCreate.bareFrom(retrieveJID(uri));
} catch (XmppStringprepException e) {
throw new IllegalStateException(e);
}
String name = "";
String query = uri.getQuery();
if (query.contains("name=")) {
StringBuilder buf = new StringBuilder();
int x = query.indexOf("name=") + 5;
while (x < query.length() && query.charAt(x) != ';') {
buf.append(query.charAt(x));
x++;
}
}
String group = "";
if (query.contains("group=")) {
StringBuilder buf = new StringBuilder();
int x = query.indexOf("group=") + 6;
while (x < query.length() && query.charAt(x) != ';') {
buf.append(query.charAt(x));
x++;
}
}
String name = "";
String query = uri.getQuery();
if (query.contains("name=")) {
StringBuilder buf = new StringBuilder();
int x = query.indexOf("name=") + 5;
while (x < query.length() && query.charAt(x) != ';') {
buf.append(query.charAt(x));
x++;
}
}
String group = "";
if (query.contains("group=")) {
StringBuilder buf = new StringBuilder();
int x = query.indexOf("group=") + 6;
while (x < query.length() && query.charAt(x) != ';') {
buf.append(query.charAt(x));
x++;
}
}
Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
RosterEntry userEntry = roster.getEntry(jid);
Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
RosterEntry userEntry = roster.getEntry(jid);
roster.createEntry(jid, name, new String[] { group });
roster.createEntry(jid, name, new String[]{group});
RosterGroup rosterGroup = roster.getGroup(group);
if (rosterGroup == null) {
rosterGroup = roster.createGroup(group);
}
if (userEntry == null) {
roster.createEntry(jid, name, new String[] { group });
userEntry = roster.getEntry(jid);
} else {
userEntry.setName(name);
rosterGroup.addEntry(userEntry);
}
userEntry = roster.getEntry(jid);
RosterGroup rosterGroup = roster.getGroup(group);
if (rosterGroup == null) {
rosterGroup = roster.createGroup(group);
}
if (userEntry == null) {
roster.createEntry(jid, name, new String[]{group});
} else {
userEntry.setName(name);
rosterGroup.addEntry(userEntry);
}
}
/**

View File

@ -758,7 +758,7 @@ public class Base64 {
java.io.ByteArrayInputStream bais = null;
java.io.ObjectInputStream ois = null;
Object obj = null;
Object obj;
try {
bais = new java.io.ByteArrayInputStream(objBytes);

View File

@ -127,7 +127,7 @@ public class SparkToaster {
// Flag that indicate if use alwaysOnTop or not.
// method always on top start only SINCE JDK 5 !
boolean useAlwaysOnTop = true;
boolean useAlwaysOnTop;
private String title;

View File

@ -29,7 +29,7 @@ public class Emoticon {
private String imageName;
private String emoticonName;
private File emoticonDirectory;
private List<String> equivalants = new ArrayList<>();
private List<String> equivalants;
/**

View File

@ -50,7 +50,7 @@ public class GatewayTabItem extends CollapsiblePane implements GatewayItem {
private RolloverButton _signInOut = new RolloverButton();
private RolloverButton _registerButton = new RolloverButton();
private JCheckBox _autoJoin = new JCheckBox();
private boolean _transportRegistered = false;
private boolean _transportRegistered;
private RolloverButton _autoJoinButton = new RolloverButton();

View File

@ -46,13 +46,13 @@ public class LinuxIdleTime implements IdleTime {
@Override
public long getIdleTimeMillis() {
X11.Window win = null;
X11.Window win;
Xss.XScreenSaverInfo info = null;
X11.Display dpy = null;
final X11 x11 = X11.INSTANCE;
final Xss xss = Xss.INSTANCE;
long idlemillis = 0L;
long idlemillis;
try {
dpy = x11.XOpenDisplay(null);
win = x11.XDefaultRootWindow(dpy);
@ -61,13 +61,8 @@ public class LinuxIdleTime implements IdleTime {
idlemillis = info.idle.longValue();
} finally {
if (info != null)
x11.XFree(info.getPointer());
info = null;
if (dpy != null)
x11.XCloseDisplay(dpy);
dpy = null;
if (info != null) x11.XFree(info.getPointer());
if (dpy != null) x11.XCloseDisplay(dpy);
}
return idlemillis;
}

View File

@ -54,7 +54,7 @@ public class PrivacyManager {
private PrivacyListManager privacyManager;
private PrivacyPresenceHandler _presenceHandler = new PrivacyPresenceHandler();
private Set<SparkPrivacyListListener> _listListeners = new HashSet<>();
private boolean _active = false;
private boolean _active;
private SparkPrivacyList previousActiveList;
/**

View File

@ -32,9 +32,9 @@ public class SparkPrivacyList {
/**
* List name will be used to identify PrivacyList
*/
private String _listName = "";
private boolean _isActive = false;
private boolean _isDefault = false;
private String _listName;
private boolean _isActive;
private boolean _isDefault;
private List<PrivacyItem> _privacyItems = new LinkedList<>();
private PrivacyList _myPrivacyList;
private final Set<SparkPrivacyItemListener> _listeners = new HashSet<>();

View File

@ -63,8 +63,8 @@ public class HistoryTranscript extends SwingWorker {
private JButton pageLeft = new JButton("<");
private JButton pageRight = new JButton(">");
private BareJid jid = null;
private SimpleDateFormat notificationDateFormatter = null;
private SimpleDateFormat messageDateFormatter = null;
private SimpleDateFormat notificationDateFormatter;
private SimpleDateFormat messageDateFormatter;
private final AtomicBoolean isInitialized = new AtomicBoolean(false);
private LocalPreferences pref = SettingsManager.getLocalPreferences();
@ -400,7 +400,7 @@ public class HistoryTranscript extends SwingWorker {
cal.setTime(oldDate);
Date newDate;
ChatTranscript history = new ChatTranscript();
ChatTranscript history;
boolean handled = true;
for(int i = startValue; i != endValue; i += iteratorValue){

View File

@ -72,8 +72,8 @@ import java.util.concurrent.LinkedBlockingQueue;
public class VCardManager {
private VCard personalVCard;
private transient byte[] personalVCardAvatar = null; // lazy loaded cache of avatar binary data.
private transient String personalVCardHash = null; // lazy loaded cache of avatar hash.
private transient byte[] personalVCardAvatar; // lazy loaded cache of avatar binary data.
private transient String personalVCardHash; // lazy loaded cache of avatar hash.
private Map<BareJid, VCard> vcards = Collections.synchronizedMap( new HashMap<>());

View File

@ -50,7 +50,7 @@ import java.security.cert.X509Certificate;
*/
public class EasyX509TrustManager implements X509TrustManager {
private X509TrustManager standardTrustManager = null;
private X509TrustManager standardTrustManager;
/**
* Log object for this class.

View File

@ -133,7 +133,7 @@ final public class FormUtils {
public static String getPushedURL(String body) {
String urlToPush = null;
String urlToPush;
int index = body.indexOf("]");
urlToPush = body.substring(index + 1);
int index2 = urlToPush.indexOf("http://");

View File

@ -52,7 +52,7 @@ public class WorkgroupDataForm extends JPanel {
private final Map valueMap = new HashMap<String, JComponent>();
private int row = 5;
private Form searchForm;
private Map presetVariables = new HashMap();
private Map presetVariables;
private List<String> requiredList = new ArrayList<String>();
private EnterListener listener;
@ -173,13 +173,8 @@ public class WorkgroupDataForm extends JPanel {
}
else if (o instanceof JComboBox) {
Object v = ((JComboBox)o).getSelectedItem();
String value = "";
if (v instanceof FormField.Option) {
value = ((FormField.Option)v).getValue();
}
else {
value = (String)v;
}
String value = (v instanceof FormField.Option) ? ((FormField.Option) v).getValue() : (String) v;
List<String> list = new ArrayList<String>();
list.add(value);
if (list.size() > 0) {

View File

@ -387,7 +387,7 @@ public class Workpane {
room.getSplitPane().setRightComponent(tabbedPane);
Form form = null;
Form form;
try {
form = FastpathPlugin.getWorkgroup().getWorkgroupForm();
}
@ -801,13 +801,6 @@ public class Workpane {
try {
if (FastpathPlugin.getAgentSession().isOnline()) {
Presence.Mode mode = presence.getMode();
if (status == null) {
status = "";
}
if (mode == null) {
mode = Presence.Mode.available;
}
FastpathPlugin.getAgentSession().setStatus(presence.getMode(), status);
}
}

View File

@ -52,7 +52,7 @@ public final class WorkgroupRosterTree extends JPanel {
private final JiveTreeNode rootNode = new JiveTreeNode(FpRes.getString("title.contact.list"));
private final Tree rosterTree;
private final Map<JiveTreeNode, EntityBareJid> addressMap = new HashMap<>();
private boolean showUnavailableAgents = true;
private boolean showUnavailableAgents;
private final List workgroupList;
private Collection<? extends BareJid> exclusionList;

View File

@ -188,11 +188,6 @@ public final class AgentConversations extends JPanel implements ChangeListener {
EntityBareJid agentJID = presence.getFrom().asEntityBareJidOrThrow();
AgentStatus agentStatus = presence.getExtension("agent-status", "http://jabber.org/protocol/workgroup");
String status = presence.getStatus();
if (status == null) {
status = "Available";
}
if (agentStatus != null) {
List list = agentStatus.getCurrentChats();
@ -224,12 +219,9 @@ public final class AgentConversations extends JPanel implements ChangeListener {
}
calculateNumberOfChats(agentRoster);
}
});
}
};
agentWorker.start();
}
}
@ -311,7 +303,7 @@ public final class AgentConversations extends JPanel implements ChangeListener {
if (muc.isJoined()) {
// Try and remove myself as an owner if I am one.
Collection owners = null;
Collection owners;
try {
owners = muc.getOwners();
}

View File

@ -172,11 +172,6 @@ public final class CurrentActivity extends JPanel {
BareJid agentJID = presence.getFrom().asBareJid();
AgentStatus agentStatus = presence.getExtension("agent-status", "http://jabber.org/protocol/workgroup");
String status = presence.getStatus();
if (status == null) {
status = "Available";
}
if (agentStatus != null) {
List<ChatInfo> list = agentStatus.getCurrentChats();
@ -261,7 +256,7 @@ public final class CurrentActivity extends JPanel {
if (muc.isJoined()) {
// Try and remove myself as an owner if I am one.
Collection owners = null;
Collection owners;
try {
owners = muc.getOwners();
}

View File

@ -253,7 +253,7 @@ public class InvitationPane {
private void removeOwner(MultiUserChat muc) {
if (muc.isJoined()) {
// Try and remove myself as an owner if I am one.
Collection owners = null;
Collection owners;
try {
owners = muc.getOwners();
}

View File

@ -316,7 +316,7 @@ public class UserInvitationPane {
private void removeOwner(MultiUserChat muc) {
if (muc.isJoined()) {
// Try and remove myself as an owner if I am one.
Collection<Affiliate> owners = null;
Collection<Affiliate> owners;
try {
owners = muc.getOwners();
}

View File

@ -90,7 +90,7 @@ public class ChatSearch implements Searchable {
List<String> workgroupStrings = JidUtil.toStringList(workgroups);
filledForm.setAnswer("workgroups", workgroupStrings);
ReportedData reportedData = null;
ReportedData reportedData;
try {
reportedData = agentSession.searchTranscripts(filledForm);
for ( final ReportedData.Row row : reportedData.getRows() ) {

View File

@ -110,7 +110,6 @@ public class SparkFileUploadPlugin implements Plugin, ChatRoomListener, GlobalMe
{
ChatRoomDecorator decorator = decorators.remove(roomId);
decorator.finished();
decorator = null;
}
}

View File

@ -265,7 +265,6 @@ public class SparkMeetPlugin implements Plugin, ChatRoomListener, GlobalMessageL
{
ChatRoomDecorator decorator = decorators.remove(roomId);
decorator.finished();
decorator = null;
}
if (electronThread != null)
@ -410,7 +409,7 @@ public class SparkMeetPlugin implements Plugin, ChatRoomListener, GlobalMessageL
{
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
byte[] bytesIn = new byte[4096];
int read = 0;
int read;
while ((read = zipIn.read(bytesIn)) != -1)
{

View File

@ -106,7 +106,7 @@ public class SparkToaster {
// Flag that indicate if use alwaysOnTop or not.
// method always on top start only SINCE JDK 5 !
boolean useAlwaysOnTop = true;
boolean useAlwaysOnTop;
private String title;