paparazzi icon indicating copy to clipboard operation
paparazzi copied to clipboard

java.lang.NoSuchFieldException: modifiers

Open sobaya-0141 opened this issue 2 years ago • 9 comments

Description #171 Related OpenJDK Runtime Environment Zulu18.32+11-CA (build 18.0.2+9)

Steps to Reproduce ./gradlew recordPaparazziDebug

java.lang.NoSuchFieldException: modifiers
	at java.base/java.lang.Class.getDeclaredField(Class.java:2642)
	at app.cash.paparazzi.Paparazzi.forcePlatformSdkVersion(Paparazzi.kt:388)
	at app.cash.paparazzi.Paparazzi.prepare(Paparazzi.kt:148)
	at app.cash.paparazzi.Paparazzi$apply$statement$1.evaluate(Paparazzi.kt:122)
	at app.cash.paparazzi.agent.AgentTestRule$apply$1.evaluate(AgentTestRule.kt:17)
	at com.google.testing.junit.testparameterinjector.PluggableTestRunner$ContextMethodRule$1.evaluate(PluggableTestRunner.java:420)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
	at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:577)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at jdk.proxy1/jdk.proxy1.$Proxy2.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
	Suppressed: java.lang.reflect.InaccessibleObjectException: Unable to make private native java.lang.reflect.Field[] java.lang.Class.getDeclaredFields0(boolean) accessible: module java.base does not "opens java.lang" to unnamed module @4b8f7a19
		at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
		at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
		at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:200)
		at java.base/java.lang.reflect.Method.setAccessible(Method.java:194)
		at app.cash.paparazzi.Paparazzi.forcePlatformSdkVersion(Paparazzi.kt:398)

sobaya-0141 avatar Sep 02 '22 23:09 sobaya-0141

what version are you using? I think this should be fixed on master with https://github.com/cashapp/paparazzi/pull/530, but it's unreleased, so I'd like to confirm whether there's work to be done here, or if this can be closed out.

jrodbx avatar Sep 04 '22 03:09 jrodbx

I am using version 1.0.0

I believe this problem is occurring with a specific Java distribution. Because it occurred with Zulu18.32 and not with Temurin-18.0.2.1+1.

sobaya-0141 avatar Sep 04 '22 14:09 sobaya-0141

Mind confirming the issue?

jrodbx avatar Sep 05 '22 05:09 jrodbx

We are seeing a similar regression in Paparazzi as of this weekend. Reverting to a previous snapshot of Paparazzi did not resolve the issue for us but reverting to v1.0.0 did resolve it.

DavidBrunow avatar Sep 07 '22 16:09 DavidBrunow

We are seeing a similar regression in Paparazzi as of this weekend. Reverting to a previous snapshot of Paparazzi did not resolve the issue for us but reverting to v1.0.0 did resolve it.

@DavidBrunow 1.0.0 is the newest version of Paparazzi no? Did you mean something else?


I am also getting this error, and I tried with Temurin-18.0.2.1+1 and 19.

michaelcspeed avatar Oct 03 '22 14:10 michaelcspeed

Seeing this as well

mshearer123 avatar Jul 24 '23 10:07 mshearer123

Based on this answer there's workaround yet for Java 18+. However, following the future of the commit mentioned in #205's comment, they migrated to using Unsafe in https://github.com/powermock/powermock/pull/1026 which may or may not work on Java 18 and 19.

As a workaround, you can try to set your Test task's toolchain to something lower:

tasks.withType(Test).configureEach {
    javaLauncher = javaToolchains.launcherFor {
        languageVersion = JavaLanguageVersion.of(11)
    }
}

TWiStErRob avatar Jul 24 '23 11:07 TWiStErRob

Based on this answer there's workaround yet for Java 18+. However, following the future of the commit mentioned in #205's comment, they migrated to using Unsafe in powermock/powermock#1026 which may or may not work on Java 18 and 19.

As a workaround, you can try to set your Test task's toolchain to something lower:

tasks.withType(Test).configureEach {
    javaLauncher = javaToolchains.launcherFor {
        languageVersion = JavaLanguageVersion.of(11)
    }
}

Thanks, this has fixed the modifiers error, but now I get

 kotlin.UninitializedPropertyAccessException: lateinit property sessionParamsBuilder has not been initialized
        at app.cash.paparazzi.Paparazzi$Companion.getSessionParamsBuilder$paparazzi(Paparazzi.kt:626)
        at app.cash.paparazzi.Paparazzi.prepare(Paparazzi.kt:162)
        at app.cash.paparazzi.Paparazzi$apply$statement$1.evaluate(Paparazzi.kt:124)
        at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)

Seems to be just locally (macOS). On our CI with the same java it works.

mshearer123 avatar Aug 01 '23 15:08 mshearer123

Note, there might be a better workaround than toolchains: https://github.com/cashapp/paparazzi/pull/1030/files

Re sessionParamsBuilder, https://github.com/cashapp/paparazzi/issues/486 looks related, but not necessarily the same problem. If that doesn't help, please consider opening a separate issue to keep this one focused on modifiers.

TWiStErRob avatar Aug 01 '23 19:08 TWiStErRob