Skip to content

Commit 8313e43

Browse files
committed
SPARK-2360: Isolate bugs, log improvements
There is a slew of minor issues, such as operating on non-existing images, that throw unchecked exceptions and break the application badly. To isolate these occurrences, exception handling can be put in place, with some logging being generated. That won’t solve the underlying issue, but it should limit the impact of these issues.
1 parent 05b8e82 commit 8313e43

File tree

12 files changed

+243
-202
lines changed

12 files changed

+243
-202
lines changed

core/src/main/java/org/jivesoftware/spark/ui/ContactInfoWindow.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ public void customizeUI(ContactItem contactItem) {
303303
}
304304
avatarLabel.setBorder(BorderFactory.createLineBorder(Color.lightGray, 1, true));
305305
}
306-
catch (MalformedURLException e) {
307-
Log.error(e);
306+
catch (Exception e) {
307+
Log.warning("Unable to update avatar in contact info window", e);
308308
}
309309

310310
// Get VCard from memory (if available)

core/src/main/java/org/jivesoftware/spark/ui/ContactItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ public void updateAvatarInSideIcon() {
601601
setSideIcon(icon);
602602
}
603603
}
604-
} catch (MalformedURLException e) {
605-
Log.error(e);
604+
} catch (Exception e) {
605+
Log.warning("Unable to update avatar in side icon", e);
606606
}
607607
}
608608

core/src/main/java/org/jivesoftware/spark/ui/VCardPanel.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,15 @@ public VCardPanel(final BareJid jid) {
7777
add(avatarImage, new GridBagConstraints(0, 0, 1, 3, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 0), 0, 0));
7878
buildAvatarHover();
7979

80-
Image aImage = SparkRes.getImageIcon(SparkRes.BLANK_24x24).getImage();
81-
aImage = aImage.getScaledInstance(-1, 64, Image.SCALE_SMOOTH);
82-
ImageIcon ico = new ImageIcon(aImage);
83-
84-
avatarImage.setIcon(ico);
85-
80+
try {
81+
Image aImage = SparkRes.getImageIcon(SparkRes.BLANK_24x24).getImage();
82+
aImage = aImage.getScaledInstance(-1, 64, Image.SCALE_SMOOTH);
83+
ImageIcon ico = new ImageIcon(aImage);
84+
85+
avatarImage.setIcon(ico);
86+
} catch (Exception e) {
87+
Log.error("Unable to process image in vcard!", e);
88+
}
8689

8790
VCard vcard = SparkManager.getVCardManager().getVCard(jid);
8891

@@ -105,7 +108,7 @@ public VCardPanel(final BareJid jid) {
105108
icon = new ImageIcon(newImage);
106109
}
107110
catch (Exception e) {
108-
Log.error(e);
111+
Log.error("Unable to fetch image in vcard!", e);
109112
}
110113
}
111114
else {
@@ -153,7 +156,7 @@ private void showAvatarBig(boolean bool, VCard vcard) {
153156
icon = new ImageIcon(newImage);
154157

155158
} catch (Exception e1) {
156-
Log.error(e1);
159+
Log.error("Unable to process vcard avatar", e1);
157160
}
158161

159162
} else {

core/src/main/java/org/jivesoftware/spark/ui/VCardViewer.java

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -75,58 +75,61 @@ public VCardViewer(final BareJid jid) {
7575
avatarImage = new JLabel();
7676
add(avatarImage, new GridBagConstraints(0, 0, 1, 3, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 0), 0, 0));
7777

78-
79-
Image aImage = SparkRes.getImageIcon(SparkRes.BLANK_24x24).getImage();
80-
aImage = aImage.getScaledInstance(-1, 64, Image.SCALE_SMOOTH);
81-
ImageIcon ico = new ImageIcon(aImage);
82-
83-
avatarImage.setIcon(ico);
84-
85-
final SwingWorker vcardLoader = new SwingWorker() {
86-
VCard vcard = null;
87-
88-
@Override
89-
public Object construct() {
90-
vcard = SparkManager.getVCardManager().getVCard(jid);
91-
return vcard;
92-
}
93-
94-
@Override
95-
public void finished() {
96-
if (vcard == null) {
97-
// Do nothing.
98-
return;
78+
try {
79+
Image aImage = SparkRes.getImageIcon(SparkRes.BLANK_24x24).getImage();
80+
aImage = aImage.getScaledInstance(-1, 64, Image.SCALE_SMOOTH);
81+
ImageIcon ico = new ImageIcon(aImage);
82+
83+
avatarImage.setIcon(ico);
84+
85+
final SwingWorker vcardLoader = new SwingWorker()
86+
{
87+
VCard vcard = null;
88+
89+
@Override
90+
public Object construct()
91+
{
92+
vcard = SparkManager.getVCardManager().getVCard(jid);
93+
return vcard;
9994
}
10095

101-
ImageIcon icon = null;
96+
@Override
97+
public void finished()
98+
{
99+
if (vcard == null) {
100+
// Do nothing.
101+
return;
102+
}
102103

103-
byte[] bytes = vcard.getAvatar();
104-
if (bytes != null && bytes.length > 0) {
105-
try {
106-
icon = new ImageIcon(bytes);
107-
Image aImage = icon.getImage();
108-
aImage = aImage.getScaledInstance(-1, 48, Image.SCALE_SMOOTH);
109-
icon = new ImageIcon(aImage);
104+
ImageIcon icon = null;
105+
106+
byte[] bytes = vcard.getAvatar();
107+
if (bytes != null && bytes.length > 0) {
108+
try {
109+
icon = new ImageIcon(bytes);
110+
Image aImage = icon.getImage();
111+
aImage = aImage.getScaledInstance(-1, 48, Image.SCALE_SMOOTH);
112+
icon = new ImageIcon(aImage);
113+
} catch (Exception e) {
114+
Log.warning("Unable to get scaled avatar from vcard.", e);
115+
}
116+
} else {
117+
icon = SparkRes.getImageIcon(SparkRes.DEFAULT_AVATAR_32x32_IMAGE);
110118
}
111-
catch (Exception e) {
112-
Log.error(e);
119+
120+
if (icon != null && icon.getIconWidth() > 0) {
121+
avatarImage.setIcon(icon);
122+
avatarImage.setBorder(BorderFactory.createLineBorder(Color.lightGray, 1, true));
113123
}
114-
}
115-
else {
116-
icon = SparkRes.getImageIcon(SparkRes.DEFAULT_AVATAR_32x32_IMAGE);
117-
}
118124

119-
if (icon != null && icon.getIconWidth() > 0) {
120-
avatarImage.setIcon(icon);
121-
avatarImage.setBorder(BorderFactory.createLineBorder(Color.lightGray, 1, true));
125+
vcard.setJabberId(jid);
126+
buildUI(vcard);
122127
}
123-
124-
vcard.setJabberId(jid);
125-
buildUI(vcard);
126-
}
127-
};
128-
129-
vcardLoader.start();
128+
};
129+
vcardLoader.start();
130+
} catch (Exception e) {
131+
Log.warning("Unable to get avatar from vcard.", e);
132+
}
130133
}
131134

132135
private void buildUI(final VCard vcard) {

core/src/main/java/org/jivesoftware/spark/ui/conferences/ConferenceRoomBrowser.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -920,26 +920,37 @@ public Object construct() {
920920
}
921921

922922
if (isbookmark && ispassword) {
923-
Image img = ImageCombiner.combine(bookmarkicon, passwordicon);
924-
iconLabel.setIcon(new ImageIcon(img));
923+
try {
924+
Image img = ImageCombiner.combine(bookmarkicon, passwordicon);
925+
if (img != null) {
926+
iconLabel.setIcon(new ImageIcon(img));
927+
}
928+
} catch (Exception e) {
929+
Log.warning("Unable to set icon for bookmarked & password-protected room " + jid, e);
930+
}
925931
} else if (isbookmark) {
926932
iconLabel.setIcon(bookmarkicon);
927933
} else if (ispassword) {
928-
Image img = ImageCombiner.returnTransparentImage(
929-
passwordicon.getIconWidth(), passwordicon.getIconHeight());
930-
931-
Image combined = ImageCombiner.combine(new ImageIcon(img),
932-
passwordicon);
933-
934-
iconLabel.setIcon(new ImageIcon(combined));
934+
try {
935+
if (passwordicon != null) {
936+
Image img = ImageCombiner.returnTransparentImage(
937+
passwordicon.getIconWidth(), passwordicon.getIconHeight());
938+
Image combined = ImageCombiner.combine(new ImageIcon(img), passwordicon);
939+
if (combined != null) {
940+
iconLabel.setIcon(new ImageIcon(combined));
941+
}
942+
}
943+
} catch (Exception e) {
944+
Log.warning("Unable to set icon for password-protected room " + jid, e);
945+
}
935946
}
936947

937948
String occupants = Integer.toString(numberOfOccupants);
938949
if (numberOfOccupants == -1) {
939950
occupants = "n/a";
940951
}
941952

942-
return new Object[] { iconLabel, roomName.toString(), jid.getLocalpart().toString(), occupants };
953+
return new Object[] { iconLabel, roomName == null ? jid.getLocalpart().toString() : roomName.toString(), jid.getLocalpart().toString(), occupants };
943954
}
944955

945956
@Override

core/src/main/java/org/jivesoftware/spark/ui/status/CustomMessages.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,16 @@ public CustomStatus() {
345345
// Add Types
346346
for (StatusItem statusItem : statusBar.getStatusList()) {
347347
if (!PresenceManager.isOnPhone(statusItem.getPresence())) {
348-
ImageIcon icon = (ImageIcon) statusItem.getIcon();
348+
try {
349+
ImageIcon icon = (ImageIcon) statusItem.getIcon();
349350

350-
ImageIcon newIcon = new ImageIcon(icon.getImage());
351-
newIcon.setDescription(statusItem.getText());
351+
ImageIcon newIcon = new ImageIcon(icon.getImage());
352+
newIcon.setDescription(statusItem.getText());
352353

353-
typeBox.addItem(newIcon);
354+
typeBox.addItem(newIcon);
355+
} catch (Exception e) {
356+
Log.warning("Unable to update icon on custom status bar", e);
357+
}
354358
}
355359
}
356360

core/src/main/java/org/jivesoftware/spark/ui/status/StatusBar.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,23 @@ public void doRun() {
165165
}
166166

167167
public void setAvatar(Icon icon) {
168-
if (icon == null) {
169-
imageLabel.setIcon(null);
170-
} else {
171-
Image image = ImageCombiner.iconToImage(icon);
172-
if (icon.getIconHeight() > 64 || icon.getIconWidth() > 64) {
173-
imageLabel.setIcon(new ImageIcon(image.getScaledInstance(-1, 64, Image.SCALE_SMOOTH)));
168+
try {
169+
if (icon == null) {
170+
imageLabel.setIcon(null);
174171
} else {
175-
imageLabel.setIcon(icon);
172+
Image image = ImageCombiner.iconToImage(icon);
173+
if (icon.getIconHeight() > 64 || icon.getIconWidth() > 64) {
174+
imageLabel.setIcon(new ImageIcon(image.getScaledInstance(-1, 64, Image.SCALE_SMOOTH)));
175+
} else {
176+
imageLabel.setIcon(icon);
177+
}
176178
}
179+
imageLabel.setBorder(null);
180+
revalidate();
181+
allowProfileEditing();
182+
} catch (Exception e) {
183+
Log.warning("Unable to set avatar", e);
177184
}
178-
imageLabel.setBorder(null);
179-
revalidate();
180-
allowProfileEditing();
181185
}
182186

183187
public CommandPanel getCommandPanel() {
@@ -506,7 +510,7 @@ protected void updateVCardInformation(final VCard vCard) {
506510
imageLabel.validate();
507511
imageLabel.repaint();
508512
} catch (Exception e) {
509-
// no issue
513+
Log.warning("Unable to update vcard viewer with avatar data", e);
510514
}
511515
} else {
512516
imageLabel.setIcon(null);

0 commit comments

Comments
 (0)