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

4.10.2.2: fix merging of primitive array types

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 22
    • 17, 19
    • specification
    • vm
    • 8
    • generic
    • generic

    Description

      JVMS §4.10.2.2 (https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.10.2.2-300) specifies that when merging two operand stacks, int[] and String[] are merged into Object[]:

      > If corresponding values are both array reference types, then their dimensions are examined. If the array types have the same dimensions, then the merged value is a reference to an instance of an array type which is first common supertype of both array types. (If either or both of the array types has a primitive element type, then Object is used as the element type instead.) [...]
      >
      > [...] **Even int[] and String[] can be merged; the result is Object[]**, because Object is used instead of int when computing the first common supertype.

      In the first place, Object[] is not a supertype of int[], so this merge does not make any sense.
      It can also be does not work when trying to create bytecode that takes the statements in the JVMS at face value (see reproducer).

      I did ask on Stack Overflow (https://stackoverflow.com/q/76735066/845414), where I got the answer that "This obviously wrong statement shouldn't exist in the first place.".

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: