How To Fix “Unrecognized option: –add-opens = jdk.compiler / com.sun.tools.javac.code = ALL-UNNAMED” In Java IntelliJ IDEA

How To Fix “Unrecognized option: –add-opens = jdk.compiler / com.sun.tools.javac.code = ALL-UNNAMED” In Java IntelliJ IDEA

Many developers have run into the error “Unrecognized option: –add-opens = jdk.compiler/com.sun.tools.javac.code = ALL-UNNAMED” in Java IntelliJ IDEA after updating this IDE or importing their projects. This is a problem that you can solve easily with a few steps. Keep reading to find out how.

“Unrecognized option: –add-opens = jdk.compiler/com.sun.tools.javac.code = ALL-UNNAMED” In Java Intellij IDEA

JetBrains frequently introduces new updates to its popular IDE, IntelliJ IDEA. This comprehensive software also supports importing existing Java projects to it. During these processes, however, many have seen this message when trying to run their projects:

Unrecognized option: --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Most of the time, this problem is caused by language-level incompatibility. That means you have set the wrong language level for your projects. This is a common issue when importing them or updating IntelliJ IDEA, which can lead to mismatched configurations.

In this IDE, the language level of a Java project determines the Java version the editor needs to support. This version can be different from the SDK you plan to use, allowing you to target features in a version while using a newer SDK to build your project.

This setting defines how the IDE will assist you in developing the project, including making sure you don’t use new syntax and constructs not available at that language level. You can even set a different language level for each module.

For example, you can use SDK 19 (the newest version as of this writing) while only targeting Java 17, the current long-term support (LTS) version. IntelliJ IDEA’s assistance features will constantly inspect your code and make sure it is compatible with Java 17.

This setting also has an impact on the compilation. Unless you manually change the version of the target bytecode in your setting, it will be the same as your project’s language level.

However, it is your job to set these options (SDK implementation and language level) to the correct values. The error above occurs when this isn’t the case.

In particular, JDK 8 is a popular Java version and still retains widespread use. However, newer versions don’t support illegal reflective access, which is a legal feature in JDK 8.

To help developers migrate that, Oracle introduces a new option into the launcher: –add-opens. You can use it when you have to allow your code to perform deep reflection in newer SDKs.

This option isn’t available in SDK 8 and will produce the error you are seeing. To get rid of it, you should set the language level of your project back to 8.

To change the language level for your project, open it in IntelliJ IDEA.

  • Open File > Project Structure
  • In the setting window, select Project in Project Settings.
  • Change Language level to 8.
  • Click OK to save your configuration.

Summary

The error “Unrecognized option: –add-opens = jdk.compiler/com.sun.tools.javac.code = ALL-UNNAMED” in Java IntelliJ IDEA occurs when you set the wrong language level for your project. Go to the Project Structure settings and roll it back, and your project can run without problems.

Maybe you are interested:

Leave a Reply

Your email address will not be published. Required fields are marked *