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

20,671

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

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.

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

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....'"

1.Project SDK version: enter image description here

2.Project Bytecode version enter image description here

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!

Share:
20,671
Spiff
Author by

Spiff

Updated on August 10, 2021

Comments

  • Spiff
    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
    turbanoff almost 4 years
    You need to compile with the -XDignore.symbol.file option. Where in IntelliJ IDEA I can specify this option?
  • Spiff
    Spiff almost 4 years
    It should be File->Settings->Build Execution Deployment->Java Compiler-> Additional command line parameters
  • turbanoff
    turbanoff almost 4 years
    Nope. It doesn't help. I created bug report youtrack.jetbrains.com/issue/IDEA-241594
  • alexfr
    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
    Kevin Oswaldo over 3 years
    This 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
    Kacper Cichecki over 3 years
    I didn't analyse this option too much. It worked for me so I was happy. What do you mean "cross-compilation"?
  • Kevin Oswaldo
    Kevin Oswaldo over 3 years
    By 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.