-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix "Could not determine jdk version for project" error #980
Conversation
Generate changelog in
|
idea-plugin/src/main/java/com/palantir/javaformat/intellij/FormatterProvider.java
Show resolved
Hide resolved
int indexOfVersionDelimiter = version.indexOf('.'); | ||
String normalizedVersion = | ||
indexOfVersionDelimiter >= 0 ? version.substring(0, indexOfVersionDelimiter) : version; | ||
normalizedVersion = normalizedVersion.replaceAll("-ea", ""); | ||
try { | ||
return Integer.parseInt(normalizedVersion); | ||
return OptionalInt.of(Integer.parseInt(normalizedVersion)); | ||
} catch (NumberFormatException e) { | ||
log.error("Could not parse sdk version: {}", version, e); | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning null for an OptionalInt
here seems not ideal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! Fixed, and filed #987 to enable baseline-null-away on this repo
👍 |
Released 2.40.0 |
Fixes #979
Before this PR
See linked issue.
I think this is happening because
ProjectRootManager.getInstance(project).getProjectSdk()
here is sometimes returningnull
. This is allowed by its method contract (there is a@Nullable
marking on the method), so we need to handle it gracefully.After this PR
==COMMIT_MSG==
Fix "Could not determine jdk version for project" error
==COMMIT_MSG==
With this PR, I intend for palantir-java-format to handle this situation by logging a warning and not performing any formatting.
Possible downsides?
If this state persists indefinitely, users may find that formatting no longer works and no longer have the warning in their IDE pointing in this direction. Users rarely view IDE warning logs (in fact I had to search for how to find them when researching for this PR).