Bug 342819 - Code rejected by javac with name clash error compiles under eclipse.
Summary: Code rejected by javac with name clash error compiles under eclipse.
Status: VERIFIED DUPLICATE of bug 334306
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-14 06:14 EDT by mirak CLA
Modified: 2011-08-05 02:54 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mirak CLA 2011-04-14 06:14:02 EDT
Build Identifier: 20100218-1602

"Name clash: The method convert(A) of type DTOAdapter<A,B> has the same erasure as convert(B) of type TwoWayDTOAdapter<A,B> but does not override it"

however changing method order in the implementing class resolve the error


Reproducible: Always

Steps to Reproduce:
public interface DTOAdapter<A, B> {
    public B convert(A a);
}

public interface TwoWayDTOAdapter<A, B> extends DTOAdapter <A, B>{
    public A convert(B b) throws AdapterException;
}

this doesn't work and gives the above description error :

public class TestAdapter implements TwoWayDTOAdapter<Long, Integer> {

    public Long convert(Integer b) throws AdapterException {
        // TODO Auto-generated method stub
        return null;
    }

    public Integer convert(Long a) throws AdapterException {
        // TODO Auto-generated method stub
        return null;
    }
}



this works, however I just inverted method declaration order :

public class TestAdapter implements TwoWayDTOAdapter<Long, Integer> {

    public Integer convert(Long a) throws AdapterException {
        // TODO Auto-generated method stub
        return null;
    }
	
    public Long convert(Integer b) throws AdapterException {
        // TODO Auto-generated method stub
        return null;
    }
}

inverting the types, with the faulty order like in the first case make it work :

public class TestAdapter implements TwoWayDTOAdapter<Integer,Long> {

    public Long convert(Integer b) throws AdapterException {
        // TODO Auto-generated method stub
        return null;
    }

    public Integer convert(Long a) throws AdapterException {
        // TODO Auto-generated method stub
        return null;
    }
}


Note that when generating the stub, eclipse gives the wrong order
Comment 1 Srikanth Sankaran CLA 2011-04-14 07:24:01 EDT
(In reply to comment #0)
> Build Identifier: 20100218-1602

Can you please test with a more recent build say 3.7 or so.
I could not reproduce this on 3.7. I also verified that this
works as expected on HEAD.

I plan to close this as WORKSFORME.
Comment 2 mirak CLA 2011-04-15 04:39:32 EDT
(In reply to comment #1)
> (In reply to comment #0)
> > Build Identifier: 20100218-1602
> 
> Can you please test with a more recent build say 3.7 or so.
> I could not reproduce this on 3.7. I also verified that this
> works as expected on HEAD.
> 
> I plan to close this as WORKSFORME.

I tested it on eclipse 3.7M6 and it compiles in all cases.

However some people report me that it doesn't work with javac
Comment 3 mirak CLA 2011-04-15 04:57:17 EDT
(In reply to comment #2)
> (In reply to comment #1)
> > (In reply to comment #0)
> > > Build Identifier: 20100218-1602
> > 
> > Can you please test with a more recent build say 3.7 or so.
> > I could not reproduce this on 3.7. I also verified that this
> > works as expected on HEAD.
> > 
> > I plan to close this as WORKSFORME.
> 
> I tested it on eclipse 3.7M6 and it compiles in all cases.
> 
> However some people report me that it doesn't work with javac

I tested and it doesnt build with javac 1.5, however the eclipse bytecode runs on the jvm from the jdk1.5.0_21


$ /cygdrive/c/Program\ Files/Java/jdk1.5.0_21/bin/javac.exe *.java
 
TestAdapter.java:4: name clash: convert(B) in fr.test.TwoWayDTOAdapter<java.lang.Long,java.lang.Integer> and convert(A) in fr.test.DTOAdapter<java.lang.Long,java.lang.Integer> have the same erasure, yet neither overrides the other
public class TestAdapter implements TwoWayDTOAdapter<Long, Integer> {
       ^
1 error
Comment 4 Srikanth Sankaran CLA 2011-04-15 05:53:09 EDT
The program attached to comment 0 fails to compile with
eclipse 3.7, 3.7 M6 as well as HEAD, not with the name
clash error reported, but due to the fact that overriding
method attempts to throw exceptions not listed in the
throws clause of the overridden method.

I see the same behavior with javac 5,6,7 - All of them
complain about the throws clause. So I don't know how
you managed to run the program - It is likely you are
using slightly modified tests. Please post the exact test
case you are using so we can be on the same page.
Comment 5 mirak CLA 2011-04-15 06:49:00 EDT
(In reply to comment #4)
> The program attached to comment 0 fails to compile with
> eclipse 3.7, 3.7 M6 as well as HEAD, not with the name
> clash error reported, but due to the fact that overriding
> method attempts to throw exceptions not listed in the
> throws clause of the overridden method.
> 
> I see the same behavior with javac 5,6,7 - All of them
> complain about the throws clause. So I don't know how
> you managed to run the program - It is likely you are
> using slightly modified tests. Please post the exact test
> case you are using so we can be on the same page.


Here is the exception code.
The code you mention works if "throws AdapterException" is removed everywhere  though.


public class AdapterException extends RuntimeException {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4296648530651520598L;

	public AdapterException() {
		super();
		// TODO Auto-generated constructor stub
	}

	public AdapterException(String message, Throwable cause) {
		super(message, cause);
		// TODO Auto-generated constructor stub
	}

	public AdapterException(String message) {
		super(message);
		// TODO Auto-generated constructor stub
	}

	public AdapterException(Throwable cause) {
		super(cause);
		// TODO Auto-generated constructor stub
	}

}
Comment 6 mirak CLA 2011-04-15 07:00:32 EDT
here is the code without the exception


public interface DTOAdapter<A, B> {
	public B convert(A a);
}


public interface TwoWayDTOAdapter<A, B> extends DTOAdapter <A, B>{
	public A convert(B b);
}


public class TestAdapter implements TwoWayDTOAdapter<Long, Integer> {

	public Long convert(Integer b) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public Integer convert(Long a) {
		// TODO Auto-generated method stub
		return null;
	}
}
Comment 7 Srikanth Sankaran CLA 2011-04-15 07:05:47 EDT
Thanks, I do see a difference in behavior and will investigate.
Changed the title suitably.
Comment 8 mirak CLA 2011-04-15 08:35:22 EDT
(In reply to comment #7)
> Thanks, I do see a difference in behavior and will investigate.
> Changed the title suitably.


I don't really see why it shouldn't work on javac either.

I understand that in case the given type for A and B are the same, then it wouldn't work obviously, but it would be dectected at compile time anyway at the implementor level.
Comment 9 Srikanth Sankaran CLA 2011-05-16 10:57:39 EDT
Released junit org.eclipse.jdt.core.tests.compiler.regression.MethodVerifyTest.test342819()

*** This bug has been marked as a duplicate of bug 334306 ***
Comment 10 Olivier Thomann CLA 2011-06-28 09:54:39 EDT
Verified that the code doesn't compile. For comment 6, the error is reported against:
    public A convert(B b);