JDK-8284046 : reconsider cleanup of OptionalDataException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io:serialization
  • Priority: P5
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2022-03-31
  • Updated: 2022-03-31
Related Reports
Relates :  
Relates :  
Description
The OptionalDataException class differs from established conventions for exception classes in a couple ways:

1. it has no public constructors
2. it has public, writable fields

We should reconsider cleaning up this class. This was previously considered in JDK-8168101 which was closed because there was no compelling rationale to fix it. That may indeed have been the case; however, this exception class is a notable outlier compared to almost every other exception class in the system. Because it differs from established patterns, this class is flagged by various static detectors such as the one used by JDK-8283414.

Public constructors could be added without much difficulty.

Getters for the fields could be added, and the fields removed (possibly after deprecation). A middle ground might be to make the fields final. Some corpus searching might be of use to determine the degree of incompatibility.