Unable to reference sun.*

Jonathan Gibbons Jonathan.Gibbons at Sun.COM
Sat May 10 07:49:59 PDT 2008


The compiler strongly warns about access to JDK internal classes  
available through JDK 5. It prohibits access any newer JDK internal  

-- Jon

On May 10, 2008, at 5:24 AM, Brendon McLean wrote:

> Hi,
> I've been developing an application on the Mac, but the target  
> audience will be cross platform.  I've just discovered that the  
> application doesn't compile on either Windows or Linux on Java 6.   
> The compiler is complaining that one of the sun.* package I'm  
> importing doesn't exist.  I'm very well aware that linking to these  
> packages is strongly discouraged, but I was wondering whether  
> perhaps it is now enforced?  I have the following file:
> import sun.reflect.misc.MethodUtil;
> public class Test {
>     public static void main(String[] args) throws  
> NoSuchMethodException {
>         MethodUtil.getMethod(Test.class, "main", new Class[] 
> {String[].class});
>     }
> }
> This file will:
> * Compile on all platforms under Java 5
> * Compile on all platforms when compiled in IntelliJ IDEA
> * Compile on Java 6 using javac on the Mac.
> * Fail to compile on Linux and Windows using Java 6 javac.
> The package is located in classes.jar on the Mac and in rt.jar on  
> all other platforms.  In other words, this class should compile  
> without any classpath argument.  Also of interest, is that  
> referencing classes in the com.sun.* packages will work but generate  
> a warning.  I can only conclude that there is something about the  
> Java 6 compiler that is actively preventing me from linking to sun.*  
> packages.
> Is this true?  Or have I missed something so obvious I'm going to  
> have to give up programming and pursue farming?
> Brendon McLean.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20080510/c0cc696e/attachment.html 

More information about the compiler-dev mailing list