JaroslavTulach closed pull request #438: More robustness when resource name of 
loadImageIcon is null
URL: https://github.com/apache/incubator-netbeans/pull/438
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/openide.util.ui/src/org/openide/util/ImageUtilities.java 
b/openide.util.ui/src/org/openide/util/ImageUtilities.java
index 1fd8745b3..c90164e8b 100644
--- a/openide.util.ui/src/org/openide/util/ImageUtilities.java
+++ b/openide.util.ui/src/org/openide/util/ImageUtilities.java
@@ -403,6 +403,9 @@ public void resultChanged(LookupEvent ev) {
 
     static Image getIcon(String resource, boolean localized) {
         if (localized) {
+            if (resource == null) {
+                return null;
+            }
             synchronized (localizedCache) {
                 ActiveRef<String> ref = localizedCache.get(resource);
                 Image img = null;
@@ -475,6 +478,9 @@ static Image getIcon(String resource, boolean localized) {
     *  and is not optimized/interned
     */
     private static Image getIcon(String name, ClassLoader loader, boolean 
localizedQuery) {
+        if (name == null) {
+            return null;
+        }
         ActiveRef<String> ref = cache.get(name);
         Image img = null;
 
diff --git 
a/openide.util.ui/test/unit/src/org/openide/util/ImageUtilitiesTest.java 
b/openide.util.ui/test/unit/src/org/openide/util/ImageUtilitiesTest.java
index 7f94e333a..087a49d61 100644
--- a/openide.util.ui/test/unit/src/org/openide/util/ImageUtilitiesTest.java
+++ b/openide.util.ui/test/unit/src/org/openide/util/ImageUtilitiesTest.java
@@ -21,10 +21,9 @@
 import java.awt.Color;
 import java.awt.Image;
 import java.awt.image.BufferedImage;
-import java.awt.image.ImageObserver;
-import java.net.MalformedURLException;
 import java.net.URL;
 import javax.swing.Icon;
+import javax.swing.ImageIcon;
 import javax.swing.UIManager;
 import junit.framework.*;
 
@@ -38,6 +37,16 @@ public ImageUtilitiesTest (String testName) {
         super (testName);
     }
 
+    public void testNullYieldsNullLocalized() throws Exception {
+        ImageIcon icon = ImageUtilities.loadImageIcon(null, true);
+        assertNull(icon);
+    }
+
+    public void testNullYieldsNull() throws Exception {
+        ImageIcon icon = ImageUtilities.loadImageIcon(null, false);
+        assertNull(icon);
+    }
+
     public void testMergeImages() throws Exception {
         // test if merged image preserves alpha (#90862)
         BufferedImage img1 = new BufferedImage(16, 16, 
BufferedImage.TYPE_INT_ARGB);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to