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

Bug 526050

Summary: [content assist] NodeFinder.perform returns incorrect node when overriding default methods from interfaces
Product: [Eclipse Project] JDT Reporter: Clovis Seragiotto <clovis.seragiotto>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: noopur_gupta
Version: 4.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description Clovis Seragiotto CLA 2017-10-15 07:51:16 EDT
1) Create the class
class Foo {
    interface Bar {
        default int getInt() {
            return 0;
        }
    }
    
    Bar b = new Bar() {
        //
    };
}

2) Right before // press <Ctrl+Space> <g> <e> <t> <i> <n> <t> <Enter>

The inserted code is:
public default int getInt() {};

"default" is not allowed and ";" is unnecessary. Expected is:

@Override
public int getInt() {
    // TODO Auto-generated method stub
    return Bar.super.getInt();
}

which is what you get if you press <Ctrl+Space>, select the method getInt from the list of suggestions, and then press <Enter>.
Comment 1 Noopur Gupta CLA 2017-10-15 10:18:55 EDT
The problem is in 
org.eclipse.jdt.core.dom.NodeFinder.perform(ASTNode root, int start, int length) API which is invoked from OverrideCompletionProposal#updateReplacementString in jdt.ui.

When content assist is invoked without typing any character, the offset in the example is 160 and when it is invoked after pressing a char 'g', the offset is 161. In the first case, the API correctly returns the AnonymousClassDeclaration node for {}, whereas in the second case it wrongly returns the VDF node for "b". This results in incorrect computation of the replacement string.

Moving to JDT Core.
Comment 2 Eclipse Genie CLA 2020-01-11 07:22:00 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 3 Clovis Seragiotto CLA 2020-01-12 21:21:22 EST
The bug can still be reproduced.