Bug 346042 - [1.5][compiler] ecj compiles code rejected by javac for varargs parameters of inaccessible type
Summary: [1.5][compiler] ecj compiles code rejected by javac for varargs parameters of...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.8 M4   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-17 03:44 EDT by Ayushman Jain CLA
Modified: 2011-12-06 06:18 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ayushman Jain CLA 2011-05-17 03:44:07 EDT
Eclipse(I20110514-0800) compiles the following code fine, but generates invalid bytecode which fails at runtime with a java.lang.IllegalAccessError.

A.java
----------
package p1;

class A {
  A() {
  }
}
------------

B.java
------------
package p1;
import java.io.*;
public class B extends A {
 public B() {}

 public void foo(A... args) {
  System.out.println(args);
 }
}
-----------

C.java
----------
package p2;
import p1.B;
public class C {

 public static final void main(String[] args) {
   (new B()).foo(new B(), new B());
 }
}

javac7b138 correctly complains at compile time
C:\Documents and Settings\Administrator\Desktop\Eclipse builds\eclipse-SDK-I2011
0514-0800-win32\eclipse\workspace\A\src\p2\C.java:6: error: method foo in class
B cannot be applied to given types;
   (new B()).foo(new B(), new B());
            ^
  required: A[]
  found: B,B
  reason: formal varargs element type A is not accessible from class C
1 error
--------------------------------------------------------------------

This was a javac bug which is fixed with http://bugs.sun.com/view_bug.do?bug_id=6313164
Comment 1 Olivier Thomann CLA 2011-05-17 08:43:00 EDT
I would target 3.7.1 to match the Java 7 behavior when the Java 7 support is released.
Comment 2 Srikanth Sankaran CLA 2011-08-04 00:24:13 EDT
Don't expect to get to this before 3.8. Retargetting.
Comment 3 Srikanth Sankaran CLA 2011-11-13 23:58:28 EST
Released fix for 3.8 M4 via commit b8b8ddf64dedf8c9c31f5a6a372768428e737f63.
We now issue a near identical message as javac. For the case in comment#0
we report

"The method foo(A...) of type B is not applicable as the formal varargs element type A is not accessible here"
Comment 4 Jay Arthanareeswaran CLA 2011-12-06 06:18:19 EST
Verified for 3.8M4 with build I20111204-2000.