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

6.5: Inappropriate use of 'interface type' in aastore, checkcast, instanceof


    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 9
    • Component/s: specification
    • Labels:
    • Subcomponent:


      1. The specs of the aastore, checkcast, and instanceof instructions have long said:

      • If S is an interface type, then:
        - If T is a class type, then T must be Object.
        - If T is an interface type, then T must be the same interface as S or a superinterface of S.

      These lines can be safely removed, since S can never be an interface type. (An implication with a vacuous condition has no force, since it cannot be falsified.) S is the run time type of a reference value, so it must be an array reference or concrete class reference or null.

      2. The aastore spec does not say whether a null value will pass the run-time check. That deserves clarification, since the wording is very explicit about which values may be stored: "Specifically, assignment of a value of reference type S (source) to an array component of reference type T (target) is allowed only if:"

      An obvious fix is to say "If S is the null reference type, then the assignment is allowed." but JVMS 2.4 has never introduced a "null reference type". A better fix is to rephrase along the lines of checkcast and instanceof, so it's clear that a null /value/ gets a pass and that the run-time check is for a non-null /value/ only:

      ***... The arrayref, index, and value are popped from the operand stack.

      If /value/ is null, then /value/ is stored as the component of the array at /index/.

      Otherwise, /value/ is non-null. If the type of /value/ is assignment compatible with the type of the components of the array referenced by /arrayref/, then /value/ is stored as the component of the array at /index/.

       The following rules are used to determine whether a /value/ that is not null is assignment compatible with the array component type. If S is the type of the object referred to by /value/, and T is the reference type of the array component, then aastore determines whether assignment is compatible as follows: - If S is a class type ... - If S is an array type ...***


          Issue Links



              • Assignee:
                abuckley Alex Buckley
                jrose John Rose
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: