How to compile code calling unexpected classes to an older release?

Claes Redestad claes.redestad at oracle.com
Thu Oct 27 09:14:36 UTC 2016


Hi,

"-XDignore.symbol.file -source 8 -target 8" can get your code to compile 
(add -nowarn or set a valid bootclasspath to get rid of the warning).

So, it seems --release 8 has issues with internal classes not visible to 
javac in 9?

/Claes

On 2016-10-27 10:59, Wang Weijun wrote:
> I have a program like this:
>
> public class A1 {
>     public static void main(String[] args) throws Exception {
>         new sun.security.util.HexDumpEncoder()
>                 .encodeBuffer(new byte[16], System.out);
>     }
> }
>
> and I want to compile it to jdk8 using javac in jdk9.
>
> It fails with
>
> $ javac --release 8 A1.java
> A1.java:7: error: package sun.security.util does not exist
>         new sun.security.util.HexDumpEncoder()
>                              ^
> 1 error
>
> Same error if I added "--add-exports java.base/sun.security.util=ALL-UNNAMED", although I think that should be useless in this case.
>
> Is there a way to do it?
>
> Thanks
> Max
>
> P.S. I cannot just use javac from jdk8 because this is meant to be a jtreg test and the test might launch an earlier version of VM to execute itself again, and specifying -compilejdk:$JDK8 shows other failures (--class-path not recognizable).
>
>



More information about the compiler-dev mailing list