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

Require receiver of invokespecial to be an instance of the current class?

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 7, 8
    • specification
    • vm

      Longstanding behavior of invokespecial in HotSpot is to produce an error if, for an invokespecial (other than <init>) the objectref on the stack is not an instanceof the current class.

      ---

      Example (see JDK-8009697):

      public class A {
        public void m() { System.out.println("A.m"); }
      }

      public class Test extends A {
        public static void main(String[] args) {
          new A
          dup
          invokespecial A/<init>()V
          invokespecial A/m()V
        }
      }

      Exception in thread "main" java.lang.VerifyError: Bad type on operand stack in method

      ---

      I cannot find this specified. Possibilities:
      - It's specified somewhere (perhaps 4.10, which I don't understand very well?), and there's no bug
      - By virtue of being common practice, it should be added to the spec
      - HotSpot is being too restrictive, and should change (this is not a bug, JDK-8009697 is)

      Related rules in the spec:
      - Per 4.9.2, invokespecial must name <init>, or a method in the current class or one of its supers
      - Per 6.5-invokespecial, _protected_ methods have a restriction like this outside of their package

            dlsmith Dan Smith
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: