Bug 469186 - bridge method line number should not be 1
Summary: bridge method line number should not be 1
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-02 14:00 EDT by Markus Keller CLA
Modified: 2015-06-02 14:00 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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)