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

Using reflection to work with the elements of a preview API at run time deserves to be mentioned in the JavaSE API specification

    Details

    • Type: Enhancement
    • Status: New
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 16
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      JEP 12 (JDK-8195734) contains the following (as of July 17th 2020):

      ==================
      Preview APIs are not "hidden" at run time, even when preview features are disabled. A sufficiently motivated program can use reflection to detect, instantiate, and invoke the elements of a preview API at run time, whether preview features are enabled or disabled. Using reflection to refer to standalone, essential, or convenient preview APIs allows a program to be compiled without enabling preview features, and without its class files being marked as depending on preview features. This implies that the program is expected to run on multiple Java releases -- one release where the preview API is found and exploited via reflection, and other releases where it is unavailable -- and this in turn implies that the program is being developed for distribution. It is very strongly recommended that any program which uses preview APIs is not distributed. The special rule that allows for "quiet" use of reflective preview APIs aims to accommodate frameworks that react properly to the presence of preview features in user code being tested on a new version of the framework (that is, the user code is not being distributed).
      ==================

      However the normative specification of "java.lang.reflect" JavaSE API package doesn't seem to contain any related assertions. This important aspect of behavior explained in JEP12 deserves to be mentioned in the JavaSE API specification.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                dbessono Dmitry Bessonov
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: