Bug 147024 - [compiler] Compiler bug when accessing static final attribute in a non-static way
Summary: [compiler] Compiler bug when accessing static final attribute in a non-static...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.2.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 159350 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-06-14 05:51 EDT by Laurent Mirguet CLA
Modified: 2006-09-29 17:14 EDT (History)
2 users (show)

See Also:


Attachments
Proposed patch (15.79 KB, patch)
2006-06-20 09:03 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Laurent Mirguet CLA 2006-06-14 05:51:53 EDT
See the following program:

public class MyClass {
	public static final boolean flag = true;

	public boolean getFlag() {
		if (this.flag) return true;
		else return false;
	}

	public static void main(String[] args) {
		System.out.println("It worked.");
	}
}

When we try to compile/execute it in Eclipse 3.2RC7 (JDK1.4.2) we get the following error: "java.lang.VerifyError: (class:pack/MyClass, method:getFlag signature: ()Z) Illegal target for jump or branch"

It works with Eclipse 3.0.2
Comment 1 Philipe Mulet CLA 2006-06-15 06:37:29 EDT
Reproduced
Comment 2 Philipe Mulet CLA 2006-06-15 06:43:41 EDT
Problem comes from prefixing the static with a receiver.
i.e. workaround is to remove unnecessary "this." qualification to "flag" field access in IF statement.

        public boolean getFlag() {
                if (flag) return true;
                else return false;
        }

Note that a warning is emitted to signal that the static field should be accessed in a static way.
Comment 3 Philipe Mulet CLA 2006-06-20 08:59:45 EDT
boolean code generation got reworked during 3.2 cycle to address other issues and make it more optimized. However, it was lacking optimization in this particular scenario, since the prefix of a static field access is optimized more aggressively nowadays.

Fix released for 3.2.1 (TARGET_321)
Fix released for 3.3M1 (HEAD)

Added BooleanTest#test037
Comment 4 Philipe Mulet CLA 2006-06-20 09:03:20 EDT
Created attachment 44913 [details]
Proposed patch
Comment 5 Frederic Fusier CLA 2006-08-08 09:07:10 EDT
Verified for 3.3 M1 using build I20060807-2000.

Note that I could not reproduce using 3.2 build (M20060629-1905) but only with 3.2 RC7...
Comment 6 David Audel CLA 2006-09-11 10:54:12 EDT
Verified for 3.2.1 using build M20060908-1655
Comment 7 Philipe Mulet CLA 2006-09-29 17:14:26 EDT
*** Bug 159350 has been marked as a duplicate of this bug. ***