16

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

Dmitry Spikhalskiy
  • 5,379
  • 1
  • 26
  • 40
  • worth mentioning what intelliJ version are you using? – Naman Sep 28 '17 at 20:45
  • @nullpointer added an info about Idea build – Dmitry Spikhalskiy Sep 28 '17 at 20:48
  • And what is the default JAVA_HOME set on your machine? Since I am unable to reproduce this with `2017.2.4` using `sun.misc.Unsafe` in module created new. – Naman Sep 28 '17 at 20:52
  • @nullpointer It's /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home – Dmitry Spikhalskiy Sep 28 '17 at 20:57
  • Can you include an [MCVE](https://stackoverflow.com/help/mcve) please? – jrtapsell Sep 28 '17 at 20:58
  • @DmitrySpikhalskiy `../bin` is something that you might be missing in that case? – Naman Sep 28 '17 at 20:58
  • @jrtapsell If I have - I will resolve the issue or will go to the IDEA bugtracker. So, no for now. – Dmitry Spikhalskiy Sep 28 '17 at 21:00
  • Can you see if the language version in IntelliJ is 1.8 or 1.9 please – jrtapsell Sep 28 '17 at 21:02
  • @jrtapsell It's 1.8 for this post. Can't actually tell if 1.9 resolves anything because with 1.9 I get more same issues on another place in IDEA - ```cannot find symbol: class PostConstruct location: package javax.annotation```. While in pure cmd + maven everything is still fine. – Dmitry Spikhalskiy Sep 28 '17 at 21:15
  • `Unsafe` is `public` and both exported and opened by it's module. The only thing I can think of is that it isn't added to the module graph, so you could try adding `--add-modules jdk.unsupported` as a compiler argument. However, I can't reproduce this error either. – Jorn Vernee Sep 28 '17 at 21:17
  • *cannot find symbol: class PostConstruct location: package javax.annotation*...could you check the project sdk specified once. – Naman Sep 29 '17 at 01:48

2 Answers2

24

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.

mstrap
  • 16,808
  • 10
  • 56
  • 86
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.

Dmitry Spikhalskiy
  • 5,379
  • 1
  • 26
  • 40