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

InstanceKlass::cast passes through NULL

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • hotspot
    • b93
    • generic
    • generic

      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.

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

              Created:
              Updated:
              Resolved: