Closed xian closed 4 years ago
Experiencing this with OpenJDK 10.0.2 as well
It crashes with OpenJDK 12.0.1
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalAccessException: Can not set static final org.robolectric.internal.IShadow field org.robolectric.shadow.api.Shadow.SHADOW_IMPL to org.robolectric.internal.bytecode.ShadowImpl
at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:223)
at org.robolectric.internal.bytecode.Sandbox.configure(Sandbox.java:84)
at org.robolectric.internal.SandboxTestRunner.configureSandbox(SandboxTestRunner.java:206)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:224)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:100)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: Can not set static final org.robolectric.internal.IShadow field org.robolectric.shadow.api.Shadow.SHADOW_IMPL to org.robolectric.internal.bytecode.ShadowImpl
at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:208)
at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:221)
... 18 more
Caused by: java.lang.IllegalAccessException: Can not set static final org.robolectric.internal.IShadow field org.robolectric.shadow.api.Shadow.SHADOW_IMPL to org.robolectric.internal.bytecode.ShadowImpl
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:76)
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:80)
at java.base/jdk.internal.reflect.UnsafeQualifiedStaticObjectFieldAccessorImpl.set(UnsafeQualifiedStaticObjectFieldAccessorImpl.java:77)
at java.base/java.lang.reflect.Field.set(Field.java:780)
at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:206)
... 19 more
I was able to fix it using JDK from Android Studio instead of OpenJDK: https://github.com/jOOQ/jOOR/issues/39 https://bugs.openjdk.java.net/browse/JDK-8216558
I was able to fix this on Jenkins this by forcing JDK 8:
sh './gradlew -Dorg.gradle.java.home=/usr/java/jdk1.8.0_221/ app:lintDebug'
how to workaround this issue
Any news on this? I'm still getting those warnings and my tests are failing
Any news on this? Seems that gradle might block them in the future so the builds will fail.
Robolectric-4.4-SNAPSHOT crashes on Oracle JDK-13.02:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.robolectric.util.ReflectionHelpers$6 (file:/Users/dkalinowski/.gradle/caches/modules-2/files-2.1/org.robolectric/shadowapi/4.4-SNAPSHOT/23586bcd06ccfb6fd3d52857f4b3dc81fa4ac946/shadowapi-4.4-SNAPSHOT.jar) to method java.lang.ClassLoader.getPackage(java.lang.String)
WARNING: Please consider reporting this to the maintainers of org.robolectric.util.ReflectionHelpers$6
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalAccessException: Can not set static final org.robolectric.internal.IShadow field org.robolectric.shadow.api.Shadow.SHADOW_IMPL to org.robolectric.internal.bytecode.ShadowImpl
at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:223)
at org.robolectric.internal.bytecode.Sandbox.configure(Sandbox.java:84)
at org.robolectric.internal.SandboxTestRunner.configureSandbox(SandboxTestRunner.java:210)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:228)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:96)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: Can not set static final org.robolectric.internal.IShadow field org.robolectric.shadow.api.Shadow.SHADOW_IMPL to org.robolectric.internal.bytecode.ShadowImpl
at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:208)
at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:221)
... 18 more
Caused by: java.lang.IllegalAccessException: Can not set static final org.robolectric.internal.IShadow field org.robolectric.shadow.api.Shadow.SHADOW_IMPL to org.robolectric.internal.bytecode.ShadowImpl
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:76)
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:80)
at java.base/jdk.internal.reflect.UnsafeQualifiedStaticObjectFieldAccessorImpl.set(UnsafeQualifiedStaticObjectFieldAccessorImpl.java:77)
at java.base/java.lang.reflect.Field.set(Field.java:780)
at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:206)
... 19 more
I am guessing it fails, because in Oracle JDK 13 this doens't work:
Field.class.getDeclaredField("modifiers");
https://github.com/powermock/powermock/issues/939
I think there is workaround, which could be used for Robolectric:
https://github.com/powermock/powermock/pull/1010/commits/66ce9f77215bae68b45f35481abc8b52a5d5b6ae#diff-21c1fc51058efd316026f11f34f51c5c
Pretty sure my tests are failing because of this. Please also see the above linked issue. On my Azure Devops Pipeline I tried to manually set the java version to use to zulu-8.jdk (pre-installed on their mac images) but it errors with the same error as below.
My local machine uses the java SDK 12, these are its errors:
I don't have this problem with Oracle JDK 11 nor with OpenJDK 11.
Just confirmed that with zulu-11.jdk the CI is also still having the same issues.
Are you sure? Run it from ./gradlew and check earlier what ./gradlew -v shows just to be sure.
OpenJDK 11 on local mac: Some tests are erroring because of the reflection stuff. JDK8 on local mac: All tests run fine.
Zulu 8 on Azure DevOps, running testBrandXEnvIntegrationDebugUnitTest: Runs fine Zulu 11 on Azure DevOps, running testBrandXEnvIntegrationDebugUnitTest: Runs fine
Default & Zulu 8 on Azure DevOps, running assembleBrandX, testBrandXEnvIntegrationDebugUnitTest: Runs fine except for the latest unit test task, which errors.
brandX means that there is one task for each of the 8 brands. So I'm running 8 assemble tasks and 8 unit test tasks at once.
Caused by: java.lang.IllegalAccessException: Can not set static final org.robolectric.internal.IShadow field org.robolectric.shadow.api.Shadow.SHADOW_IMPL to org.robolectric.internal.bytecode.ShadowImpl
The Java 13 issue is tracked here: #5303
I am trying to figure we still need the logic that uses reflection to remove the final
modifier in ReflectionHelpers.setStatic. The code to do that is ancient and seems to have been introduced in https://github.com/robolectric/robolectric/commit/a81c990109844c663e28659aa3af206f34654de8
In that commit, it seems like it was used to set Build.MODEL
using reflection. This is now done using a shadow:
https://github.com/robolectric/robolectric/blob/master/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBuild.java#L64-L66
One potential issue is that it could break tests that inadvertently use ReflectionHelpers.setStaticField to remove the final
modifier. I am not sure how widespread this is, though.
Warnings are gone in 4.4-alpha-4 with JDK 11.0.8.
Warnings are gone in 4.4-alpha-4 with JDK 11.0.8.
This didn't work for me :(. I am using OpenJDK 11.0.2
@varuntribe try 4.4, it was released a few days ago.
What warning are you seeing? Can you post the stack trace.
4.4 fixed the warnings and exceptions on on our side :+1:
(running on OpenJDK 11.0.8
)
This issue is still happening on JDK 11.0.10. These are the warning I'm seeing:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.robolectric.util.ReflectionHelpers (file:/Users/damiafuentesescote/.gradle/caches/transforms-2/files-2.1/798773a72451440191287a836ecb034a/jetified-shadowapi-4.3.1.jar) to field java.lang.reflect.Field.modifiers
WARNING: Please consider reporting this to the maintainers of org.robolectric.util.ReflectionHelpers
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
JDK version: 11.0.11 (Android Studio default JDK)
I am using this on the test class:
@RunWith(AndroidJUnit4::class) @Config(sdk = [28]) // https://github.com/robolectric/robolectric/pull/6776 class TasksViewModelTest {
so i get this , after the test pass:
Downloading from maven
[Robolectric] com.example.android.architecture.blueprints.todoapp.tasks.TasksViewModelTest.setFilterAllTasks_tasksAddViewVisible: sdk=28; resources=BINARY
Downloading from maven
Called loadFromPath(/system/framework/framework-res.apk, true); mode=binary sdk=28
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.robolectric.util.ReflectionHelpers$6 (file:/Users/<-redacted->/.gradle/caches/transforms-2/files-2.1/51ca475befca9580e803105e026cef34/jetified-shadowapi-4.3.1.jar) to method java.lang.ClassLoader.getPackage(java.lang.String)
WARNING: Please consider reporting this to the maintainers of org.robolectric.util.ReflectionHelpers$6
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Robolectric triggers a warning in openjdk 9: