Bug 174879 - [1.5][compiler] Optimisation for empty if blocks results in not evaluating the test expression
Summary: [1.5][compiler] Optimisation for empty if blocks results in not evaluating th...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-20 17:16 EST by David R. MacIver CLA
Modified: 2007-03-20 12:55 EDT (History)
1 user (show)

See Also:


Attachments
Regression tests (3.64 KB, patch)
2007-02-21 10:02 EST, Olivier Thomann CLA
no flags Details | Diff
Proposed fix (7.16 KB, patch)
2007-02-21 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 David R. MacIver CLA 2007-02-20 17:16:06 EST
Build ID: M20060921-0945

Steps To Reproduce:
Compile and run this code:

package test;

public class Test {
	public static void main(String[] args){   
	    Boolean myBool = null;	
	    if (myBool){ }}}   	

This should throw a NullPointerException - in 14.9.1 of the JLS the execution of an if statement is defined to evaluate its test expression. When myBool is evaluated, it should dereference the null value and so throw an NPE.

Interestingly, if you replace "if (myBool) { }" with "if (myBool);" the code does throw an NPE.
Comment 1 Olivier Thomann CLA 2007-02-20 22:26:26 EST
In case there is an unboxing conversion involved, the condition needs to be generated and popped from the stack.
Philippe,
I'll prepare a patch for single name reference, field reference, qualified name reference and array reference.
Comment 2 Olivier Thomann CLA 2007-02-21 10:02:17 EST
Created attachment 59477 [details]
Regression tests
Comment 3 Olivier Thomann CLA 2007-02-21 10:48:47 EST
Created attachment 59482 [details]
Proposed fix
Comment 4 Olivier Thomann CLA 2007-02-23 10:39:31 EST
Released for 3.3M6.
Comment 5 Frederic Fusier CLA 2007-03-20 12:55:25 EDT
Verified for 3.3 M6 using build I20070320-0010.