IconLoader returning nothing but black pixel in 2019.2
Answered
I am the author of https://github.com/ThomasR/intellij-diff-plugin.
For loading icons, I use
com.intellij.openapi.util.IconLoader.getIcon("foo.svg")
which worked fine in 2019.1, but in 2019.2 I always get a black pixel.


You can reproduce the issue on the current master branch.
What could be the cause?
Please sign in to leave a comment.
Additional information:
The same icon still works in the plugin list view.
I'm confused. Does that view use a different icon loader?
This is probably related to https://youtrack.jetbrains.com/issue/IDEA-206535, the icon loader used for line markers also does not display SVG.
I patched my intellij-community for a fix so I can see SVG icons in the gutter. I rely on this to visually validate code.
Thanks Vladimir, but that is not the problem. Even when I try to load .png files, it returns a black pixel. And SVGs worked fine in 2019.1
I did some further debugging, and found that
com.intellij.openapi.util.IconLoader.CachedImageIcon#getRealIconalways returnscom.intellij.openapi.util.IconLoader#EMPTY_ICONThe root cause seems to be this:
https://github.com/JetBrains/intellij-community/blob/2f91a272fd766773abc3e6d85b5d7035f9da3ed4/platform/util/ui/src/com/intellij/ui/icons/ImageDescriptor.java#L100
I am by no means an expert in Java's resource loading mechanism, so it may be something super simple. What am I missing here?
I am no expert but I think the path for your icons should start with "/' since they are at the root of your resource path. Alternately, you should move your icons to the same relative path as your class package which is used as resourceClass for loading then the relative resource path should work.
I think resource resolution works like class resolution, either a full path is needed or if it is in the same package then only the name can be used.
I keep it simple and use absolute paths for my resource paths so they can be loaded using any class in the distribution.
To clarify, the resource path if not absolute then becomes relative to the class used for loading the reasource:
In my plugin the jar contains:
The resources when loaded using PluginIcons class will be located using "/icons/png/..." or "/icons/svg/..." using absolute path or "png/..." or "svg/..." using relative path.
Perfect, thank you!
Prepending the icon path with "/" solved the issue :)
Reference: https://youtrack.jetbrains.com/issue/IDEA-218876
Wow that took me weeks to figure out. Ultimately I had to debug into the source code of the platform to figure out why the icon wasn't loading, to then find the right google search term to find this post. It was very confusing to upgrade to 2019.2 and simply have the icon not load.
It would be really helpful to mention the use of absolute paths in https://www.jetbrains.org/intellij/sdk/docs/reference_guide/work_with_icons_and_images.html. That page specifically talks about how to organize resources but doesn't explain the use of absolute paths. Which might actually be ok if the platform didn't decide to load a single pixel instead of the default image.
Stefan Sullivan Thanks for your feedback, I"ve just pushed an update to above page in SDK docs containing a dedicated note about this issue.