-
Notifications
You must be signed in to change notification settings - Fork 515
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 NoSuchFieldError in newer Kotlin plugins #3422
Conversation
try { | ||
val instanceField = KotlinTopLevelTypeAliasFqNameIndex::class.java.getField("INSTANCE") | ||
val instance = instanceField.get(null) | ||
if (instance is KotlinTopLevelTypeAliasFqNameIndex) { |
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.
Should not we throw an exception in the else block in case instance
is of any type other than KotlinTopLevelTypeAliasFqNameIndex
? So if in the future it breaks again, we at least get a proper stacktrace
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.
hmm, I think that case overall is highly unlikely: <T>.INSTANCE
static field exists but is not of type T
.
I guess to make it safer we could reflectively check for Companion
+ getInstance
method though and then throw if neither INSTANCE
field nor $Companion.getInstance
is present?
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.
Fair enough!
} catch (e: Exception) { | ||
/* intentionally empty, fall back to getInstance() call in case of errors */ | ||
} | ||
return KotlinTopLevelTypeAliasFqNameIndex.getInstance() |
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.
And then this could be moved into the catch
block
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.
thanks!
Uses an ugly reflection hack to access the
KotlinTopLevelTypeAliasFqNameIndex
in the newer Kotlin plugin on IDEA 2022.2 / Kotlin 1.7.x.Fixes #3324