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
By default, IntelliJ IDEA shows all classes, methods, and other elements of the current file. To toggle the elements you want to show, click the corresponding buttons on the Structure tool window toolbar. to show class fields. to have protected class members shown in the tree.
Compile a single file or classOpen the needed file in the editor and from the main menu, select Build | Recompile 'class name' ( Ctrl+Shift+F9 ). Alternatively, in the Project tool window, right-click the class you need and from the context menu, select Recompile 'class name'.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With