JDK-8078165 : [macosx] NPE when attempting to get image from toolkit
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-04-20
  • Updated: 2015-09-29
  • Resolved: 2015-04-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Fixed 9 b65Fixed
Description
The default toolkit under macos is LWCToolkit. It JDK8 this overrides getImage:
    public Image getImage(URL url) {

        if (imageCached(url)) {
            return super.getImage(url);
        }

       URL url2x = getScaledImageURL(url);
        return (imageExists(url2x))
               ? getImageWithResolutionVariant(url, url2x) :super.getImage(url);
    }
getScaledImageURL may return null. While SunToolkit.imageExists does checkfor null, it does this after a call to checkPermissions:

    protected static boolean imageExists(URL url) {
        checkPermissions(url);
        if (url != null) {
            try (InputStream is = url.openStream()) {
                return true;
            }catch(IOException e){
                return false;
            }
        }
        return false;
    }
Unfortunately, if there's a SecurityManager that checkPermissions call eventually ends up in URLUtil:

    public static Permission getConnectPermission(URL url) throws IOException
{
        String urlStringLowerCase = url.toString().toLowerCase();

Where the null url gets dereferenced.

Comments
Review: http://cr.openjdk.java.net/~anashaty/8078165/webrev.00/
22-04-2015

Simpler testcase: Toolkit.getDefaultToolkit().getImage(new URL("file://./text@2x.png"));
22-04-2015