Skip to content
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 searching of modifiers field for JDK 8-17 #408

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion utbot-core/src/main/kotlin/org/utbot/common/ReflectionUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ object Reflection {
unsafe = f.get(null) as Unsafe
}

private val modifiersField: Field = Field::class.java.getDeclaredField("modifiers")

// TODO: works on JDK 8-17. Doesn't work on JDK 18
private val modifiersField: Field = run {
val getDeclaredFields0 = Class::class.java.getDeclaredMethod("getDeclaredFields0", Boolean::class.java)
getDeclaredFields0.isAccessible = true
@Suppress("UNCHECKED_CAST")
val fields = getDeclaredFields0.invoke(Field::class.java, false) as Array<Field>
fields.first { it.name == "modifiers" }
}

init {
modifiersField.isAccessible = true
Expand Down