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

InstanceKlass::cast passes through NULL

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b93
    • CPU:
      generic
    • OS:
      generic

      Description

      InstanceKlass::cast is a checking conversion function, downcasting a Klass* to an InstanceKlass* if the argument klass is indeed an InstanceKlass, asserting if not.

      However, unlike many (most? all?) other similar checking conversion functions in Hotspot, this one allows the argument pointer to be a null pointer, and in that case returns a null pointer of the requested type. Given the more common practice of having such checking conversion functions assert when the argument is a null pointer, the behavior here is surprising to some.

      It's not known whether there are any uses of InstanceKlass::cast that make use of that behavior for null pointers. Certainly a large percentage of uses will (nearly) instantly crash if given a null pointer, because the result is immediately the target of a member function call.

      We should examine the uses of InstanceKlass::cast and see if we can safely change the behavior to require a non-null pointer. Even if there are some small number of cases that depend on the present behavior, it might be better to change those than to retain the existing somewhat surprising behavior.

        Attachments

          Activity

            People

            • Assignee:
              coleenp Coleen Phillimore
              Reporter:
              kbarrett Kim Barrett
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: