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

Toolkit.getScreenInsets(GraphicsConfiguration) may throw ClassCastException

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Java 11.0.4

      A DESCRIPTION OF THE PROBLEM :
      We have crash reports from a user indicating that Toolkit.getScreenInsets(GraphicsConfiguration) can throw ClassCastException on Windows in some cases. The code is running in an IntelliJ IDEA plugin. I see in the source for WToolkit.getScreenInsets(GraphicsConfiguration) that the result of GraphicsContext.getDevice() is cast to Win32GraphicsDevice without any type validation.

      We have not seen this bug in our Java application, which uses the same code and has a few hundred thousand users, but have seen in in the IntelliJ plugin, which has a few hundred, so most likely IntelliJ is implementing a buffered image paint for icons.

      Relevant parts of the stack dump:
      java.lang.ClassCastException: class sun.awt.image.BufferedImageDevice cannot be cast to class sun.awt.Win32GraphicsDevice (sun.awt.image.BufferedImageDevice and sun.awt.Win32GraphicsDevice are in module java.desktop of loader 'bootstrap')
      at java.desktop/sun.awt.windows.WToolkit.getScreenInsets(WToolkit.java:612)
      at hu.c(hu.java:602)
      ...
      at org.jgrasp.ijplugin.IJIcon.paintIcon(IJIcon.java:1)
      at com.intellij.openapi.actionSystem.ex.ActionButtonLook.paintIconAt(ActionButtonLook.java:141)
      at com.intellij.openapi.actionSystem.ex.ActionButtonLook.paintIcon(ActionButtonLook.java:137)
      at com.intellij.openapi.actionSystem.impl.ActionButton.paintButtonLook(ActionButton.java:400)
      at com.intellij.openapi.actionSystem.impl.ActionButton.paintComponent(ActionButton.java:364)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1074)



      CUSTOMER SUBMITTED WORKAROUND :
      Catch the ClassCastException and assume zero insets.

      FREQUENCY : rarely


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                serb Sergey Bylokhov
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: