Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4280591
Votes 0
Synopsis Invalid initializer accepted by new compiler (4030496 rises from the dead)
Category java:compiler
Reported Against kestrel , kestrel-beta
Release Fixed
State 11-Closed, Not a Defect, bug
Priority: 5-Very Low
Related Bugs 4286560
Submit Date 13-OCT-1999
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  -----------------
(  xxxxx@xxxxx  (pts/16): ~/work .266)
:\>java -fullversion
java full version "1.3.0-L"
(  xxxxx@xxxxx  (pts/16): ~/work .262)
:\>javac CompilerTest.java 
(  xxxxx@xxxxx  (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

------------------------------------------------------ 
Work Around
N/A
Evaluation
The check was simply omitted, however, there is a reasonable spec issue
that suggests that it should be -- see the comments.

  xxxxx@xxxxx   1999-10-14

We will probably not fix this, and let the current behavior stand as the
revised spec in JLS2e.  Nothing has been definitively decided here, however.

  xxxxx@xxxxx   1999-10-27

The second edition of the JLS explicitly allows this. See the three bullets in the first paragraph of 5.2 (Assignment Conversion).

  xxxxx@xxxxx   2001-01-29
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang