eirikbakke commented on a change in pull request #2227:
URL: https://github.com/apache/netbeans/pull/2227#discussion_r448744232
##########
File path: platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
##########
@@ -307,8 +307,16 @@ public static final Image mergeImages(Image image1, Image
image2, int x, int y)
public static final Icon image2Icon(Image image) {
/* Make sure to always return a ToolTipImage, to take advantage of its
rendering tweaks for
HiDPI screens. */
- return (image instanceof ToolTipImage)
+ int h = image.getHeight(null);
+ int w = image.getWidth(null);
+ if ((h == -1) || (w == -1)) {
+ // [NETBEANS-4420] Cannot create ToolTipImage from an Image
+ // which size is not yet known.
+ return new ImageIcon(image);
+ } else {
+ return (image instanceof ToolTipImage)
? (ToolTipImage) image : assignToolTipToImageInternal(image,
"");
Review comment:
assignToolTipToImageInternal is actually supposed to handle the case of
not-yet-loaded images; it calls ToolTipImage.createNew, which calls
ImageUtilities.ensureLoaded(Image) in turn before trying to get the
width/height of the image. So the exception probably only occurs when there is
some kind of error loading the image.
To preserve handling of not-yet-loaded images, I'd suggest a fix in
ToolTipImage.createNew instead. Where it currently says
```
int w = image.getWidth(null);
int h = image.getHeight(null);
```
just do
```
// Handle images that couldn't be loaded (width/height=-1), despite our
earlier call to ensureLoaded, gracefully.
int w = Math.max(1, image.getWidth(null));
int h = Math.max(1, image.getHeight(null));
```
instead. Is my thinking right here?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists