Bug 469186

Summary: bridge method line number should not be 1
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3    
Version: 4.5   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Markus Keller CLA 2015-06-02 14:00:29 EDT
ECJ produces bridge methods with line number 1. This can lead to situations where it's hard to see which type is referenced in an exception.

Javac uses the line number of the bridge method's type declaration. This identifies the type, but avoids confusing the bridge method with the actual method (see 2nd case in the example).

-------------------
package xy;

import java.util.Arrays;
import java.util.Comparator;

public class BridgeMethodLineNumber {

    public static void main(String[] args) {
        Comparator raw= new Comparator<Integer>() {
            @Override
            public int compare(Integer i1, Integer i2) {
                return i1 / 0;
            }
        };
        try {
            Object[] objects= { "1", "2" };
            Arrays.sort(objects, raw);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Object[] objects= { 1, 2 };
            Arrays.sort(objects, raw);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
-------------------

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
	at xy.BridgeMethodLineNumber$1.compare(BridgeMethodLineNumber.java:1)
	at java.util.TimSort.countRunAndMakeAscending(TimSort.java:351)
	at java.util.TimSort.sort(TimSort.java:216)
	at java.util.Arrays.sort(Arrays.java:1438)
	at xy.BridgeMethodLineNumber.main(BridgeMethodLineNumber.java:17)
java.lang.ArithmeticException: / by zero
	at xy.BridgeMethodLineNumber$1.compare(BridgeMethodLineNumber.java:12)
	at xy.BridgeMethodLineNumber$1.compare(BridgeMethodLineNumber.java:1)
	at java.util.TimSort.countRunAndMakeAscending(TimSort.java:351)
	at java.util.TimSort.sort(TimSort.java:216)
	at java.util.Arrays.sort(Arrays.java:1438)
	at xy.BridgeMethodLineNumber.main(BridgeMethodLineNumber.java:23)