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

Invalid initializer accepted by new compiler (4030496 rises from the dead)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P5
    • None
    • 1.3.0
    • tools
    • generic, sparc
    • generic, solaris_2.6

    Description

      It seems this old 1.1 bug (4030496) has resurfaced in 1.3. Specifically,

      byte b = '?';

      is accepted in 1.3.

      ------------

      Bug 4286560 appears to be another manifestation of the same problem, that is,
      that the compiler allows an implicit coercion from char to byte. The
      description is reproduced below (maddox 11/1/99):

      See The Java Language Specification (paragraph 5.5, page 67) :
      "
      The detailed rules for compile-time correctness checking of a casting conversion
      of a value of compile-time reference type S (source) to a compile-time reference
      type T (target) are as follows :
      [...]
       + If S is an array type SC[], that is, an array of components of type SC:
       [...]
         + If T is an array type TC[], that is, an array of components of type TC,
           then a compile-time error occurs unless one of the following is true :
          + TC and SC are the same primitive type
          + TC and SC are reference types and type SC can be cast to TC by a recursive
            application of these compile-time rules for casting.
      "
      The new java compiler doesn't follow these rules.

      See the example demonstrating the bug:
      --------------- CompilerTest.java --------------------
      class CompilerTest {
          public static void main(String[] argv) {
              byte[] encoded = { '0', '1', '3', 'f', ')', 'O', '0', 'x' };
          }
      }
      -------------- Output from the test -----------------
      (ans@matmech(pts/16): ~/work .266)
      :\>java -fullversion
      java full version "1.3.0-L"
      (ans@matmech(pts/16): ~/work .262)
      :\>javac CompilerTest.java
      (ans@matmech(pts/16): ~/work .263)
      :\>oldjavac CompilerTest.java
      CompilerTest.java:3: Incompatible type for array. Explicit cast needed to convert char to byte.
                      byte[] encoded = { '0', '1', '3', 'f', ')', 'O', '0', 'x' };
                                       ^
      1 error

      ------------------------------------------------------

      Attachments

        Issue Links

          Activity

            People

              gafter Neal Gafter
              wmaddoxsunw William Maddox (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: