Bug 520434 - [1.8] Convert to method reference change semantics
Summary: [1.8] Convert to method reference change semantics
Status: CLOSED DUPLICATE of bug 499863
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.7   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-01 16:16 EDT by Casper Færgemand CLA
Modified: 2017-08-02 09:44 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Casper Færgemand CLA 2017-08-01 16:16:27 EDT
One of the following JUnit tests fail:

	class A {
		boolean called = false;

		void callOnce(int i) {
			if (called) {
				throw new IllegalArgumentException();
			} else {
				called = true;
			}
		}
	}

	@Test
	public void fine() {
		IntStream.of(1, 2, 3).forEach(i -> new A().callOnce(i));
	}

	@Test
	public void error() {
		IntStream.of(1, 2, 3).forEach(new A()::callOnce);
	}

Fine and error can be changed to one another using Ctrl + 1 and Convert to lambda expression or Convert to method reference, but the semantics of the two are not identical. Fine creates a new A for each forEach, while error reuses the same instance of A for each forEach.
Comment 1 Noopur Gupta CLA 2017-08-02 09:44:17 EDT
It should be handled with bug 499863.

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