This is the mail archive of the java-prs@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

java/7912: invalid verification error for arrays


>Number:         7912
>Category:       java
>Synopsis:       invalid verification error for arrays
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 13 14:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Eric Blake
>Release:        3.1 20020501 (prerelease)
>Organization:
>Environment:
System: Linux quaffle 2.4.9-31smp #1 SMP Tue Feb 26 06:55:00 EST 2002 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --enable-languages=c,c++,java --prefix=/fpga3/users/eblake/gcc
>Description:
	
The bytecode verifier is choking on legal widening casts from
multi-dimensioned arrays to smaller dimensions of Cloneable or
Serializable.  However, it is correctly allowing similar casts to
arrays of Object.  This is also a recently discovered bug in Sun's VM
verifier.

It appears to be a problem for verifying putstatic, putfield,
invokestatic, invokespecial, invokevirtual, and invokeinterface, but
not with checkcast or instanceof.
>How-To-Repeat:
	<When reporting a compiler error, preprocessor output must be
	included>
$ cat Foo.java
class Foo
{
  static Cloneable[] c;
  public static void main(String[] args)
  {
    c = new int[1][][];
  }
}
$ gcj -C Foo.java
$ gcj -o Foo --main=Foo Foo.class
Foo.java: In class `Foo':
Foo.java: In method `Foo.main(java.lang.String[])':
Foo.java:6: verification error at PC=11
Foo.java:6: expected type 'java.lang.Cloneable[]' but stack contains 'int[][][]'
$ sed -e "s/Cloneable/Object/" Foo.java > Foo1.java
$ mv Foo1.java Foo.java
$ gcj -C Foo.java
$ gcj -o Foo --main=Foo Foo.class
$
>Fix:
	
In the user code, create a temporary Object variable to widen the
original array into, then downcast that variable to the desired
Cloneable[] or Serializable[]. That forces the bytecode compiler to
use the checkcast bytecode, which passes verification.
    Object o = new int[1][][];
    c = (Cloneable[]) o;
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]