Ghidra is a software reverse engineering (SRE) framework
GP-1831 - fixed potential NPE for plugin packages that do not specify an icon
dragonmachere2858eca97c6
diff --git a/Ghidra/Framework/Generic/src/main/java/resources/icons/ImageIconWrapper.java b/Ghidra/Framework/Generic/src/main/java/resources/icons/ImageIconWrapper.javaindex a11e0df579..cde7aba68c 100644--- a/Ghidra/Framework/Generic/src/main/java/resources/icons/ImageIconWrapper.java+++ b/Ghidra/Framework/Generic/src/main/java/resources/icons/ImageIconWrapper.java@@ -57,14 +57,13 @@ public class ImageIconWrapper extends ImageIcon implements FileBasedIcon {* @param imageName image reference name*/public ImageIconWrapper(byte[] imageBytes, String imageName) {- if (imageBytes == null) {- throw new NullPointerException("Cannot create an ImageIconWrapper from a null URL");- }+ this.imageBytes = Objects.requireNonNull(imageBytes,+ "Cannot create an ImageIconWrapper from a null bytes");+ this.imageName = imageName;+if (imageBytes.length == 0) {throw new IllegalArgumentException("Cannot create an image from 0 bytes");}- this.imageBytes = imageBytes;- this.imageName = imageName;}/**@@ -84,7 +83,8 @@ public class ImageIconWrapper extends ImageIcon implements FileBasedIcon {* @param icon the icon*/public ImageIconWrapper(Icon icon) {- this.baseIcon = icon;+ this.baseIcon =+ Objects.requireNonNull(icon, "Cannot create an ImageIconWrapper from a null icon");}/**diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginManagerComponent.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginManagerComponent.javaindex 418f5711a9..af96ae3298 100644--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginManagerComponent.java+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginManagerComponent.java@@ -36,6 +36,8 @@ import ghidra.util.layout.VerticalLayout;import resources.ResourceManager;public class PluginManagerComponent extends JPanel implements Scrollable {+ private static final Icon DEFAULT_ICON = ResourceManager.loadImage("images/plasma.png");+private final PluginTool tool;private PluginConfigurationModel model;private List<PluginPackageComponent> packageComponentList = new ArrayList<>();@@ -107,9 +109,9 @@ public class PluginManagerComponent extends JPanel implements Scrollable {throw new AssertException("No checkbox found for " + pluginPackage);}-//==================================================================================================+//=================================================================================================// Inner Classes-//==================================================================================================+//=================================================================================================private class PluginPackageComponent extends JPanel {private final Color BG = Color.white;@@ -132,7 +134,7 @@ public class PluginManagerComponent extends JPanel implements Scrollable {}private void initizalizeCheckBoxSection() {- final JPanel checkboxPanel = new JPanel(new HorizontalLayout(0));+ JPanel checkboxPanel = new JPanel(new HorizontalLayout(0));checkboxPanel.setBackground(BG);checkBox.addActionListener(@@ -146,8 +148,12 @@ public class PluginManagerComponent extends JPanel implements Scrollable {checkboxPanel.add(checkBox);checkboxPanel.add(Box.createHorizontalStrut(10));- final JLabel iconLabel =- new GIconLabel(ResourceManager.getScaledIcon(pluginPackage.getIcon(), 32, 32, 32));+ Icon icon = pluginPackage.getIcon();+ if (icon == null) {+ icon = DEFAULT_ICON;+ }+ JLabel iconLabel =+ new GIconLabel(ResourceManager.getScaledIcon(icon, 32, 32, 32));iconLabel.setBackground(BG);checkboxPanel.add(iconLabel);@@ -158,22 +164,22 @@ public class PluginManagerComponent extends JPanel implements Scrollable {}private void initializeLabelSection() {- final JPanel centerPanel = new JPanel(new GridBagLayout());+ JPanel centerPanel = new JPanel(new GridBagLayout());GridBagConstraints gbc = new GridBagConstraints();gbc.fill = GridBagConstraints.HORIZONTAL;gbc.weightx = 1.0;centerPanel.setBackground(BG);- final JPanel labelPanel = new JPanel(new VerticalLayout(3));+ JPanel labelPanel = new JPanel(new VerticalLayout(3));labelPanel.setBackground(BG);- final GLabel nameLabel = new GLabel(pluginPackage.getName());+ GLabel nameLabel = new GLabel(pluginPackage.getName());nameLabel.setFont(nameLabel.getFont().deriveFont(18f));nameLabel.setForeground(Color.BLACK);labelPanel.add(nameLabel);- final HyperlinkComponent configureHyperlink = createConfigureHyperlink();+ HyperlinkComponent configureHyperlink = createConfigureHyperlink();labelPanel.add(configureHyperlink);labelPanel.setBorder(BorderFactory.createEmptyBorder(0, 25, 0, 40));@@ -182,7 +188,7 @@ public class PluginManagerComponent extends JPanel implements Scrollable {}private HyperlinkComponent createConfigureHyperlink() {- final HyperlinkComponent configureHyperlink =+ HyperlinkComponent configureHyperlink =new HyperlinkComponent("<html> <a href=\"Configure\">Configure</a>");configureHyperlink.addHyperlinkListener("Configure", e -> {if (e.getEventType() == EventType.ACTIVATED) {@@ -193,14 +199,14 @@ public class PluginManagerComponent extends JPanel implements Scrollable {return configureHyperlink;}- private String enchanceDescription(final String text) {+ private String enchanceDescription(String text) {return String.format("<html><body style='width: 300px'>%s</body></html>", text);}private void initializeDescriptionSection() {- final String htmlDescription = enchanceDescription(pluginPackage.getDescription());+ String htmlDescription = enchanceDescription(pluginPackage.getDescription());- final JLabel descriptionlabel = new GHtmlLabel(htmlDescription);+ JLabel descriptionlabel = new GHtmlLabel(htmlDescription);descriptionlabel.setForeground(Color.GRAY);descriptionlabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));descriptionlabel.setVerticalAlignment(SwingConstants.TOP);