Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8041704

wrong error message when mixing lambda expression and inner class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8u20
    • 8u20
    • tools
    • b17
    • x86
    • windows_vista

        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.

              pgovereau Paul Govereau (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: