IntelliJ says the package does not exist, But I can access the package
Solution 1
This is not an intellij issue.
You need to compile with the -XDignore.symbol.file
option. Some internal packages
are hidden by default unless you add this option to javac.
https://bugs.openjdk.java.net/browse/JDK-7141442
Also the comment of user @user180100 is relevant and important.
The sun.* packages are not part of the supported, public interface.
A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.
Solution 2
I had similar issue with different package:
package sun.security.x509 does not exist
I used java 11 to compile the project.
In my case I had to disable Use '--release' option for cross-compilation
in Java Compiler settings.
Solution 3
Your project SDK version under file>project structure>Project>Project SDK must be the same with your java compiler project bytecode version under file>Build, Execution, Deployment>Compiler>Java Compiler> look for "project bytecode version" right under your checkbox for "use '--release....'"
Solution 4
I had a similar error for a different package.
The packages we use were mapped to a network drive and my credentials to access that mapped drive were expired, so I had re-authenticate and tried with
IntelliJ: File -> Invalidate caches / Restart
OR
$gradle clean build
Hope this helps!
Spiff
Updated on August 10, 2021Comments
-
Spiff over 2 years
I get the error below, but I can find the package in rt.jar. I can see the JDK being used from Project Structure. I'm not sure what's missing.
Error:(6, -1) Play 2 Compiler: C:\user\projects\portal\app\com\example\security\cert\X509Cert.java:6: package sun.security.pkcs10 does not exist import sun.security.pkcs10.*; C:\user\projects\portal\app\com\v\security\cert\GenerateCSR.java:75: cannot find symbol
-
turbanoff almost 4 yearsYou need to compile with the -XDignore.symbol.file option. Where in IntelliJ IDEA I can specify this option?
-
Spiff almost 4 yearsIt should be File->Settings->Build Execution Deployment->Java Compiler-> Additional command line parameters
-
turbanoff almost 4 yearsNope. It doesn't help. I created bug report youtrack.jetbrains.com/issue/IDEA-241594
-
alexfr almost 4 years@turbanoff: Eugene Zhuravlev's comment in the linked issue finally explains the exact reasons why those error messages occur.
-
Kevin Oswaldo over 3 yearsThis did work for me, I haven't have any secondary effects yet. With this option, IntelliJ deduces from project settings when the cross-compilation is needed and automatically applies the --release compiler option for Java 9. according to this answer stackoverflow.com/a/49618223/7032513
-
Kacper Cichecki over 3 yearsI didn't analyse this option too much. It worked for me so I was happy. What do you mean "cross-compilation"?
-
Kevin Oswaldo over 3 yearsBy default, classes are compiled against the bootstrap of the platform that javac shipped with (The low code that the JVM needs to run). But javac also supports cross-compiling, where classes are compiled against a bootstraps of a different Java platform implementation. I think my project wouldn't even be able to compile if this would be an issue so I think this solution is fine.