Bug 569758 - compiler error with ternary operator
Summary: compiler error with ternary operator
Status: CLOSED DUPLICATE of bug 569498
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.18   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-16 17:19 EST by Shawn Lundvall CLA
Modified: 2020-12-16 17:57 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shawn Lundvall CLA 2020-12-16 17:19:02 EST
There is an issue with the latest update (2020-12) in eclipse as shown below in the code snippet:

public class TernaryFail {
	final static boolean debug = false;
	final static String s1 = "Test string one";
	final static String s2 = "Test string two";
	
	static public void testMethod() {
		
		//  This works with no compile error
		String test = "";
		if (debug)
			test = s1;
		else
			test = s2;
		System.out.println(test);
		
		// This works with no compile error
		test = (debug ? s1 : s2);
		System.out.println(test);
		
		// This fails compile with "debug cannot be resolved to a variable" but used to work in eclipse 2020-09 and prior
		test = new String(debug ? s1 : s2);
		System.out.println(test);
	}
}

I starting seeing this issue today after updating eclipse to 2020-12 on both the Mac (Big Sur) and Windows 10.
Comment 1 Shawn Lundvall CLA 2020-12-16 17:24:27 EST
Forgot to mention that we are using 1.8 compatibility.
Comment 2 Andrey Loskutov CLA 2020-12-16 17:57:56 EST

*** This bug has been marked as a duplicate of bug 569498 ***