Title: Proxy dex generation: thread-safety and latent naming bugs (follow-up to #2016) · Issue #2019 · NativeScript/android · GitHub
Open Graph Title: Proxy dex generation: thread-safety and latent naming bugs (follow-up to #2016) · Issue #2019 · NativeScript/android
X Title: Proxy dex generation: thread-safety and latent naming bugs (follow-up to #2016) · Issue #2019 · NativeScript/android
Description: Follow-up to #2016, which makes runtime proxy dex generation a routine path (dev servers keeping @nativescript/core off disk) instead of a rare one. None of the items below block that PR — they are pre-existing defects in the generation ...
Open Graph Description: Follow-up to #2016, which makes runtime proxy dex generation a routine path (dev servers keeping @nativescript/core off disk) instead of a rare one. None of the items below block that PR — they are...
X Description: Follow-up to #2016, which makes runtime proxy dex generation a routine path (dev servers keeping @nativescript/core off disk) instead of a rare one. None of the items below block that PR — they are...
Opengraph URL: https://github.com/NativeScript/android/issues/2019
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proxy dex generation: thread-safety and latent naming bugs (follow-up to #2016)","articleBody":"Follow-up to #2016, which makes runtime proxy dex generation a routine path (dev servers keeping `@nativescript/core` off disk) instead of a rare one. None of the items below block that PR — they are pre-existing defects in the generation path whose exposure it raises, plus small latent bugs found while reviewing it. Intended to be picked up after the ESM/loader work lands.\n\n## Concurrency (the substantive part)\n\nProxy generation has no synchronization, but it is reachable from every runtime's thread (`extend` works on workers; each `Runtime` has its own `DexFactory`, but they share one `dexDir` and the static state below):\n\n- **Silent dex corruption:** `Dump.methodDescriptorBuilder` is a `static final StringBuffer` used as `setLength(0)` → append → `toString()` (runtime-binding-generator, `Dump.java:27`). Two concurrent generations interleave and bake wrong method descriptors into a dex — no error, just a wrong class. `Dump.interfaceImplementedInterfaces[1] = classSignature` (`Dump.java:810,820`) is the same hazard on a static array.\n- **`EACCES` on the loser thread:** `jarFile.exists()` / `setReadOnly()` is a check-then-act pair (`DexFactory.java` jar assembly), and `setReadOnly()` runs on every resolve including cache hits, widening the window. Two threads resolving the same class can leave one opening a 0444 file for write.\n- **Truncated jar persisted read-only:** `fi.read(dexData, 0, dexData.length)` is a single unchecked read (`DexFactory.java`, jar assembly). A short read — e.g. racing a concurrent write of the same dex — zero-pads the jar, which is then made read-only and reused on subsequent launches within the install.\n- **`ConcurrentModificationException` window:** `ClassStorageServiceImpl.retrieveClass` iterates the loaders collection (an `unmodifiableCollection` over a `synchronizedSet`) without holding its lock while `storeClass` → `addClassLoader` mutates it. Every runtime-generated proxy adds a loader, so #2016 directly raises the hit rate (and makes the miss path O(loaders)).\n\nSuggested shape: make `Dump`'s scratch state instance-local (it already is instantiated per `ProxyGenerator`); loop the read or use `Files.readAllBytes`; write the jar to a temp name and atomically rename; synchronize the loaders iteration on the underlying set.\n\n## Latent bugs / nits\n\n- `dexFile.getPath().replace(\".dex\", \".jar\")` replaces **all** occurrences, not the suffix — a package segment containing `.dex` (e.g. `com.example.dexter…` does not, but `….dext` shapes can) mangles both names identically, so it works until two distinct classes mangle to the same jar. Use a suffix strip.\n- `$` → `_` normalization is applied to `className` but never to `baseClassName`, so `Interface.extend({...})` on a **nested** interface computes `classNameToLoad = com.tns.gen.…$…` while the generator emits `…_…` → `ClassNotFoundException`. Pre-existing; sits on the exact line #2016 guards.\n- The two prefix predicates disagree: `ClassResolver` tests `startsWith(\"com.tns.gen\")`, `DexFactory` tests `\"com.tns.gen.\"` (trailing dot). A name like `com.tns.generated.Foo` is a binding class to one and a named proxy to the other.\n- `com.tns.tests.*` is excluded from `isBindingClass`, so a missing test class now falls through to runtime generation instead of throwing — an unintended widening from #2016's fallthrough.\n- There is no name validation at all for dotted extend names (`ValidateExtendArguments` is skipped on the `hasDot` branch), and the extend-name validation specs in `extendClassNameTests.js` are commented out. A named proxy colliding with a derived anonymous name fails with a bare CNFE.\n- `JEnv::InsertClassIntoCache` caches `nullptr` on a failed resolve, and the cache read treats that as a miss forever — a name that fails once and succeeds later re-crosses JNI on every lookup (perf only).\n\n## Explicitly not included\n\nA \"migration sweep\" for legacy un-thumbed cache files was considered and rejected: `dexDir` lives under the app's `code_cache`, which the platform wipes on every app upgrade — the same event that changes the thumb — so pre-#2016 files cannot survive into a post-#2016 install. The only residue is the rare fallback dir (`files/secondary-dexes`, used when `code_cache` is unusable), which is not platform-wiped; not worth machinery.\n","author":{"url":"https://github.com/edusperoni","@type":"Person","name":"edusperoni"},"datePublished":"2026-08-20T01:58:13Z","url":"https://github.com/NativeScript/android/issues/2019"}
| 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 | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:39a05797-c8b0-96af-5f21-45c7f486e9c5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8B8A:1EC9BC:1497925:1A4294C:6B012E39 |
| html-safe-nonce | ad2cf138e9e2cd6f7001006c3d73649bb9236c9cf6e944877e7c7bf24bf23c83 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjhBOjFFQzlCQzoxNDk3OTI1OjFBNDI5NEM6NkIwMTJFMzkiLCJ2aXNpdG9yX2lkIjoiODg0Njg0NDc2Mjc1NDQ2MTI0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8ba36243995b8c2fb2e7f189cf2ec1ff06b840eeed9d7dbb5782823efd36b3b2 |
| hovercard-subject-tag | issue:5198870328 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/NativeScript/android/2019/issue_layout |
| twitter:image | https://opengraph.githubassets.com/132793a20dba5b8a1d745c319e8a2aed3061ad17cc04dd1ab1c209c7854fd437/NativeScript/android/issues/2019 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/132793a20dba5b8a1d745c319e8a2aed3061ad17cc04dd1ab1c209c7854fd437/NativeScript/android/issues/2019 |
| og:image:alt | Follow-up to #2016, which makes runtime proxy dex generation a routine path (dev servers keeping @nativescript/core off disk) instead of a rare one. None of the items below block that PR — they are... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | edusperoni |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| 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 |
| react-app-name | issues |
Links:
Viewport: width=device-width