Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8344907

NullPointerException in Win32ShellFolder2.getSystemIcon when "icon" is null

XMLWordPrintable

    • b25
    • 17
    • b06
    • generic
    • windows

      ADDITIONAL SYSTEM INFORMATION :
      Windows, x64. Bug is present in all recent releases.

      A DESCRIPTION OF THE PROBLEM :
      There is a missing null check in Win32ShellFolder2.java:1217.

      Seeing users crash in the wild with:
      > Cannot invoke "java.awt.Image.getWidth(java.awt.image.ImageObserver)" because "icon" is null.

      1215: long hIcon = getSystemIcon(iconType.getIconID()); // <-- Can return null
      1216: Image icon = makeIcon(hIcon); // <-- Has internal null check
      1217: if (LARGE_ICON_SIZE != icon.getWidth(null)) { // <-- NullPointerException -- icon is null

      Occurs when Windows is unable to provide a system icon for an `optionPaneIcon` in Win32ShellFolderManager2.java:411. The code assumes an icon will *always* be returned, but the Windows API makes no such guarantee.

      getSystemIcon calls (via JNI) LoadIcon (User32.dll). This can return null -- and sometimes does.
      https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadicona

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Reproduces when Windows is unable to return an icon.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      `static Image getSystemIcon(SystemIcon iconType)` in Win32ShellFolder2.java:1214 should return null rather than throwing a NPE.
      ACTUAL -
      Stack trace:
      java.lang.NullPointerException: Cannot invoke "java.awt.Image.getWidth(java.awt.image.ImageObserver)" because "icon" is null
          at sun.awt.shell.Win32ShellFolder2.getSystemIcon(Win32ShellFolder2.java:1217)
          at sun.awt.shell.Win32ShellFolderManager2.get(Win32ShellFolderManager2.java:411)
          at sun.awt.shell.ShellFolder.get(ShellFolder.java:272)
          at com.sun.java.swing.plaf.windows.WindowsLookAndFeel$LazyWindowsIcon.createValue(WindowsLookAndFeel.java:2100)
          at javax.swing.UIDefaults.getFromHashtable(UIDefaults.java:226)
          at javax.swing.UIDefaults.get(UIDefaults.java:274)
          at javax.swing.MultiUIDefaults.get(MultiUIDefaults.java:83)
          at javax.swing.UIManager.get(UIManager.java:1025)
          at sun.swing.DefaultLookup.get(DefaultLookup.java:99)
          at javax.swing.plaf.basic.BasicOptionPaneUI.getIconForType(BasicOptionPaneUI.java:676)
          at javax.swing.plaf.basic.BasicOptionPaneUI.getIcon(BasicOptionPaneUI.java:647)
          at javax.swing.plaf.basic.BasicOptionPaneUI.createMessageArea(BasicOptionPaneUI.java:361)
          at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:200)
          at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:160)
          at javax.swing.JComponent.setUI(JComponent.java:740)
          at javax.swing.JOptionPane.setUI(JOptionPane.java:1858)
          at javax.swing.JOptionPane.updateUI(JOptionPane.java:1880)
          at javax.swing.JOptionPane.<init>(JOptionPane.java:1845)
          at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:869)

      CUSTOMER SUBMITTED WORKAROUND :
      There is no workaround

      FREQUENCY : often


            honkar Harshitha Onkar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: