From 67e10db23d1aecd7a28c68fb19d9ab0e24838e27 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 6 Nov 2018 02:07:40 +0700 Subject: [PATCH] Fix NPE that crashes Swing EDT in Subtitles Panel (when search results includes odd languages) --- .../subtitle/SubtitlePackageCellRenderer.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/net/filebot/ui/subtitle/SubtitlePackageCellRenderer.java b/source/net/filebot/ui/subtitle/SubtitlePackageCellRenderer.java index 33423895..86f4ac1d 100644 --- a/source/net/filebot/ui/subtitle/SubtitlePackageCellRenderer.java +++ b/source/net/filebot/ui/subtitle/SubtitlePackageCellRenderer.java @@ -1,7 +1,6 @@ package net.filebot.ui.subtitle; - import java.awt.Color; import java.awt.Insets; @@ -10,18 +9,17 @@ import javax.swing.JLabel; import javax.swing.JList; import javax.swing.border.CompoundBorder; +import net.filebot.Language; import net.filebot.ResourceManager; import net.filebot.util.ui.AbstractFancyListCellRenderer; import net.filebot.util.ui.DashedSeparator; import net.miginfocom.swing.MigLayout; - class SubtitlePackageCellRenderer extends AbstractFancyListCellRenderer { private final JLabel titleLabel = new JLabel(); private final JLabel languageLabel = new JLabel(); - public SubtitlePackageCellRenderer() { super(new Insets(5, 5, 5, 5)); setHighlightingEnabled(false); @@ -34,7 +32,6 @@ class SubtitlePackageCellRenderer extends AbstractFancyListCellRenderer { setBorder(new CompoundBorder(new DashedSeparator(2, 4, Color.lightGray, Color.white), getBorder())); } - @Override public void configureListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.configureListCellRendererComponent(list, value, index, isSelected, cellHasFocus); @@ -45,8 +42,14 @@ class SubtitlePackageCellRenderer extends AbstractFancyListCellRenderer { titleLabel.setIcon(getIcon(subtitle)); if (languageLabel.isVisible()) { - languageLabel.setText(subtitle.getLanguage().getName()); - languageLabel.setIcon(ResourceManager.getFlagIcon(subtitle.getLanguage().getCode())); + Language language = subtitle.getLanguage(); + if (language != null) { + languageLabel.setText(language.getName()); + languageLabel.setIcon(ResourceManager.getFlagIcon(language.getCode())); + } else { + languageLabel.setText("Unkown Language"); + languageLabel.setIcon(ResourceManager.getFlagIcon("undefined")); + } } titleLabel.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); @@ -56,7 +59,6 @@ class SubtitlePackageCellRenderer extends AbstractFancyListCellRenderer { setBorderPainted(index < list.getModel().getSize() - 1); } - private Icon getIcon(SubtitlePackage subtitle) { switch (subtitle.getDownload().getPhase()) { case PENDING: @@ -75,12 +77,10 @@ class SubtitlePackageCellRenderer extends AbstractFancyListCellRenderer { return null; } - public JLabel getLanguageLabel() { return languageLabel; } - @Override public void validate() { // validate children, yet avoid flickering of the mouse cursor