Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335012 - [quick fix] "create '[method]' in super type '[type]'" does not keep varargs, type parameters
Summary: [quick fix] "create '[method]' in super type '[type]'" does not keep varargs,...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: 4.23 M2   Edit
Assignee: Kenneth Styrberg CLA
QA Contact: Jeff Johnston CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-21 08:25 EST by Didier Loiseau CLA
Modified: 2022-02-17 12:21 EST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Didier Loiseau CLA 2011-01-21 08:25:07 EST
Build Identifier: 20100617-1415

When a method is annotated with @Override although it doesn't override/implement a super type method, Eclipse proposes to declare the method in the super type as quick fix. When the method has varargs, the method added by Eclipse will be declared with an array instead, and thus produce a warning.

2 possible workarounds:
- modify the generated method signature after using the quick fix
- use the "Pull Up" refactoring instead, which generates the right method signature. However this adds the @Override annotation a second time, which produces another compilation error.

Reproducible: Always

Steps to Reproduce:
1. Copy the code below in a new java editor
2. On the "withVarargs" method (which does not compile), apply the proposed quick fix: "Create 'withVarargs()' in super type 'MySuperType'
3. Eclipse adds the method 'void withVarargs(int[] foo);' to MySuperType


public class CreateInSuperType implements MySuperType {
	@Override
	public void withVarargs(int... foo) {
		
	}
}

interface MySuperType {
	
}
Comment 1 Olivier Thomann CLA 2011-01-21 08:50:34 EST
Move to JDT/UI
Comment 2 Deepak Azad CLA 2011-04-21 01:19:37 EDT
Ha! The type parameters are also not copied (invoke quick fix on foo). See NewDefiningMethodProposal.addNewTypeParameters(...) :)

-----------------------------------------------------------------
public class CreateInSuperType implements MySuperType {
    @Override
    public void withVarargs(int... foo) {

    }
    
    @Override
    public <T> void foo(T t) {
    	
    }    
}

interface MySuperType {

}
----------------------------------------------------------------
Comment 3 Deepak Azad CLA 2011-04-21 01:52:38 EDT
We should probably reuse some of the code from org.eclipse.jdt.internal.corext.refactoring.structure.HierarchyProcessor.
Comment 4 Didier Loiseau CLA 2012-08-22 05:49:36 EDT
Just to say that I could still reproduce this issue in Eclipse Juno, Build id: 20120614-1722.
Comment 5 Stephan Herrmann CLA 2017-04-09 08:02:57 EDT
I just ran into this while reviewing bug 514213, in particular when I stumbled upon an empty method NewDefiningMethodProposal.addNewTypeParameters(..):
Comment 6 Stephan Herrmann CLA 2017-04-09 08:09:35 EDT
The following empty methods may have an excuse, which should then be documented:
- NewMethodCorrectionProposal.addNewExceptions(..)
- NewMethodCorrectionProposal.addNewTypeParameters(..)
Comment 7 Eclipse Genie CLA 2020-08-14 08:47:34 EDT
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 8 Eclipse Genie CLA 2022-01-12 15:11:20 EST
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/189566
Comment 9 Jeff Johnston CLA 2022-01-14 14:06:42 EST
Released for 4.23 M2
Comment 11 Jeff Johnston CLA 2022-02-17 12:21:52 EST
Verified for 4.23 M2 using I20220216