From d09964ca3c65a94b0d835b9a2c5f80fe63b5c960 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 24 Aug 2024 21:54:55 +0300 Subject: [PATCH 01/11] SPARK-2337 ContactList.sendMessages(): early return Signed-off-by: Sergey Ponomarev --- .../jivesoftware/spark/ui/ContactList.java | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java b/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java index e62e5212c..a571bda36 100644 --- a/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java +++ b/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java @@ -1705,37 +1705,35 @@ private void clearSelectionList(ContactItem selectedItem) { private void sendMessages(Collection items) { - StringBuilder buf = new StringBuilder(); InputDialog dialog = new InputDialog(); final String messageText = dialog.getInput(Res.getString("title.broadcast.message"), Res.getString("message.enter.broadcast.message"), SparkRes.getImageIcon(SparkRes.BLANK_IMAGE), SparkManager.getMainWindow()); - if (ModelUtil.hasLength(messageText)) { - - final Map broadcastMessages = new HashMap<>(); - for (ContactItem item : items) { - final Message message = new Message(); - message.setTo(item.getJid()); - final Map properties = new HashMap<>(); - properties.put("broadcast", true); - message.addExtension(new JivePropertiesExtension(properties)); - message.setBody(messageText); - if (!broadcastMessages.containsKey(item.getJid().toString())) { - buf.append(item.getDisplayName()).append("\n"); - broadcastMessages.put(item.getJid().toString(), message); - } + if (!ModelUtil.hasLength(messageText)) { + return; + } + StringBuilder buf = new StringBuilder(); + final Map broadcastMessages = new HashMap<>(); + for (ContactItem item : items) { + final Message message = new Message(); + message.setTo(item.getJid()); + final Map properties = new HashMap<>(); + properties.put("broadcast", true); + message.addExtension(new JivePropertiesExtension(properties)); + message.setBody(messageText); + if (!broadcastMessages.containsKey(item.getJid().toString())) { + buf.append(item.getDisplayName()).append('\n'); + broadcastMessages.put(item.getJid().toString(), message); } + } - for (Message message : broadcastMessages.values()) { - try { - SparkManager.getConnection().sendStanza(message); - } catch (SmackException.NotConnectedException | InterruptedException e) { - Log.warning("Unable to send broadcast to " + message.getTo(), e); - } + for (Message message : broadcastMessages.values()) { + try { + SparkManager.getConnection().sendStanza(message); + } catch (SmackException.NotConnectedException | InterruptedException e) { + Log.warning("Unable to send broadcast to " + message.getTo(), e); } - UIManager.put("OptionPane.okButtonText", Res.getString("ok")); - JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.hasbeenbroadcast.to", buf.toString()), Res.getString("title.notification"), JOptionPane.INFORMATION_MESSAGE); } - - + UIManager.put("OptionPane.okButtonText", Res.getString("ok")); + JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.hasbeenbroadcast.to", buf.toString()), Res.getString("title.notification"), JOptionPane.INFORMATION_MESSAGE); } // For plugin use only From 4fa78d8b8ae281db39c07cbd4903ceb0a83956b2 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 24 Aug 2024 22:27:59 +0300 Subject: [PATCH 02/11] SPARK-2337 Rewrite usage of Map.containsKey() to avoid double lookup Signed-off-by: Sergey Ponomarev --- .../java/org/jivesoftware/spark/SoundManager.java | 13 +++++++------ .../java/org/jivesoftware/spark/UserManager.java | 3 +-- .../org/jivesoftware/spark/ui/ContactList.java | 3 +-- .../spark/ui/login/GSSAPIConfiguration.java | 15 +++------------ .../sparkimpl/certificates/OIDTranslator.java | 5 +++-- .../sparkimpl/profile/VCardManager.java | 8 +++++--- 6 files changed, 20 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/spark/SoundManager.java b/core/src/main/java/org/jivesoftware/spark/SoundManager.java index 93363699c..cacac5750 100644 --- a/core/src/main/java/org/jivesoftware/spark/SoundManager.java +++ b/core/src/main/java/org/jivesoftware/spark/SoundManager.java @@ -49,15 +49,16 @@ public SoundManager() { * @return the AudioClip found. If no audio clip was found, returns null. */ public AudioClip getClip(String clip) { - if (!clipMap.containsKey(clip)) { + AudioClip audioClip = clipMap.get(clip); + if (audioClip == null) { // Add new clip - final AudioClip newClip = loadClipForURL(clip); - if (newClip != null) { - clipMap.put(clip, newClip); + audioClip = loadClipForURL(clip); + if (audioClip != null) { + clipMap.put(clip, audioClip); } } - return clipMap.get(clip); + return audioClip; } /** @@ -140,4 +141,4 @@ private AudioClip loadClipForURL(String clipOfURL) { } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/jivesoftware/spark/UserManager.java b/core/src/main/java/org/jivesoftware/spark/UserManager.java index 16e1aaf66..d9a05cfee 100644 --- a/core/src/main/java/org/jivesoftware/spark/UserManager.java +++ b/core/src/main/java/org/jivesoftware/spark/UserManager.java @@ -395,9 +395,8 @@ public void searchContacts(String contact, final JFrame parent) { for (ContactGroup contactGroup : contactList.getContactGroups()) { contactGroup.clearSelection(); for (ContactItem contactItem : contactGroup.getContactItems()) { - if (!contactMap.containsKey(contactItem.getJid().toString())) { + if (contactMap.putIfAbsent(contactItem.getJid().toString(), contactItem) == null) { contacts.add(contactItem); - contactMap.put(contactItem.getJid().toString(), contactItem); } } } diff --git a/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java b/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java index a571bda36..34f06c7e5 100644 --- a/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java +++ b/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java @@ -1719,9 +1719,8 @@ private void sendMessages(Collection items) { properties.put("broadcast", true); message.addExtension(new JivePropertiesExtension(properties)); message.setBody(messageText); - if (!broadcastMessages.containsKey(item.getJid().toString())) { + if (broadcastMessages.putIfAbsent(item.getJid().toString(), message) == null) { buf.append(item.getDisplayName()).append('\n'); - broadcastMessages.put(item.getJid().toString(), message); } } diff --git a/core/src/main/java/org/jivesoftware/spark/ui/login/GSSAPIConfiguration.java b/core/src/main/java/org/jivesoftware/spark/ui/login/GSSAPIConfiguration.java index db6ac92b6..f0178ad3b 100644 --- a/core/src/main/java/org/jivesoftware/spark/ui/login/GSSAPIConfiguration.java +++ b/core/src/main/java/org/jivesoftware/spark/ui/login/GSSAPIConfiguration.java @@ -67,9 +67,9 @@ private void init( boolean config_from_file ) public AppConfigurationEntry[] getAppConfigurationEntry( String name ) { AppConfigurationEntry[] a = new AppConfigurationEntry[ 1 ]; - if ( configs.containsKey( name ) ) + Vector v = configs.get( name ); + if ( v != null ) { - Vector v = configs.get( name ); a = v.toArray( a ); return a; } @@ -81,16 +81,7 @@ public AppConfigurationEntry[] getAppConfigurationEntry( String name ) public boolean putAppConfigurationEntry( String name, String module, AppConfigurationEntry.LoginModuleControlFlag controlFlag, Map options ) { - Vector v; - if ( configs.containsKey( name ) ) - { - v = configs.get( name ); - } - else - { - v = new Vector<>(); - configs.put( name, v ); - } + Vector v = configs.computeIfAbsent(name, k -> new Vector<>()); return v.add( new AppConfigurationEntry( module, controlFlag, options ) ); } diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/certificates/OIDTranslator.java b/core/src/main/java/org/jivesoftware/sparkimpl/certificates/OIDTranslator.java index 89cf8aca1..b6ca69103 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/certificates/OIDTranslator.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/certificates/OIDTranslator.java @@ -104,8 +104,9 @@ public final class OIDTranslator { } public static String getDescription(String oid) { - if (OIDtoDescriptionMap.containsKey(oid)) { - return OIDtoDescriptionMap.get(oid); + String description = OIDtoDescriptionMap.get(oid); + if (description != null) { + return description; } else { Log.warning("Unknown description for Object ID (OID: " + oid + ")"); return Res.getString("cert.unknown.oid"); diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java b/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java index b59679a57..c4ade751c 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java @@ -430,8 +430,9 @@ public VCard getVCard(BareJid jid) { */ public VCard getVCardFromMemory(BareJid jid) { // Check in memory first. - if (vcards.containsKey(jid)) { - return vcards.get(jid); + VCard currentVcard = vcards.get(jid); + if (currentVcard != null) { + return currentVcard; } // if not in memory @@ -540,7 +541,8 @@ public void addVCard(BareJid jid, VCard vcard) { if (vcard == null) return; vcard.setJabberId(jid.toString()); - if (vcards.containsKey(jid) && vcards.get(jid).getError() == null && vcard.getError()!= null) + VCard currentVcard = vcards.get(jid); + if (currentVcard != null && currentVcard.getError() == null && vcard.getError()!= null) { return; From 12721d9cfe275b2a92bb0fbd1b04796623887faf Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 24 Aug 2024 22:42:33 +0300 Subject: [PATCH 03/11] SPARK-2337 VCardManager fix typo Signed-off-by: Sergey Ponomarev --- .../org/jivesoftware/sparkimpl/profile/VCardManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java b/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java index c4ade751c..cff1eead7 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java @@ -449,9 +449,9 @@ public VCard getVCardFromMemory(BareJid jid) { } /** - * Returns the VCard. You should always use useChachedVCards. VCardManager - * will keep the VCards up to date. If you wan't to force a network reload - * of the VCard you can set useChachedVCards to false. That means that you + * Returns the VCard. You should always use useCachedVCards. VCardManager + * will keep the VCards up to date. If you want to force a network reload + * of the VCard you can set useCachedVCards to false. That means that you * have to wait for the vcard response. The method will block until the * result is available or a timeout occurs (like reloadVCard(String jid)). * If there is no response from server this method a dummy vcard with an From 2d7576eeddbab86713e278eb47b96a1a24f6978d Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 24 Aug 2024 22:56:58 +0300 Subject: [PATCH 04/11] SPARK-2337 Use Files.write() to save bytes to file Signed-off-by: Sergey Ponomarev --- .../plugin/history/ConversationHistoryPlugin.java | 5 ++--- .../sparkimpl/plugin/transcripts/ChatTranscripts.java | 8 ++------ .../org/jivesoftware/sparkimpl/profile/VCardManager.java | 5 ++--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/history/ConversationHistoryPlugin.java b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/history/ConversationHistoryPlugin.java index 7a0030c93..4dd0d3d77 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/history/ConversationHistoryPlugin.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/history/ConversationHistoryPlugin.java @@ -37,6 +37,7 @@ import java.awt.event.*; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -285,9 +286,7 @@ public void shutdown() { // Write out new File try { File conFile = new File(transcriptDir, "conversations.xml"); - BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(conFile), StandardCharsets.UTF_8)); - out.write(builder.toString()); - out.close(); + Files.write(conFile.toPath(), builder.toString().getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { Log.error(e); diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/transcripts/ChatTranscripts.java b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/transcripts/ChatTranscripts.java index 7cf75697d..3d95546a5 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/transcripts/ChatTranscripts.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/transcripts/ChatTranscripts.java @@ -28,15 +28,13 @@ import org.jxmpp.jid.impl.JidCreate; import java.io.BufferedReader; -import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.io.RandomAccessFile; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -122,9 +120,7 @@ private static void writeToFile(File transcriptFile, Collection // Write out new File try { transcriptFile.getParentFile().mkdirs(); - BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(transcriptFile), StandardCharsets.UTF_8)); - out.write(builder.toString()); - out.close(); + Files.write(transcriptFile.toPath(), builder.toString().getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { Log.error(e); diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java b/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java index cff1eead7..f9408b8da 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java @@ -56,6 +56,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.time.Duration; import java.time.Instant; import java.util.*; @@ -759,9 +760,7 @@ private void persistVCard(BareJid jid, VCard vcard) { // write xml to file try { - BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(vcardFile), StandardCharsets.UTF_8)); - out.write(xml); - out.close(); + Files.write(vcardFile.toPath(), xml.getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { Log.error(e); From 3799e96b948e18dc073623d39ffbe8bf83f4fbe3 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 31 Aug 2024 11:09:13 +0300 Subject: [PATCH 05/11] SPARK-2337 PluginViewer.getPluginList() return empty list on exception Signed-off-by: Sergey Ponomarev --- .../jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java index 26bb125ae..378b94480 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java @@ -55,6 +55,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -504,10 +505,10 @@ public Collection getPluginList( InputStream response ) catch ( DocumentException | SAXException e ) { Log.error( e ); + return Collections.emptyList(); } List plugins = pluginXML.selectNodes( "/plugins/plugin" ); - for ( Node plugin1 : plugins ) { PublicPlugin publicPlugin = new PublicPlugin(); @@ -605,7 +606,7 @@ public Collection getPluginList( InputStream response ) } catch ( Exception ex ) { - ex.printStackTrace(); + Log.error(ex); } From b4fb685852d4a51172c1a4e68f6485e4f6de8eaf Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 31 Aug 2024 11:25:10 +0300 Subject: [PATCH 06/11] SPARK-2337 JiveInfo.getVersion() avoid null Signed-off-by: Sergey Ponomarev --- .../main/java/org/jivesoftware/sparkimpl/settings/JiveInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/settings/JiveInfo.java b/core/src/main/java/org/jivesoftware/sparkimpl/settings/JiveInfo.java index 0372a551f..ca9aca2fa 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/settings/JiveInfo.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/settings/JiveInfo.java @@ -42,7 +42,7 @@ public static String getVersion() { return version.trim(); } - return null; + return "3.0.3"; // avoid null and return at least some current version } public static String getOS() { From c7a6d8c4f0afe414ed877f60f8b37c0b0e01bdb9 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 31 Aug 2024 11:36:11 +0300 Subject: [PATCH 07/11] SPARK-2337 PluginViewer.getPluginList(): extract sparkVersion var to get it once for all plugins --- .../jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java index 378b94480..cfb62a28e 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java @@ -508,6 +508,7 @@ public Collection getPluginList( InputStream response ) return Collections.emptyList(); } + String sparkVersion = JiveInfo.getVersion(); List plugins = pluginXML.selectNodes( "/plugins/plugin" ); for ( Node plugin1 : plugins ) { @@ -521,8 +522,8 @@ public Collection getPluginList( InputStream response ) try { - String version = plugin.selectSingleNode( "minSparkVersion" ).getText(); - if ( !isGreaterOrEqual( JiveInfo.getVersion(), version ) ) + String minSparkVersion = plugin.selectSingleNode( "minSparkVersion" ).getText(); + if ( !isGreaterOrEqual( sparkVersion, minSparkVersion ) ) { Log.error( "Unable to load plugin " + name + " due to min version incompatibility." ); continue; From 002b2ab1e9ef142cc1f8342a988e4ff23ade3ccb Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 31 Aug 2024 11:37:22 +0300 Subject: [PATCH 08/11] SPARK-2337 PluginViewer.getPluginList(): get plugin name before checking of minSparkVersion --- .../org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java index cfb62a28e..3f294f671 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java @@ -515,11 +515,11 @@ public Collection getPluginList( InputStream response ) PublicPlugin publicPlugin = new PublicPlugin(); String clazz; - String name = null; try { Element plugin = (Element) plugin1; + String name = plugin.selectSingleNode("name").getText(); try { String minSparkVersion = plugin.selectSingleNode( "minSparkVersion" ).getText(); @@ -535,7 +535,6 @@ public Collection getPluginList( InputStream response ) continue; } - name = plugin.selectSingleNode( "name" ).getText(); clazz = plugin.selectSingleNode( "class" ).getText(); publicPlugin.setPluginClass( clazz ); publicPlugin.setName( name ); From b4fa44a6576fc396aa8d8052bbcdaac6855cbc7e Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 31 Aug 2024 11:45:58 +0300 Subject: [PATCH 09/11] SPARK-2337 PluginViewer.getPluginList(): remove redundant exception catch: another one exists for the whole block --- .../sparkimpl/plugin/viewer/PluginViewer.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java index 3f294f671..ae405bdb6 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java @@ -520,18 +520,10 @@ public Collection getPluginList( InputStream response ) Element plugin = (Element) plugin1; String name = plugin.selectSingleNode("name").getText(); - try - { - String minSparkVersion = plugin.selectSingleNode( "minSparkVersion" ).getText(); - if ( !isGreaterOrEqual( sparkVersion, minSparkVersion ) ) - { - Log.error( "Unable to load plugin " + name + " due to min version incompatibility." ); - continue; - } - } - catch ( Exception e ) + String minSparkVersion = plugin.selectSingleNode( "minSparkVersion" ).getText(); + if ( !isGreaterOrEqual( sparkVersion, minSparkVersion ) ) { - Log.error( "Unable to load plugin " + name + " due to no minSparkVersion." ); + Log.error( "Unable to load plugin " + name + " due to min version incompatibility." ); continue; } @@ -608,8 +600,6 @@ public Collection getPluginList( InputStream response ) { Log.error(ex); } - - } return pluginList; } From 73c5a205b304bd0ad16e7a7505789b1df3a1b6b8 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 31 Aug 2024 11:51:15 +0300 Subject: [PATCH 10/11] SPARK-2337 PluginViewer.getPluginList(): merge var declarations with assignment --- .../jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java index ae405bdb6..5cd899741 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java @@ -512,9 +512,6 @@ public Collection getPluginList( InputStream response ) List plugins = pluginXML.selectNodes( "/plugins/plugin" ); for ( Node plugin1 : plugins ) { - PublicPlugin publicPlugin = new PublicPlugin(); - - String clazz; try { Element plugin = (Element) plugin1; @@ -527,7 +524,8 @@ public Collection getPluginList( InputStream response ) continue; } - clazz = plugin.selectSingleNode( "class" ).getText(); + String clazz = plugin.selectSingleNode("class").getText(); + PublicPlugin publicPlugin = new PublicPlugin(); publicPlugin.setPluginClass( clazz ); publicPlugin.setName( name ); From 74dec456b5d65aa3e20aaf71d3155a9472783f6a Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 31 Aug 2024 11:55:46 +0300 Subject: [PATCH 11/11] SPARK-2337 PluginViewer.loadInstalledPlugins() and AutoCompleteDocument.autoComplete(): remove redundant casts --- .../org/jivesoftware/spark/component/AutoCompleteDocument.java | 3 +-- .../org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/spark/component/AutoCompleteDocument.java b/core/src/main/java/org/jivesoftware/spark/component/AutoCompleteDocument.java index 2f3843de0..6bc0fe3cd 100644 --- a/core/src/main/java/org/jivesoftware/spark/component/AutoCompleteDocument.java +++ b/core/src/main/java/org/jivesoftware/spark/component/AutoCompleteDocument.java @@ -54,8 +54,7 @@ public void insertString(int offs, String str, AttributeSet a) } public String autoComplete(String text) { - for (Object aDictionary : dictionary) { - String word = (String) aDictionary; + for (String word : dictionary) { if (word.startsWith(text)) { return word.substring(text.length()); } diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java index 5cd899741..7b4cf543b 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java @@ -135,9 +135,8 @@ private void loadInstalledPlugins() { PluginManager pluginManager = PluginManager.getInstance(); List plugins = pluginManager.getPublicPlugins(); - for ( Object plugin1 : plugins ) + for ( PublicPlugin plugin : plugins ) { - PublicPlugin plugin = (PublicPlugin) plugin1; final SparkPlugUI ui = new SparkPlugUI( plugin ); ui.useLocalIcon(); installedPanel.add( ui );