Status Update
Comments
vi...@google.com <vi...@google.com> #2
What steps are needed to reproduce this issue? Frequency of occurrence?
Can you provide the API document where this expected behavior is explained?
Android bug report (to be captured after reproducing the issue)
For steps to capture a bug report, please refer:
Alternate method
Navigate to “Developer options”, ensure “USB debugging” is enabled, then enable “Bug report shortcut”. Capture bug report by holding the power button and selecting the “Take bug report” option.
Note: Please upload the bug report and screenshot to google drive and share the folder to android-bugreport@google.com, then share the link here.
he...@headius.com <he...@headius.com> #3
I believe the code is here, patched for Android to explicitly use a publicLookup to acquire a reference to the primitive identity method. This acquisition is what fails.
he...@headius.com <he...@headius.com> #4
The original change to use this Lookup came many years ago, in this commit that expands several MethodHandles methods for primitive types.
I believe all the lookups that happen within MethodHandles (and possibly similar lookups in the rest of java.lang.invoke) need privileges to be able to self-reflect these non-public API methods. I do not know enough about the new public/private API blocking system to know how that is done.
he...@headius.com <he...@headius.com> #5
The lookup eventually fails here when it tries to acquire a reflected Method for these hidden identity
overloads:
I assume there's a way to mark this access as allowed.
vi...@google.com <vi...@google.com> #6
We have shared this with our product and engineering team and will update this issue with more information as it becomes available.
he...@headius.com <he...@headius.com> #7
What can I do to help get this fixed?
we...@gmail.com <we...@gmail.com> #8
we...@gmail.com <we...@gmail.com> #9
I faced the same problem when I applied Scala language in my project (the following is from Logcat
):
...
Accessing hidden method Ljava/lang/invoke/MethodHandles;->identity(Z)Z (max-target-o, reflection, denied)
...
java.lang.AssertionError: java.lang.NoSuchMethodException: java.lang.invoke.MethodHandles.identity [boolean]
at java.lang.invoke.MethodHandles.makeIdentity(MethodHandles.java:3092)
at java.lang.invoke.MethodHandles.identity(MethodHandles.java:3026)
at java.lang.invoke.MethodHandles.constant(MethodHandles.java:3003)
at scala.reflect.internal.util.AlmostFinalValue.<clinit>(AlmostFinalValue:38)
at scala.reflect.internal.util.StatisticsStatics.<clinit>(StatisticsStatics:24)
at scala.reflect.internal.Symbols$TypeSymbol.<init>(Symbols:3232)
at scala.reflect.internal.Symbols$ClassSymbol.<init>(x:3288)
at scala.reflect.internal.Symbols$ModuleClassSymbol.<init>(x:3453)
at scala.reflect.internal.Symbols$PackageClassSymbol.<init>(x:3502)
at scala.reflect.internal.Mirrors$Roots$RootClass.<init>(x:308)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anon$2.<init>(x:81)
at scala.reflect.runtime.JavaMirrors$JavaMirror.RootClass$lzycompute(x:81)
at scala.reflect.runtime.JavaMirrors$JavaMirror.RootClass(x:81)
at scala.reflect.internal.Mirrors$Roots$EmptyPackageClass.<init>(x:332)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anon$4.<init>(x:83)
at scala.reflect.runtime.JavaMirrors$JavaMirror.EmptyPackageClass$lzycompute(x:83)
at scala.reflect.runtime.JavaMirrors$JavaMirror.EmptyPackageClass(x:83)
at scala.reflect.runtime.JavaMirrors$JavaMirror.EmptyPackageClass(x:69)
at scala.reflect.internal.Mirrors$RootsBase.init(x:252)
at scala.reflect.runtime.JavaMirrors.createMirror(x:47)
at scala.reflect.runtime.JavaMirrors.rootMirror(x:54)
at scala.reflect.runtime.JavaMirrors.rootMirror$(x:54)
at scala.reflect.runtime.JavaUniverse.rootMirror$lzycompute(x:30)
at scala.reflect.runtime.JavaUniverse.rootMirror(x:30)
at scala.reflect.runtime.JavaUniverse.rootMirror(x:30)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(x:301)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(x:301)
at scala.reflect.internal.Definitions$DefinitionsClass.init(x:1511)
at scala.reflect.runtime.JavaUniverse.init(x:154)
at scala.reflect.runtime.JavaUniverse.<init>(x:93)
at scala.reflect.runtime.package$.universe$lzycompute(x:29)
at scala.reflect.runtime.package$.universe(x:29)
at hobby.wei.c.reflow.lite.Task$.defKeyVType$lzycompute(x:44)
at hobby.wei.c.reflow.lite.Task$.defKeyVType(x:44)
at com.example.demomaterial3.test1$.$anonfun$testReflow$1(x:54)
at com.example.demomaterial3.test1$$$ExternalSyntheticLambda1.apply$mcV$sp(x:0)
at scala.runtime.java8.JFunction0$mcV$sp.apply(x:23)
at hobby.wei.c.reflow.Reflow$$anon$1$$anon$2.doWork(x:202)
at hobby.wei.c.reflow.Task.exec$(x:168)
at hobby.wei.c.reflow.Task.exec(x:146)
at hobby.wei.c.reflow.Tracker$Runner.run(x:643)
at hobby.wei.c.reflow.Worker$.$anonfun$scheduleBuckets$7(x:187)
at hobby.wei.c.reflow.Worker$$$ExternalSyntheticLambda3.run(x:0)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.NoSuchMethodException: java.lang.invoke.MethodHandles.identity [boolean]
at java.lang.Class.getMethod(Class.java:2937)
at java.lang.Class.getDeclaredMethod(Class.java:2914)
at java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:840)
at java.lang.invoke.MethodHandles.makeIdentity(MethodHandles.java:3090)
at java.lang.invoke.MethodHandles.identity(MethodHandles.java:3026)
at java.lang.invoke.MethodHandles.constant(MethodHandles.java:3003)
at scala.reflect.internal.util.AlmostFinalValue.<clinit>(AlmostFinalValue:38)
...
At the line at hobby.wei.c.reflow.lite.Task$.defKeyVType(x:44)
, i have mede a call to scala.reflect.api.TypeTags.TypeTag
, thus causing the error to appear.
But I have no problem testing on standard jdk17. The Scala version i used is org.scala-lang:scala-reflect:2.12.18
, and the demo project is on:
Please pay attention to this issue.
mi...@google.com <mi...@google.com> #10
What device are you running this on? Can you please attach a bugreport taken soon after that crash?
mi...@google.com <mi...@google.com> #11
Can you please also attach apk you've built?
we...@gmail.com <we...@gmail.com> #12
I'm running on emulator devices both with Pixel_5_API_33
and Pixel_7_Pro_API_34
. And annex is the apk, you can see the Exception
from Logcat
as it does not crash, because it is just a test app.
mi...@google.com <mi...@google.com> #13
I can repro it with your APK though it seems to be working fine in a test project.
Even though
mi...@google.com <mi...@google.com> #14
I am working on a fix, but it seems that the app will crash with
hobby.wei.c.reflow.CodeException: scala.reflect.internal.MissingRequirementError: class scala.Array in JavaMirror with dalvik.system.PathClassLoader[DexPathList
...
12-07 15:58:05.808 2246 2270 E @|ow.Feedback$Log$@d88: at hobby.wei.c.reflow.Task.exec(x:154)
12-07 15:58:05.808 2246 2270 E @|ow.Feedback$Log$@d88: at hobby.wei.c.reflow.Tracker$Runner.run(x:643)
12-07 15:58:05.808 2246 2270 E @|ow.Feedback$Log$@d88: at hobby.wei.c.reflow.Worker$.$anonfun$scheduleBuckets$7(x:187)
12-07 15:58:05.808 2246 2270 E @|ow.Feedback$Log$@d88: at hobby.wei.c.reflow.Worker$$$ExternalSyntheticLambda3.run(x:0)
12-07 15:58:05.808 2246 2270 E @|ow.Feedback$Log$@d88: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
12-07 15:58:05.808 2246 2270 E @|ow.Feedback$Log$@d88: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
12-07 15:58:05.808 2246 2270 E @|ow.Feedback$Log$@d88: at java.lang.Thread.run(Thread.java:1012)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: Caused by: scala.reflect.internal.MissingRequirementError: class scala.Array in JavaMirror with dalvik.system.PathClassLoader[DexPathList
....
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.MissingRequirementError$.signal(x:24)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.MissingRequirementError$.notFound(x:25)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Mirrors$RootsBase.$anonfun$getModuleOrClass$5(x:61)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Mirrors$RootsBase.getRequiredClass(x:61)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Definitions$DefinitionsClass.ArrayClass$lzycompute(x:494)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Definitions$DefinitionsClass.ArrayClass(x:494)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Definitions$DefinitionsClass.arrayType(x:942)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Definitions$DefinitionsClass.$anonfun$JavaRepeatedParamClass$1(x:421)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Definitions$DefinitionsClass.JavaRepeatedParamClass$lzycompute(x:1370)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Definitions$DefinitionsClass.JavaRepeatedParamClass(x:421)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Definitions$DefinitionsClass.syntheticCoreClasses$lzycompute(x:1417)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Definitions$DefinitionsClass.syntheticCoreClasses(x:1414)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Mirrors$RootsBase.init(x:265)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.JavaMirrors.createMirror(x:47)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.JavaMirrors.$anonfun$runtimeMirror$1(x:64)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.JavaMirrors.runtimeMirror(x:62)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.JavaMirrors.runtimeMirror$(x:61)
12-07 15:58:05.814 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.JavaUniverse.runtimeMirror(x:30)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.JavaMirrors$JavaMirror.mirrorDefining(x:607)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.SymbolLoaders$PackageScope.$anonfun$lookupEntry$1(x:148)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.SymbolLoaders$PackageScope$$ExternalSyntheticLambda0.apply(x:0)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.SymbolLoaders$PackageScope.syncLockSynchronized(x:133)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.SymbolLoaders$PackageScope.lookupEntry(x:135)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.tpe.FindMembers$FindMemberBase.walkBaseClasses(x:110)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.tpe.FindMembers$FindMemberBase.searchConcreteThenDeferred(x:75)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.tpe.FindMembers$FindMemberBase.apply(x:55)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Types$Type.$anonfun$findMember$1(x:1043)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Types$Type.findMemberInternal$1(x:1041)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Types$Type.findMember(x:1046)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Types$Type.memberBasedOnName(x:672)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Types$Type.member(x:636)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Mirrors$RootsBase.getRequiredClass(x:55)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(x:301)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(x:301)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.internal.Definitions$DefinitionsClass.init(x:1511)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.JavaUniverse.init(x:154)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.JavaUniverse.<init>(x:93)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.package$.universe$lzycompute(x:29)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.reflect.runtime.package$.universe(x:29)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at hobby.wei.c.reflow.lite.Task$.defKeyVType$lzycompute(x:44)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at hobby.wei.c.reflow.lite.Task$.defKeyVType(x:44)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at com.example.demomaterial3.test1$.$anonfun$testReflow$1(x:54)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at com.example.demomaterial3.test1$$$ExternalSyntheticLambda1.apply$mcV$sp(x:0)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at scala.runtime.java8.JFunction0$mcV$sp.apply(x:23)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at hobby.wei.c.reflow.Reflow$$anon$1$$anon$2.doWork(x:202)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at hobby.wei.c.reflow.Task.exec$(x:168)
12-07 15:58:05.816 2246 2270 E @|ow.Feedback$Log$@d88: at hobby.wei.c.reflow.Task.exec(x:146)
we...@gmail.com <we...@gmail.com> #15
You try this apk, i -keep class scala.Array
in proguard rules.
mi...@google.com <mi...@google.com> #16
Thanks for reporting this, it was indeed a bug. aosp/2864747 should fix it.
re Caused by: scala.reflect.internal.FatalError: package scala does not have a member Int
. I guess it won't be the only missing class.
we...@gmail.com <we...@gmail.com> #17
Also thank you for fixing this bug, i will solve the rest.
Description
As part of securing non-public APIs, it appears that a critical piece of the MethodHandle API has been blocked without allowing internal classes to use it.
Attempting to use the MethodHandles.constant method, which returns a MethodHandle that returns a constant value, you will see the following error:
The underlying cause is that MethodHandles.makeIdentity appears to reflectively access a restricted MethodHandles.identity variant:
I could not find the exact source that corresponds to MethodHandles.java:2928 here.
I believe this access of MethodHandles.identity should be allowed, or perhaps the implementation of MethodHandles.makeIdentity needs to be updated to a version that does not reflectively access (via Lookup) the identity method.
Note this also affects other java.lang.invoke classes that depend on the public MethodHandles.identity; specifically, the SwitchPoint class uses this call path in its class initialization, so this restriction prevents SwitchPoint from being loaded at all.
This was discovered while updating JRuby and its Android framework "Ruboto" for Android level 33. JRuby uses invokedynamic and method handles extensively.