Bug 5179 - Qualifed static field access doesn't initialize its class
Summary: Qualifed static field access doesn't initialize its class
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.1
: P3 normal
Target Milestone: 3.3.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-12-22 16:06 UTC by Bryce McKinlay
Modified: 2003-08-05 02:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-05-25 13:50:18


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bryce McKinlay 2001-12-22 16:06:00 UTC
The following test case crashes because no class initialization for "Bar" is generated.

Release:
gcc version 3.1 20011221 (experimental)

How-To-Repeat:
class Bar
{
  static Bar B = new Bar();
  int i = 1;
}

public class Qual2
{
  public static void main(String[] args)
  {
    System.out.println (Bar.B.i);    // crash
    System.out.println ((Bar.B).i);  // crash    
  }
}
Comment 1 Andrew Pinski 2003-05-24 19:13:53 UTC
Confirmed on 3.3 (20021216), Yes I know that this is an old prelease but still.
But fixed on mainline (20030524).
Comment 2 Dara Hazeghi 2003-05-25 03:44:00 UTC
Hello,

with gcc 3.2.3, 3.3 branch, and mainline (20030524), the testcase here crashes as reported:
Exception in thread "main" java.lang.NullPointerException
   at Qual.main(java.lang.String[]) (Unknown Source)

Dara
Comment 3 Andrew Pinski 2003-05-25 04:14:10 UTC
I cannot reproduce this on the mainline (20030524) on i686-pc-linux-gnu:
tin:~/src/gnu/gcctest>gcj --main=Qual2 Qual2.java 
tin:~/src/gnu/gcctest>./a.out 
1
1
tin:~/src/gnu/gcctest>gcj --main=Qual2 Qual2.java -O3
tin:~/src/gnu/gcctest>./a.out
1
1
tin:~/src/gnu/gcctest>gcj --main=Qual2 Qual2.java -O3 -C
gcj: cannot specify `main' class when not linking
tin:~/src/gnu/gcctest>gcj Qual2.java -O3 -C
tin:~/src/gnu/gcctest>gij Qual2
1
1
tin:~/src/gnu/gcctest>java Qual2
1
1
tin:~/src/gnu/gcctest>javac Qual2.java 
tin:~/src/gnu/gcctest>!gij
gij Qual2
1
1
tin:~/src/gnu/gcctest>gcj Qual2.class --main=Qual2 Bar.class 
tin:~/src/gnu/gcctest>./a.out 
1
1
Comment 4 Andrew Pinski 2003-05-25 13:50:18 UTC
This is fixed for 3.4 as noted above by me.
Comment 5 Andrew Pinski 2003-05-28 00:38:48 UTC
Since this is not a regression I can closing this bug as it is fixed in a later version of gcc.