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

Add final or sealed modifier to appropriate java.awt API classes

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • client-libs
    • None
    • source, binary
    • low
    • Hide
      If someone has circumvented package protections to subclass these, then they may no longer be able to do so. However JDK now enforces strong encapsulation of JDK module internals, so this is not possible anyway without additional steps.

      The compatibility risk is both source and binary since as well as compile time checking of this, the VM enforces it at runtime.
      Show
      If someone has circumvented package protections to subclass these, then they may no longer be able to do so. However JDK now enforces strong encapsulation of JDK module internals, so this is not possible anyway without additional steps. The compatibility risk is both source and binary since as well as compile time checking of this, the VM enforces it at runtime.
    • Java API
    • SE

      Summary

      Make several AWT API classes sealed or final.

      Problem

      There are classes in the AWT API which have a known set of direct sub-classes, or no sub-classes. These should have the sealed or final modifier applied to indicate this.

      Solution

      Apply the sealed modifier from JEP 409 ( https://openjdk.java.net/jeps/409 ) to explicitly document and limit the direct API sub-classes of existing API classes which have no public or protected constructors - and so can be compatibly updated in this way. Similarly identified classes which have no sub-classes should be marked final.

      Sub-classes of newly sealed classes are made non-sealed as needed, or final if they are not already - if that is a compatible change.

      Specification

      java.awt.GridBagLayoutInfo

      -public class GridBagLayoutInfo implements java.io.Serializable
      +public final class GridBagLayoutInfo implements java.io.Serializable
      

      java.awt.PointerInfo

      -public class PointerInfo 
      +public final class PointerInfo 
      

      java.awt. ScrollPaneAdjustable

      -public class ScrollPaneAdjustable implements Adjustable, Serializable 
      +public final class ScrollPaneAdjustable implements Adjustable, Serializable 
      

      java.awt.dnd.DropTargetContext

      
      -public class DropTargetContext implements Serializable 
      +public final class DropTargetContext implements Serializable
      

      java.awt.TextComponent

      -public class TextComponent extends Component implements Accessible {
      +public sealed class TextComponent extends Component implements Accessible
      +     permits TextArea,
      +             TextField {
      

      java.awt.TextField

      -public class TextField extends TextComponent 
      +public non-sealed class TextField extends TextComponent 
      

      java.awt.TextArea

      -public class TextArea extends TextComponent 
      +public non-sealed class TextArea extends TextComponent 
      

      java.awt.InputEvent

      -public abstract class InputEvent extends ComponentEvent 
      +public abstract sealed class InputEvent extends ComponentEvent
      +    permits KeyEvent,
      +            MouseEvent {
      

      java.awt.event.KeyEvent

      -public class KeyEvent extends InputEvent 
      +public non-sealed class KeyEvent extends InputEvent 
       
      ------ java.awt.event.MouseEvent
      -public class MouseEvent extends InputEvent 
      +public non-sealed class MouseEvent extends InputEvent 
      

      java.awt.desktop.AppEvent

      -public class AppEvent extends EventObject {
      +public sealed class AppEvent extends EventObject
      +    permits AboutEvent,
      +            AppForegroundEvent,
      +            AppHiddenEvent,
      +            AppReopenedEvent,
      +            FilesEvent,
      +            OpenURIEvent,
      +            PreferencesEvent,
      +            QuitEvent,
      +            ScreenSleepEvent,
      +            SystemSleepEvent,
      +            UserSessionEvent {
      

      java.awt.desktop.FilesEvent

      -public class FilesEvent extends AppEvent {
      +public sealed class FilesEvent extends AppEvent
      +    permits OpenFilesEvent,
      +            PrintFilesEvent {
      

            prr Philip Race
            prr Philip Race
            Alexey Ivanov, Sergey Bylokhov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: