Bug 79396

Summary: [compiler] Static receiver for a static method invocation should be generated to cover side-effects
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Apply on HEAD none

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