JDK-8041704 : wrong error message when mixing lambda expression and inner class
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u20
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2014-04-24
  • Updated: 2014-07-29
  • Resolved: 2014-05-27
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
8u20 b17Fixed 9Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b10)
Java HotSpot(TM) Client VM (build 25.20-b10, mixed mode)

A DESCRIPTION OF THE PROBLEM :
https://bugs.openjdk.java.net/browse/JDK-8030816
javac (8u20-ea-b10) does't crash but outputs a wrong error message when mixing a lambda expression and an inner class.
-----
//import java.awt.event.*;
import javax.swing.*;

public class Test {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame("Test");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JButton button = new JButton("Test");
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                }
            });
            frame.add(button);
            frame.setSize(160, 160);
            frame.setVisible(true);
        });
    }
}
-----

P.S. Without a lambda expression, javac (8u20-ea-b10) does't output the wrong error message.
-----
//import java.awt.event.*;
import javax.swing.*;

public class Test1 {
    public static void main(String[] args) {
//        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame("Test1");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JButton button = new JButton("Test");
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                }
            });
            frame.add(button);
            frame.setSize(160, 160);
            frame.setVisible(true);
//        });
    }
}
-----

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test.java:10: error: cannot find symbol
            button.addActionListener(new ActionListener() {
                                         ^
  symbol:   class ActionListener
  location: class Test
1 error
ACTUAL -
Test.java:12: error: missing return statement
                public void actionPerformed(ActionEvent e) {
                                                           ^
Test.java:10: error: cannot find symbol
            button.addActionListener(new ActionListener() {
                                         ^
  symbol:   class ActionListener
  location: class Test
2 errors

REPRODUCIBILITY :
This bug can be reproduced always.


Comments
Smaller example: public class Test { void f(Runnable r) { f(() -> { f(new MISSING() { public void run() {} }); }); } }
20-05-2014