SPARK-2356: Guard against missing resources

When a resource is missing, Spark should log and return null, rather than throw an unchecked exception.
This commit is contained in:
Guus der Kinderen
2025-10-09 16:33:17 +02:00
parent 834a6fe8a7
commit 0734d54743
12 changed files with 52 additions and 28 deletions

View File

@ -15,6 +15,8 @@
*/
package org.jivesoftware.resource;
import org.jivesoftware.spark.util.log.Log;
import javax.swing.ImageIcon;
import java.io.IOException;
@ -55,9 +57,14 @@ public class ConfigurationRes {
}
public static ImageIcon getImageIcon(String imageName) {
final String iconURI = getString(imageName);
final URL imageURL = cl.getResource(iconURI);
return new ImageIcon(imageURL);
try {
final String iconURI = getString(imageName);
final URL imageURL = cl.getResource(iconURI);
return new ImageIcon(imageURL);
} catch (Throwable t) {
Log.warning(imageName + " not found.", t);
}
return null;
}
public static URL getURL(String propertyName) {

View File

@ -208,8 +208,8 @@ public class Default {
cache.put(imageName, icon);
return icon;
}
catch (Exception ex) {
Log.debug(imageName + " not found.");
catch (Throwable t) {
Log.warning(imageName + " not found.", t);
}
return null;
}

View File

@ -15,6 +15,8 @@
*/
package org.jivesoftware.resource;
import org.jivesoftware.spark.util.log.Log;
import javax.swing.ImageIcon;
import java.io.IOException;
@ -52,9 +54,14 @@ public class SoundsRes {
}
public static ImageIcon getImageIcon(String imageName) {
final String iconURI = getString(imageName);
final URL imageURL = cl.getResource(iconURI);
return new ImageIcon(imageURL);
try {
final String iconURI = getString(imageName);
final URL imageURL = cl.getResource(iconURI);
return new ImageIcon(imageURL);
} catch (Throwable t) {
Log.warning(imageName + " not found.", t);
}
return null;
}
public static URL getURL(String propertyName) {

View File

@ -355,8 +355,8 @@ public class SparkRes {
try {
final URL imageURL = getURL(imageName);
return new ImageIcon(imageURL);
} catch (Exception ex) {
Log.error(imageName + " not found.");
} catch (Throwable t) {
Log.warning(imageName + " not found.", t);
}
return null;
}

View File

@ -16,6 +16,7 @@
package org.jivesoftware.fastpath.resources;
import org.jivesoftware.fastpath.FastpathPlugin;
import org.jivesoftware.spark.util.log.Log;
import javax.swing.ImageIcon;
import javax.swing.JEditorPane;
@ -267,8 +268,8 @@ public class FastpathRes {
final URL imageURL = cl.getResource(iconURI);
return new ImageIcon(imageURL);
}
catch (Exception ex) {
System.out.println(imageName + " not found.");
catch (Throwable t) {
Log.warning(imageName + " not found.", t);
}
return null;
}

View File

@ -206,8 +206,9 @@ public class IncomingCallUI extends JPanel {
avatarLabel.validate();
avatarLabel.repaint();
}
catch (Exception e) {
catch (Throwable t) {
// no issue
Log.warning("Unable to generate image from avatar", t);
}
}

View File

@ -20,6 +20,8 @@ import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.net.URL;
import org.jivesoftware.spark.util.log.Log;
/**
* Use for Phone Res Internationalization.
*
@ -48,8 +50,8 @@ public class JinglePhoneRes {
final URL imageURL = JinglePhoneRes.cl.getResource(iconURI);
return new ImageIcon(imageURL);
}
catch (Exception ex) {
System.out.println(imageName + " not found.");
catch (Throwable t) {
Log.warning(imageName + " not found.", t);
}
return null;
}

View File

@ -45,9 +45,14 @@ public class OTRResources {
* @return
*/
public static ImageIcon getIcon(String fileName) {
final ClassLoader cl = OTRResources.class.getClassLoader();
ImageIcon icon = new ImageIcon(cl.getResource(fileName));
return icon;
try {
final ClassLoader cl = OTRResources.class.getClassLoader();
ImageIcon icon = new ImageIcon(cl.getResource(fileName));
return icon;
} catch (Throwable t) {
Log.warning(fileName + " not found.", t);
}
return null;
}
/**

View File

@ -1,6 +1,7 @@
package org.jivesoftware.game.reversi;
import org.jivesoftware.resource.UTF8Control;
import org.jivesoftware.spark.util.log.Log;
import java.net.URL;
import java.util.PropertyResourceBundle;
@ -42,9 +43,9 @@ public class ReversiRes {
final URL imageURL = ReversiRes.cl.getResource(iconURI);
return new ImageIcon(imageURL);
}
catch (Exception ex) {
System.out.println(imageName + " not found.");
}
catch (Throwable t) {
Log.warning(imageName + " not found.", t);
}
return null;
}

View File

@ -58,8 +58,8 @@ public class PhoneRes {
final URL imageURL = cl.getResource(iconURI);
return new ImageIcon(imageURL);
}
catch (Exception ex) {
System.out.println(imageName + " not found.");
catch (Throwable t) {
Log.warn(imageName + " not found.", t);
}
return null;
}
@ -79,4 +79,4 @@ public class PhoneRes {
}
return null;
}
}
}

View File

@ -220,8 +220,8 @@ public class IncomingCallUI extends JPanel {
avatarLabel.validate();
avatarLabel.repaint();
}
catch (Exception e) {
// no issue
catch (Throwable t) {
Log.warning("Unable to generate image from avatar", t);
}
}

View File

@ -203,8 +203,8 @@ public class OutgoingCallUI extends JPanel {
avatarLabel.validate();
avatarLabel.repaint();
}
catch (Exception e) {
// no issue
catch (Throwable t) {
Log.warning("Unable to generate image from avatar", t);
}
}