Title: fix: restore interface methods hidden on API 28 by edusperoni · Pull Request #2122 · NativeScript/android · GitHub
Open Graph Title: fix: restore interface methods hidden on API 28 by edusperoni · Pull Request #2122 · NativeScript/android
X Title: fix: restore interface methods hidden on API 28 by edusperoni · Pull Request #2122 · NativeScript/android
Description: Description On Android 9, objects of some non-public platform classes were missing public interface methods in JS. The visible case: iterating a java.util.concurrent.ConcurrentHashMap's keySet(), values() or entrySet() failed with iterator.hasNext is not a function. The bug A class that is not in the build-time metadata (non-public JDK classes are not) is described on the device by reflection: the runtime takes each class's own declared methods and walks up the superclass chain. It never looks at the interfaces the class implements. ConcurrentHashMap's iterators get hasNext() and remove() from a non-public base class. On Android 9 those two members are on the hidden-API "dark greylist", and for an app targeting API 28 or higher getDeclaredMethods() drops such members silently, with no log line. So the JS prototype had next but no hasNext. Only Android 9 is affected. Earlier versions have no such filtering, and from Android 10 these members count as public API. It is not specific to ConcurrentHashMap. On Android 9 ArrayList and HashMap spliterators lose tryAdvance, forEachRemaining and estimateSize, and TreeMap sub-map iterators lose forEachRemaining. Every missing member is a method of a public interface the object implements. A lookup on the hidden class is also denied through JNI whenever app Java code is on top of the stack (a callback, a worker), so resolving the method on the concrete class is not a fix. The fix A platform class that is missing from the build-time metadata now also gets the methods of the public interfaces it implements, under every name its class chain does not already have. Those entries are the interface's own, so a call resolves the method on the interface (java.util.Iterator.hasNext), which is public API in every calling context, and dispatches virtually to the hidden implementation. Rules: Additive only. A name that exists anywhere on the class chain is never touched; overload sets are never merged. Platform (boot class path) classes only. App and library classes carry no hidden-API flags and are described exactly as before. Only interfaces in the app's build-time metadata contribute. A public but non-SDK interface is skipped without being resolved. Same on every API level. Among several interfaces declaring a name, the most specific one wins. Static interface methods are never added. The cost is paid once per such class: a few getInterfaces() calls on the Java side, and one name check per interface method when its prototype is built. Nothing is added to any call path or to lookups of classes that already exist. A second commit fixes a defect this exposed: an interface resolved on the device (it has no superclass) was linked to the node of an unrelated type, because its empty base line was read into a stale variable. Materialising that node crashed. Behaviour change on current Android versions Default methods of public interfaces that a non-public platform class does not override become callable, where they were undefined on every API level before. Examples on API 33: forEachRemaining on ConcurrentHashMap and HashMap iterators; reversed and thenComparing on the comparator behind String.CASE_INSENSITIVE_ORDER. Names that existed before stay on the prototype they were on. The added names come from the SDK the app is built against, as for every class in the metadata: a method newer than the device (Enumeration.asIterator on API 28) is a function that throws when called. Verification Cause confirmed on an API 28 emulator: relaxing the device's hidden-API policy makes the three failing specs pass with no code change; reflection from app code shows BaseIterator's declared methods without hasNext/remove, and logcat names the dark greylist when they are looked up individually. Full suite, 1613 specs, 0 failures on the API 28 emulator and on an API 33 phone. On main the API 28 run has the three ConcurrentHashMap failures. Without the fix, 12 of the new specs fail on API 28 and the two that describe the new default-method behaviour fail on API 33. The spec that calls hidden methods first from a callback that app Java code invokes fails on API 28 when the call is made to resolve on the concrete class instead (Accessing hidden method … (dark greylist, JNI)). :runtime:testDebugUnitTest: 36 tests, 0 failures. CI runs API 33 only, so the Android 9 behaviour was verified locally. Not run: other API levels. Not included Hidden public methods of platform classes that belong to no interface, hidden public fields, and hidden overloads whose name already exists on the class chain with another signature. Applying the same rule to app and library classes, which would make interface default methods callable on their non-public implementers and on lambdas too. That changes the shape of far more classes and is left for a separate decision. Does your pull request have unit tests? Yes: new specs in testJavaIterators.js (removal through ConcurrentHashMap iterators, ArrayList and HashMap spliterators, a TreeMap sub-map iterator, default methods on a ConcurrentHashMap iterator and on a private comparator, a call first made from an app-Java callback, a worker, and pins that existing members, app classes, overloads and a direct ByteBuffer are unchanged), plus JVM tests of the interface ordering and of the generated description. Summary by CodeRabbit Bug Fixes Runtime-resolved Java classes now expose applicable public interface methods, improving access to operations such as iterator removal, spliterator methods, default interface methods, and comparator reversal. Method resolution for runtime-resolved sub-lists and interface methods invoked through callbacks and workers is now covered by additional tests.
Open Graph Description: Description On Android 9, objects of some non-public platform classes were missing public interface methods in JS. The visible case: iterating a java.util.concurrent.ConcurrentHashMap's keySet(...
X Description: Description On Android 9, objects of some non-public platform classes were missing public interface methods in JS. The visible case: iterating a java.util.concurrent.ConcurrentHashMap's key...
Opengraph URL: https://github.com/NativeScript/android/pull/2122
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:de2caf17-51fd-0bfa-49be-e66938b98868 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D990:6365:179A097:1F78944:6B0146E9 |
| html-safe-nonce | 315bf4d81a8a6dcece9e576c050e2a5b206436e2a5c16905fc0667a504e18781 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTkwOjYzNjU6MTc5QTA5NzoxRjc4OTQ0OjZCMDE0NkU5IiwidmlzaXRvcl9pZCI6IjE5ODQzNjAyMjkyNTI0NTAwMjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 61212b38f0d59da72943aac595b367f0e88837c7818a08eb751f6379b2f18b0a |
| hovercard-subject-tag | pull_request:5364559288 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/NativeScript/android/pull/2122/files |
| twitter:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| og:image:alt | Description On Android 9, objects of some non-public platform classes were missing public interface methods in JS. The visible case: iterating a java.util.concurrent.ConcurrentHashMap's keySet(... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/android git https://github.com/NativeScript/android.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 29137950 |
| octolytics-dimension-repository_nwo | NativeScript/android |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 29137950 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/android |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width