Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ: cannot find java.util.Optional

In a new project in IntelliJ I have set up a Java 8 JRE/JDK and language level 8.0.

But for some reason, the IDE cannot find java.util.Optional. The project compiles and works just fine (from within the IDE, too) but code completion does not work.

Any ideas? I'd like to ask a few other users before creating a ticket on their bugtracker...

like image 708
milgner Avatar asked Aug 08 '14 14:08

milgner


Video Answer


2 Answers

Stupid IntelliJ.

I have a SpringBoot project which worked just fine. Then, the next day, when I want to run it, I got this error: Caused by: java.lang.Error: Unresolved compilation problem: The type java.util.Optional cannot be resolved. It is indirectly referenced from required .class files without changing anything!

  • I cleared IntelliJ cache.

Although it was a maven project it was already using JDK8,

  • I have changed the Project Settings, and said (again) to use JDK8,
  • Maven re-import, Cleaned the project, Build->Rebuild project, and it magically worked again
like image 123
razvang Avatar answered Sep 17 '22 15:09

razvang


I finally figured this out. For whatever reason, there was an entry for java.util.Optional in the exlusions under Editor, General, and Auto Import.

Removing that did the trick. No idea how or why it ended up being there. Doesn't sound like anything I would want to do.

like image 31
Jilles van Gurp Avatar answered Sep 19 '22 15:09

Jilles van Gurp