Bug 96646

Summary: [1.5][compiler] VerifyError - Generics and Interfaces - "Wrong return type in function"
Product: [Eclipse Project] JDT Reporter: Bryan Barkley <bbarkley>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Apply on HEAD none

Description Bryan Barkley CLA 2005-05-25 13:09:27 EDT
The following code fails when compiled using Eclipse (3.1M7) but runs when
compiled with Sun's JDK.

---------- BaseFactory.java -------------
public abstract class BaseFactory <T> {
    public T create() throws Exception {
        return getType().newInstance();
    }
    public abstract Class<T> getType();
}

---------- StringFactory.java -------------
public interface StringFactory {
    public String create() throws Exception;
}

---------- StringFactoryImpl.java -------------
public class StringFactoryImpl extends BaseFactory<String> implements
StringFactory {
    @Override
    public Class<String> getType() {
        return String.class;
    }
    public static void main(String[] args) throws Exception {
        String emptyString = new StringFactoryImpl().create();
        System.out.printf("We have '%s' of type %s", emptyString,
emptyString.getClass());
    }
}

The error is:
java.lang.VerifyError: (class: StringFactoryImpl, method: create signature:
()Ljava/lang/String;) Wrong return type in function
Comment 1 Philipe Mulet CLA 2005-05-26 10:01:55 EDT
Reproduced
Comment 2 Philipe Mulet CLA 2005-05-26 16:06:40 EDT
Problem comes from synthetic bridge method not issuing an exception attribute.
Olivier: all synthetic methods should dump exception attributes if the binding
carries any. Only bridge methods should currently specify any, but in theory
more could do so as well.
Comment 3 Olivier Thomann CLA 2005-05-26 16:39:46 EDT
Created attachment 21860 [details]
Apply on HEAD
Comment 4 Philipe Mulet CLA 2005-05-26 16:56:39 EDT
Thanks Olivier, indeed there was another more serious issue with missing
checkcast in bridge method.

Only do the cast when access method type is different from target method.
Fixed. Added GenericTypeTest#test700.
Comment 5 Olivier Thomann CLA 2005-05-27 10:42:19 EDT
Verified in I20050526-2000