JDK-8214225 : Javac reports error for static lambda expression if return in constructor
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u192
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: x86_64
  • Submitted: 2018-11-20
  • Updated: 2018-11-22
  • Resolved: 2018-11-22
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
Linux 64 bit
Linux 4.15.0-39-generic #42-Ubuntu SMP Tue Oct 23 15:48:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)


A DESCRIPTION OF THE PROBLEM :
The following code snippet reports compilation error:
package my;

import java.util.Comparator;

public class CheckJavaCompileError {
    private static final Comparator<String> MY_COMPARATOR = Comparator.comparing(lambdaVar -> lambdaVar);

    public CheckJavaCompileError() {
        return;
    }
}

Error:(9, 9) java: variable lambdaVar might not have been initialized

REGRESSION : Last worked in version 8u192

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Put code snippet into a file and compile it

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Code successfully compiled
ACTUAL -
Compilation reports error:
Error:(9, 9) java: variable lambdaVar might not have been initialized

---------- BEGIN SOURCE ----------
package my;

import java.util.Comparator;

public class CheckJavaCompileError {
    private static final Comparator<String> MY_COMPARATOR = Comparator.comparing(lambdaVar -> lambdaVar);

    public CheckJavaCompileError() {
        return;
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Avoid using return statement in constructor

FREQUENCY : always



Comments
This has been fixed in JDK 9. Closing this as Duplicate of JDK-8077667.
22-11-2018