Bug 255008 - [compiler] Assert statement discrepancy with javac caused by an uninitialized variable
Summary: [compiler] Assert statement discrepancy with javac caused by an uninitialized...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-12 05:42 EST by Remy Suen CLA
Modified: 2008-12-11 11:16 EST (History)
2 users (show)

See Also:


Attachments
Proposed patch (17.37 KB, patch)
2008-12-08 11:55 EST, 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 Remy Suen CLA 2008-11-12 05:42:41 EST
I don't know who is at fault here but the code below is fine with Sun javac (1.5.0.16 and 1.6.0.10) but no go in JDT on I20081029-1823.

public class Test {

	protected void transform() {
		final float error;
		assert false : error;
	}

}

ECJ complains that error is uninitialized. I think javac is wrong here since the JVM will try to create a throwable with 'error' in the message somewhere but will fail because it is not initialized. But what do I know about Java compilers? :)
Comment 1 Remy Suen CLA 2008-11-12 05:45:16 EST
Scratch the above, I was trying to make a more compact test case and failed. Try this one.

public class Test {

	protected void transform(boolean srcPts) {
		final float error;
		assert !(srcPts && (error = maxError()) > 0) : error;
	}

	private float maxError() {
		return 0;
	}

}
Comment 2 Philipe Mulet CLA 2008-12-08 11:54:56 EST
This is indeed our bug (for comment 1).
The code should essentially be the same as:

float foo1(boolean srcPts) {
	final float error2;
	if (!(srcPts && (error2 = maxError()) > 0)) {
	} else {
		return error2;
	}
	return 0;
}

where ECJ correctly accepts the code as correct.
Comment 3 Philipe Mulet CLA 2008-12-08 11:55:35 EST
Created attachment 119813 [details]
Proposed patch
Comment 4 Philipe Mulet CLA 2008-12-08 11:55:53 EST
Added AssertionTest#test017
Comment 5 Philipe Mulet CLA 2008-12-10 12:43:54 EST
Released for 3.5M4.
Fixed
Comment 6 Jerome Lanneluc CLA 2008-12-11 11:16:37 EST
Verified for 3.5M4 using I20081211-0100