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

[lworld] Compiler should emit a warning if code compares the result of getClass() against the class literal for an interface

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: repo-valhalla
    • Fix Version/s: repo-valhalla
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      From http://cr.openjdk.java.net/~briangoetz/valhalla/sov/02-object-model.html:

      There is one possible incompatibility mode from such a migration – if the client compares the getClass() result with M.class. Pre-migration, an instance of Optional has class Optional.class; once Optional is migrated to an interface, instances of Optional will report some implementation class when queried with getClass.

      This incompatibility surrounding use of M.class is the major compatibility cost of the migration approach outlined here. This can be mitigated somewhat by issuing compiling warnings when comparing the getClass() result with == against the class literal for an interface, since this will be known to fail at runtime.

        Attachments

          Activity

            People

            • Assignee:
              sadayapalam Srikanth Adayapalam
              Reporter:
              sadayapalam Srikanth Adayapalam
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: