Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bug in eclipse compiler or javac?

Who is right? Eclipse or javac?

--------------- c/v/A.java ---------------

package c.v;
public class A<T> {
}

--------------- c/v/B.java ---------------

package c.v;
public class B extends A<B.Secret> {
  private class Secret {};
}

Eclipse compiles B.java just fine.

Javac has a problem.

$ javac c/v/B.java
c/v/B.java:3: c.v.B.Secret has private access in c.v.B
public class B extends A<B.Secret> {
                           ^
    1 error
like image 658
Eric Avatar asked Apr 16 '09 19:04

Eric


People also ask

Does Eclipse use javac?

Eclipse Java compiler is an incremental Java builder The Java compiler built in Eclipse is a part of JDT Core component (JDT: Java Development Tool). An incremental compiler automatically compiles code when changes are detected.

Which compiler is used in Eclipse?

In summary, Eclipse uses its own JDT core as the Java compiler. The JDT core compiler does not have a JRE. So Eclipse requires user installed JRE to run the .

Does Eclipse use compiler or interpreter?

Eclipse does have it's own compiler, it does not use the JDK compiler (javac). However, Eclipse's compiler produces standard bytecode that complies with the Java Language Specification (JLS) and JVM Specification, so the compiled code it produces will work on any compliant JVM.

Is javac a compiler?

The Java programming language compiler, javac , reads source files written in the Java programming language, and compiles them into bytecode class files.


1 Answers

The relevant parts of the Java Language Specification must be:

§8.1.4: [...] The ClassType must name an accessible (§6.6) class type, or a compile-time error occurs.

§6.6.1: [...] A member (class, interface, field, or method) of a reference (class, interface, or array) type or a constructor of a class type is accessible only if the type is accessible and the member or constructor is declared to permit access:

  • If the member or constructor is declared public, then access is permitted. All members of interfaces are implicitly public. [...]
    • Otherwise, if the member or constructor is declared private, then access is permitted if and only if it occurs within the body of the top level class (§7.6) that encloses the declaration of the member or constructor.

So since the ClassType is not within the body of the class, B.Secret is not accessible at this location, so A<B.Secret> is not accesible, so a compile-time error should occur.

like image 178
Rasmus Faber Avatar answered Oct 02 '22 21:10

Rasmus Faber