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

ComponentEvent.getComponent() may throw ClassCastException

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta2
    • generic
    • generic



      Name: ssT124754 Date: 03/01/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      KeyEvent.setSource() takes an Object as its argument. Thus a KeyEvent's source
      is not guaranteed to be a Component and the cast in
      ComponentEvent.getComponent() may fail!

      Is that original line of code
           "return (source instanceof Component) ? (Component)source : null;"
      really so expensive that it's worth all that trouble to avoid it? Remember that
      ComponentEvent is not final and the source field (of type Object) is protected,
      not private!
      (Review ID: 117942)
      ======================================================================

            ehawkessunw Eric Hawkes (Inactive)
            ssultanasunw Shaheen Sultana (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: