Intellij doesn't see some non-public JDK 9 classes during compilation

9.8k views Asked by At

I have a project that used JDK 8.0 before and now migrating to JDK 9. The project is not modularised yet.

All problems with closing access to private JDK API fixed and I'm able to build the project from the command line using maven, 1.8 language level and JDK 9.

Intellij Idea doesn't highlight any issues at all, JDK 9 set up as a project SDK, but if I try to build the project inside the Idea itself - I get compilation issues in the idea console:

Information:javac 9 was used to compile java sources
Error:(5, 16) java: package sun.misc does not exist
Error:(22, 19) java: cannot find symbol
  symbol:   class Unsafe
  location: class <...>.UnsafeAccessor

So, the project is building fine in CMD using JDK 9 now, the error doesn't make too much sense because sun.misc.Unsafe exists and public in JDK 9, Idea itself doesn't highlight anything, so it understands that everything exists.

What could cause the issue for project building inside the Idea?

Info about the IDEA build:

IntelliJ IDEA 2017.2.5

Build #IU-172.4343.14, built on September 26, 2017

JRE: 1.8.0_152-release-915-b12 x86_64

JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Mac OS X 10.13

2

There are 2 answers

1
mstrap On

For me, the solution was to disable the option Use '--release' option for cross-compilation' (Java 9 and later) in IDEA's Preferences, section Compiler, Java Compiler. JDK 11, IDEA 2020.1.

1
Dmitry Spikhalskiy On

Ok, after I fixed all real issues like adding modules in --add-modules, etc - after that I was able to build the project with language level 9 and JDK 9 in both cmd and Idea. Also I'm able to build the same code base with language level 8 and JDK 8 in both cmd and Idea. And I am able to build it in cmd/mvn with JDK 9 and language level 8, but in Idea - I get a lot of errors like "package sun.misc does not exist". After fixing and checking all of this, it looks like a pure Idea bug for me.