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/8025: ICE when bytecode does array access on null


>Number:         8025
>Category:       java
>Synopsis:       ICE when bytecode does array access on null
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          ice-on-legal-code
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 24 16:36:00 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 java .class file verifier is croaking when accessing array
elements of a null-typed local variable. This affects the 16
instructions [abcsilfd]a{load|store}.

Further analysis: In .java source code, no variable can have the null
type. But in .class bytecode, aconst_null is legal and has its own
type. The null type can therefore appear as the arrayref argument for
array stores and array loads - this must generate a
NullPointerException at runtime, but it is legal code and must pass
the verifier.

>How-To-Repeat:
	
Compile this program (which demonstrates the bug for iaload; the other
15 bytecodes with problems are similar) to bytecode, then from
bytecode to native.

$ cat Foo.java
class Foo
{
  void m()
  {
    int[] a = null;
    int i = a[0];
  }
}
$ gcj -C Foo.java
$ gcj -o Foo --main=Foo Foo.class
Foo.java: In class `Foo':
Foo.java: In method `Foo.m()':
Foo.java:6: Internal compiler error in build_java_check_indexed_type, at java/expr.c:890
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.
$

>Fix:
	
The following hack forces the compiler to store type information and
thus avoid the ICE:

class Foo1
{
  void m()
  {
    int[] a = null;
    Object o = a;
    a = (int[]) o; // this causes a checkcast bytecode to appear,
               // now the verifier knows a is int[] instead of null
    int i = a[0]; // correctly throws the NullPointerException
  }
}
>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]