Bug 79396 - [compiler] Static receiver for a static method invocation should be generated to cover side-effects
Summary: [compiler] Static receiver for a static method invocation should be generated...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-24 10:46 EST by Olivier Thomann CLA
Modified: 2005-02-15 07:49 EST (History)
0 users

See Also:


Attachments
Apply on HEAD (1.21 KB, patch)
2004-11-24 10:48 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2004-11-24 10:46:24 EST
Using latest, we optimize out the static receiver for a static field invocation.
We should not as this prevents the declaring class of the static field from
being initialized and this can have a side-effect on the method invocation.

public class X {

    static int Value = 2;
    
    public static void main(String args[]) {
        foo();
    }

    public static int foo() {
	    return Y.CONST.getValue();
    }

    public static int getValue() {
		return Value;
    }

}

class Y {
    static {
		X.Value = 0;
		System.out.println("Class Y is initialized");
    }
        
    static X CONST = null;
}

When executing X, it should display:
Class Y is initialized
Comment 1 Olivier Thomann CLA 2004-11-24 10:48:06 EST
Created attachment 16099 [details]
Apply on HEAD

Possible patch. The static field is generated and discarded immediately.
Comment 2 Philipe Mulet CLA 2005-02-11 18:39:18 EST
Fixed. Adjusted various regression tests.
Added Compliance_1*#test097.
Comment 3 Jerome Lanneluc CLA 2005-02-15 07:49:48 EST
Verified in I20050214