19

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
Spiff
  • 3,873
  • 4
  • 25
  • 50
  • 3
    http://www.oracle.com/technetwork/java/faq-sun-packages-142232.html –  Nov 06 '16 at 10:25
  • @rc thanks, great link, i kind of knew that, compiler issues warnings, if i use these imports, But why do I get the does not exist error? – Spiff Nov 06 '16 at 10:28
  • this might help http://stackoverflow.com/questions/28603005/replace-classes-from-sun-security-packages – Naman Nov 06 '16 at 10:32
  • @nullpointer there is the requirement not to use BC. But the main thing here is Intellij and why it does not find a package that's in the rt.jar – Spiff Nov 06 '16 at 12:07
  • @Spiff yes, if possible, I think you should – acdcjunior Mar 13 '18 at 18:35

6 Answers6

36

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

Kacper Cichecki
  • 540
  • 5
  • 12
  • 1
    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 https://stackoverflow.com/a/49618223/7032513 – Kevin Oswaldo Jan 19 '21 at 18:12
  • I didn't analyse this option too much. It worked for me so I was happy. What do you mean "cross-compilation"? – Kacper Cichecki Jan 21 '21 at 11:21
  • 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. – Kevin Oswaldo Jan 22 '21 at 22:09
5

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.

Spiff
  • 3,873
  • 4
  • 25
  • 50
  • _You need to compile with the -XDignore.symbol.file option_. Where in IntelliJ IDEA I can specify this option? – turbanoff May 22 '20 at 12:23
  • It should be File->Settings->Build Execution Deployment->Java Compiler-> Additional command line parameters – Spiff May 22 '20 at 12:45
  • 1
    Nope. It doesn't help. I created bug report https://youtrack.jetbrains.com/issue/IDEA-241594 – turbanoff May 22 '20 at 12:58
  • @turbanoff: Eugene Zhuravlev's comment in the linked issue finally explains the exact reasons why those error messages occur. – alexfr Jul 10 '20 at 20:56
4

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

Tinyiko Chauke
  • 365
  • 2
  • 14
3

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!

avp
  • 2,892
  • 28
  • 34
0

Click on the project and chose Maven->Reload This can solve it as well if deps our out sync

Peter
  • 5,556
  • 3
  • 23
  • 38
0

My computer abruptly gave a blue screen while I was writing code. On going back to the IDE, I got this exception Java Minidumps are not enabled by default on client versions of Windows which I resolved by updating/re-installing JDK.

After resolving the above error, this dependency was no longer visible. I noticed that my IDE was now pointing to the newly updated JDK.

I updated the project's JDK version by going to > File > Project Structure > Project: From here, I selected JDK 1.8.0_65.

Please refer to the screenshot for more clarity. enter image description here

Umar Kayondo
  • 405
  • 4
  • 9