ENT-11113 Updating test case for accessing modifier as per JDK17 compatibility

This commit is contained in:
Balwant Kothari 2024-01-15 15:26:10 +05:30
parent d9e0172bf7
commit 49f35aa5ea
No known key found for this signature in database
GPG Key ID: B88831D4B9E013F7
2 changed files with 5 additions and 5 deletions

View File

@ -330,6 +330,7 @@ jar {
tasks.named('test', Test) { tasks.named('test', Test) {
maxHeapSize = "3g" maxHeapSize = "3g"
maxParallelForks = (System.env.CORDA_NODE_TESTING_FORKS == null) ? 1 : "$System.env.CORDA_NODE_TESTING_FORKS".toInteger() maxParallelForks = (System.env.CORDA_NODE_TESTING_FORKS == null) ? 1 : "$System.env.CORDA_NODE_TESTING_FORKS".toInteger()
jvmArgs(['--add-opens', 'java.base/java.lang.reflect=ALL-UNNAMED', '--add-opens', 'java.base/java.util=ALL-UNNAMED'])
} }
publishing { publishing {

View File

@ -7,12 +7,12 @@ import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.After import org.junit.After
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import org.mockito.ArgumentMatchers.contains import org.mockito.ArgumentMatchers.contains
import org.mockito.kotlin.spy import org.mockito.kotlin.spy
import org.mockito.kotlin.verify import org.mockito.kotlin.verify
import org.slf4j.Logger import org.slf4j.Logger
import java.lang.invoke.MethodHandles
import java.lang.reflect.Field import java.lang.reflect.Field
import java.lang.reflect.Modifier import java.lang.reflect.Modifier
import java.nio.file.Files import java.nio.file.Files
@ -71,13 +71,12 @@ class ConfigHelperTests {
} }
@Test(timeout = 300_000) @Test(timeout = 300_000)
@Ignore("TODO JDK17: Modifiers no longer supported")
fun `bad keys are ignored and warned for`() { fun `bad keys are ignored and warned for`() {
val loggerField = Node::class.java.getDeclaredField("staticLog") val loggerField = Node::class.java.getDeclaredField("staticLog")
loggerField.isAccessible = true loggerField.isAccessible = true
val modifiersField = Field::class.java.getDeclaredField("modifiers") val fieldLookup = MethodHandles.privateLookupIn(Field::class.java, MethodHandles.lookup());
modifiersField.isAccessible = true val modifiersField = fieldLookup.findVarHandle(Field::class.java, "modifiers", Int::class.javaPrimitiveType)
modifiersField.setInt(loggerField, loggerField.modifiers and Modifier.FINAL.inv()) modifiersField.set(loggerField, loggerField.modifiers and Modifier.FINAL.inv())
val originalLogger = loggerField.get(null) as Logger val originalLogger = loggerField.get(null) as Logger
val spyLogger = spy(originalLogger) val spyLogger = spy(originalLogger)
loggerField.set(null, spyLogger) loggerField.set(null, spyLogger)