Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 577987

Summary: ClassCastException on open declaration (F3) on field
Product: [Eclipse Project] JDT Reporter: Nicolas Baumann <nicolas.baumann1>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED FIXED QA Contact: Jay Arthanareeswaran <jarthana>
Severity: major    
Priority: P3 CC: kalyan_prasad, loskutov
Version: 4.22   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard:
Attachments:
Description Flags
stacktrace none

Description Nicolas Baumann CLA 2021-12-29 07:06:47 EST
A minimal example below. The error happens on field 'executors' and seems related to the new syntax of instanceof.


Version: 2021-12 (4.22.0)
Build id: 20211202-1639



import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

import javax.swing.SwingUtilities;

public class MainController {

    private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);

    public void testOK(Object o) {
        executor.submit(() -> {
            SwingUtilities.invokeLater(() -> {
                if (o instanceof Runnable) {
                    Runnable r = (Runnable)o;
                    r.run();
                }
            });
        });

    }

    public void testKO(Object o) {
        executor.submit(() -> {
            SwingUtilities.invokeLater(() -> {
                if (o instanceof Runnable r) {
                    r.run();
                }
            });
        });
    }
}
Comment 1 Nicolas Baumann CLA 2021-12-29 07:11:23 EST
Created attachment 287743 [details]
stacktrace
Comment 2 Kalyan Prasad Tatavarthi CLA 2022-01-25 02:05:15 EST
Moving to JDT Core.
Comment 3 Jay Arthanareeswaran CLA 2022-01-27 00:32:54 EST
This looks like caused by fix to bug 561132, that introduced a LocalDeclaration into the astStack. But presence of a lambda upsets the flow.

I think we should revisit the fix to the said bug rather than fixing it. Will take a look at.
Comment 4 Nicolas Baumann CLA 2023-05-02 05:37:17 EDT
Issue solved in Eclipse 2022-06. Thanks.