java.time.LocalDate not appearing as an import option when using LocalDate in IntelliJ
已回答
When I try to use LocalDate in any java-project only org.joda.time.LocalDate appears as an import. Any other class works fine (Instant, Period, etc) and if I manually write the import (import java.time.LocalDate) it works fine.
Having to manually write the import statements whenever I use LocalDate is starting to be annoying, I cannot for the life of me figure out the reason for IntelliJ to only recognise joda
请先登录再写评论。
java.time not appearing for LocalDate:

java.time appearing as expected for Instant:
Could you please share a sample project to try and reproduce the issue on our end?
Which JDK are you using for the project?
When you hold Alt key and press Enter key two times, do you see both implementations in the popup?
As there only is one available import is chooses that one immediately (cannot alt+enter twice).
I now created a brand new project, wrote LocalDate and tried to alt+enter to import. No available classes appears (as joda is not a dependency on this brand new project). I created a brand new project and did nothing else than define a LocalDate variable do you still want the sample project?
I use OpenJDK Runtime Environment (build 20.0.2+9-78) (deleted every version I had yesterday and reinstalled the sdk as I thought that may have been the issue).
It does not appear, but if I write LocalDate myself IntelliJ it is recognised and used as normally in the class (still the same problem in other classes in the project).
Thanks for the information.
I tried with a new simple project with the same JDK version and couldn't reproduce the issue. It is recognizing LocalDate as java.time.LocalDate. Could you try with another version of JDK, maybe 17, just to be sure it is not caused by JDK instance.
Also, as a general troubleshooting step, try File > Invalidate Caches.. > enable Clear file system cache and Local History option > Invalidate and Restart.
If the issue persists, please share your IDE logs (Help > Collect Logs and Diagnostic Data). You can upload them here: https://uploads.jetbrains.com, just provide the uploaded file ID.
Same results with openjdk-17. Can also mention that this issue has persisted over several months. Thank you for looking into this!
Upload id: 2023_08_28_hYNngqiDeh9Ci81ovxPmoD (file: idea-logs-20230828-08584712364148857422233631.zip)
Thank you for the update and for the log files.
In the end of log file there are entries referring to:
JDK openjdk-17 /Users/<username>/Library/Java/JavaVirtualMachines/openjdk-20.0.2/
. Could you please share screenshots of the following settings:⌘ + ,
) > Build, Execution, Deployment > Compiler > Java CompilerIf you wish, you can also share them via: https://uploads.jetbrains.com.
Upload id: 2023_08_29_25rQTHbh5iLfQGQTxfbeDq (files: image.png and 4 more)
Afterwards I also changed to JDK openjdk-20 to “better match” the installed jdk but with no changes (used corretto the last couple of months with the same results).
It looks like only one file got uploaded
image.png
not sure what happened. Could you please try uploading the rest of screenshots again?In the screenshot you shared the JDK home path for openjdk-17 is:
/Users/<username>/Library/Java/JavaVirtualMachines/openjdk-20.0.2/Contents/Home
:It seems like you have both openjdk-17 and openjdk-20 mapped to the same JDK instance?
I deleted the openjdk-17 and there is no difference when using openjdk-20 (or Amazon Corretto 17 or Amazon Corretto 20 for that matter).




Thanks for the screenshots. Nothing suspicious there.
Have you accidentally excluded
java.time.LocalDate
from auto-import/suggestions by any chance?You can check it in Settings (`⌘ + ,`) > Editor > General > Auto Import > Exclude from auto-import and completion:
YES I HAVE!
Thank you so much! :D