IntelliJ says the package does not exist, But I can access the package

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.enter image description here


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

sun.security.x509.CertAndKeyGen and sun.security.pkcs.PKCS10 - missing in JDK8. Implementation suggestions

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.