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

Wang Weijun weijun.wang at oracle.com
Thu Oct 27 08:59:48 UTC 2016


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