JDK-8042759 : Lambda returning implicitly-typed lambdas considered pertinent to applicability
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-05-08
  • Updated: 2014-07-29
  • Resolved: 2014-06-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20Fixed 9 b22Fixed
Description
FULL PRODUCT VERSION :
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux  3.4.69-desktop-1.mga2 #1 SMP Sat Nov 16 17:32:02 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
The JLS8 chapter 15.12.2.2 describes that an explicitly-typed lambda should be considered not pertinent to applicability if at least one of the return expressions is not pertinent to applicability. If an explicitly-typed lambda returns some implicitly-typed lambda, it sometimes behaves like it is considered pertinent to applicability anyway, for example if the implicitly-typed lambda is returned from inside an if-statement. 

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the test case supplied.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compilation was expected to fail.
ACTUAL -
Compilation succeeded. 

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Test {
	
	interface A {
		B m(int a, int b);
	}
	
	interface C {
		String m(int a, int b);
	}
	
	interface B {
		int m(int c);
	}
	
	public static void method(A a) {
		System.out.println("Method 1");
	}
	public static void method(C c) {
		System.out.println("Method 2");
	}
	
	public static void main(String[] args) {
		// This succeeds
		method((int a, int b) -> {
			if(a < b)
				return c -> a + b + c;
			else
				return c -> a + b + c;
		});
		
		/*But this fails (as expected)
		method((int a, int b) -> {
			return c -> a + b + c;	
		});*/		
    }
}
---------- END SOURCE ----------


Comments
ManualVerify: Bug verified manually in promoted results for build JDK9-b22
10-07-2014

ManualVerify: Bug verified manually by running tests for nightly build, 1.9.0-ea-langtools-nightly-h781-20140619-b20 Results at http://aurora.ru.oracle.com/functional/faces/RunDetails.xhtml?names=516155.JDK9-LANGTOOLS-NIGHTLY-4
20-06-2014

The issue is confirmed with 9-b11
08-05-2014