Skip to content

fix: restore interface methods hidden on API 28 - #2122

Merged
edusperoni merged 2 commits into
mainfrom
fix/runtime-types-interface-methods
Nov 17, 2026
Merged

edusperoni merged 2 commits into
mainfrom
fix/runtime-types-interface-methods

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

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.

A type resolved at run time is described by a string whose second line
names its superclass. An interface has none, so the line is just "B ",
and reading the name out of it left the variable holding the previous
token: "I" for a top-level interface, "S" for a nested one. The
interface was then linked to whatever that name resolved to. The
metadata generator names the primitive int and short nodes "I" and "S",
and materializing the "I" node as a class read garbage and crashed
(SIGSEGV in MetadataReader::ReadName).

An interface is resolved at run time when the metadata lacks it and it
is the element type of an array that reaches JS, or the enclosing type
of a nested class resolved at run time.

The base class name is now read into its own variable, and an empty one
leaves the type without a base class.
A class missing from the build-time metadata, such as the non-public
class behind a JDK iterator, is described at run time from the declared
methods of each class in its chain. On Android 9, getDeclaredMethods()
silently leaves out the members of a boot class that the platform's
hidden API lists restrict for apps targeting API 28 or later, even
public methods that implement a public interface. ConcurrentHashMap's
key, value and entry iterators therefore had no hasNext() or remove()
in JS (both are declared on the non-public BaseIterator), and
spliterators such as ArrayList's and HashMap's lacked tryAdvance(),
forEachRemaining() and estimateSize(). Android 10 and later treat such
methods as public API, so the gap was specific to Android 9.

For a boot class path class resolved at run time, getTypeMetadata now
also lists the public interfaces the class implements, with their
super-interfaces, each after its sub-interfaces. Native code installs
the instance methods of those interfaces that the build-time metadata
has on the class's prototype, under every name its class chain does not
already have, reusing each interface's own method entries. A call then
looks the method up on the interface, which is public API: looking it
up on the concrete class is what Android 9 denies, both to reflection
and to JNI lookups made with app code on the stack. An interface the
build-time metadata lacks is skipped without being resolved, so no
member of a non-SDK interface is exposed.

Only names missing from the class chain are added, so nothing that
resolved before resolves differently. On every API level a
runtime-resolved boot class now also has the interfaces' default
methods it does not override, such as Iterator.forEachRemaining() on
ConcurrentHashMap's iterators and Comparator.reversed() on
String.CASE_INSENSITIVE_ORDER. App and library classes are unchanged:
their reflection results are complete.
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change records public interfaces in boot-class metadata and uses static interface metadata to add interface methods to runtime-resolved class prototypes. New tests cover metadata generation and iterator, spliterator, callback, worker, buffer, and overload behavior.

Changes: Runtime Interface Method Resolution

Layer / File(s) Summary
Generate and locate interface metadata
test-app/runtime/src/main/java/com/tns/Runtime.java, test-app/runtime/src/main/cpp/MetadataReader.*
Boot-class metadata now includes public implemented interfaces and inherited public interfaces. MetadataReader adds static-tree lookup and skips base-class resolution when the name is empty.
Add interface methods to runtime prototypes
test-app/runtime/src/main/cpp/MetadataNode.*
MetadataNode uses interface names from runtime metadata to find static interface metadata and add eligible methods to runtime-resolved class prototypes. Existing names on the base prototype, class, or earlier interfaces are preserved.
Verify metadata and interface method behavior
test-app/runtime/src/test/java/com/tns/RuntimeTypeMetadataTest.java, test-app/app/src/main/java/com/tns/tests/IteratorFixtures.java, test-app/app/src/main/assets/app/tests/testJavaIterators.js, test-app/app/src/main/assets/app/tests/runtimeTypeInterfaceMethodsWorker.js
Tests cover interface metadata ordering and iterator-related methods, callback and worker execution, prototype placement, direct-buffer members, and sub-list overload resolution.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Runtime
  participant MetadataReader
  participant MetadataNode
  Runtime->>MetadataReader: provide runtime metadata with interface names
  MetadataReader->>MetadataNode: provide parsed metadata and static interface nodes
  MetadataNode->>MetadataNode: add eligible interface methods to the prototype
Loading
Merge Risk: Minimal · up to 51f10

This change restores public interface methods, such as iterator removal, on runtime-resolved platform classes on Android 9. It adds Java and JavaScript tests for the new behavior. No actionable merge-blocking issue was identified in the supplied material.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: restore interface methods hidden on API 28" matches the main change. The PR adds instance methods from public build-time interfaces to runtime-resolved boot-class classes, so methods s…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: restore interface methods hidden on API 28" matches the main change. The PR adds instance methods from public build-time interfaces to runtime-resolved boot-class classes, so methods such as hasNext() and remove() on ConcurrentHashMap iterators are available on Android 9. The title names the affected API level and the type of fix. The title does not mention the metadata-lookup or the Runtime.java changes, but those are supporting details.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7228595 and 51f10aa.

Files selected for processing: 9

  • test-app/app/src/main/assets/app/tests/runtimeTypeInterfaceMethodsWorker.js
  • test-app/app/src/main/assets/app/tests/testJavaIterators.js
  • test-app/app/src/main/java/com/tns/tests/IteratorFixtures.java
  • test-app/runtime/src/main/cpp/MetadataNode.cpp
  • test-app/runtime/src/main/cpp/MetadataNode.h
  • test-app/runtime/src/main/cpp/MetadataReader.cpp
  • test-app/runtime/src/main/cpp/MetadataReader.h
  • test-app/runtime/src/main/java/com/tns/Runtime.java
  • test-app/runtime/src/test/java/com/tns/RuntimeTypeMetadataTest.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@edusperoni
edusperoni merged commit 749fae8 into main Nov 17, 2026
8 checks passed
@edusperoni
edusperoni deleted the fix/runtime-types-interface-methods branch November 17, 2026 22:56
edusperoni added a commit that referenced this pull request Nov 18, 2026
### Description

Fewer Java binding classes are generated on the device, and prebuilt
ones can get names that survive source edits. The PR has four parts:
fixes that are always on, one new build step that is on by default
(opt-out), and two opt-in features meant to become defaults in a minor
release.

**What is on by default vs opt-in**

| Change | Default | Switch |
|---|---|---|
| Runtime-generation report, `Interface.extend` fixes, interface
dex-cache fixes, JS parser corrections | on | none |
| App module's own Java and Kotlin classes visible to the static binding
generator | on | opt out with `-PskipSbgAppClasses` or
`project.ext.skipSbgAppClasses = true` |
| Content-keyed binding names | off | `-PuseContentBindings` or
`project.ext.useContentBindings = true` in
`App_Resources/Android/app.gradle` |
| `java.lang.reflect.Proxy` for interfaces without a prebuilt class |
off | `android: { interfaceProxies: true }` in the app config |

The app-module step is the one default-on change with real reach, since
`app/build.gradle` ships to every app. It can only add prebuilt
bindings: whatever the generator cannot handle for an app-module type,
and every such binding `javac` rejects, is generated on the device as
before (see "It cannot break a build" below).

#### Always on

- **Runtime-generation report.**
`com.tns.DexFactory.getRuntimeGeneratedClasses()` lists every class that
was not served from the APK, one line each: `<generated|cached|proxy>
<interface|class> <loaded name> <requested name>`. Debuggable apps also
log each one with the `JS` tag. For an interface whose JS object
implements default methods, the requested name is
`com.tns.gen.<Interface>-defaults` and the loaded name is the
`-defaults` class or the proxy.
- **`Interface.extend({...})`.** It was resolved under a per-call-site
name that neither the prebuilt class nor the dex cache uses, so the
class was regenerated and re-injected on every launch even when a
prebuilt class existed. It now resolves to the interface's shared class.
The same change fixes three related defects:
- two `.extend` call sites on one interface got the first site's
constructor, so the second implementation never ran;
  - `.extend` on a nested interface threw `ClassNotFoundException`;
- `.extend` on a non-prebuilt interface in a worker ended in
`StackOverflowError`.

An explicit name that starts with `com.tns.gen.` still loads the
prebuilt class of exactly that name first.
- **Interface dex cache.** The JS method names are no longer part of the
cache key for anonymous interface implementations, because the generated
class does not depend on them. The one exception is the per-call-site
class of an interface extend with extra `interfaces`: it stubs the
default methods its JS object names, so they stay in the key. The dex
and jar are written to a temp file and renamed, and the dex is read in
full, so a killed process cannot leave a truncated file that later
launches trust. The temp file is named after the install thumb only, so
a class name as long as the file system allows still works.
- **JS parser corrections.**
- For TypeScript classes only `X.prototype.name = ...` counts as a
member; static members no longer do.
  - Quoted keys count as members.
- Object-literal accessors are still listed, marked as accessors: they
stay overrides everywhere except in content-keyed classes (see below).
- A constructor of the form `var _this = _super !== null &&
_super.apply(this, arguments) || this;` now gets a source location, so
those classes are prebuilt.
- **Extends with an interface the generator cannot load.** A row whose
base class is on the generator's classpath but one of whose `interfaces`
is not used to stop the generator with "Class not found" and fail the
build. Such a row is now left to the runtime, like a row whose base is
missing, with one line in `runSbg.log`. With content keys on it still
takes part in the collision list and the fragment warning, because the
runtime names its class after the same content. This could already
happen with a library base; the app-module step below makes it easier to
reach. A missing supertype of the base or of a listed interface still
fails the build, as before.
- **Kotlin default arguments.** The generator no longer writes a
constructor for a synthetic one (Kotlin's `DefaultConstructorMarker`
constructor), which `javac` rejected. A JS subclass of a library Kotlin
class with default constructor arguments used to fail the build and now
gets a binding.
- **Self-referencing type bounds.** A base such as `Base<T extends
Base<T>>` made the generator loop forever. It now stops and leaves that
call site to the runtime.
- **One implementation object at several `Interface.extend` call sites**
gets one constructor, as on `main`.
- **Default-method overrides after an extend of a prebuilt interface**
still get a generated `-defaults` class, as on `main`.
- **Duplicate bindings.** Two rows that generate an identical class no
longer fail the build with "File already exists"; the check compared the
file on disk (with its prologue) to the content without it. Different
contents under one name still fail, and the message names both call
sites.

#### App module classes (default on, opt-out)

The static binding generator runs before javac and kotlinc and only
loads classes from `android.jar` and dependency jars. JS subclasses and
implementations of types declared in the app's own Java and Kotlin
sources (`App_Resources/Android/src/main/java`) therefore got no
prebuilt binding and were generated on the device.

A new `compileAppClassesForSbg` task compiles those sources into
`build/nativescript/sbg-app-classes` for the generator only. It runs in
three passes: the Java sources, then the Kotlin sources against the Java
classes that compiled, then the Java sources that need Kotlin.

- **Java** uses the compiler of the JDK Gradle runs on, at the app's
`compileOptions` levels.
- **Kotlin** uses the compiler of the applied Kotlin Gradle plugin, in a
separate JVM, with the module name, JVM target, language and API
versions, jvm-default mode, opt-ins, free arguments and compiler plugins
of the Kotlin compile task of the variant being built. Depending on that
task's output instead is not possible: it compiles the generated
bindings too, so it would form a cycle with the generator.
- **Best-effort.** It cannot fail the build: sources that only compile
with the rest of the build (annotation processors, generated code) are
left out and the rest recompiled, and any other failure logs one line
and leaves those classes to the device.
- **Cost.**
- Java only, measured in a CLI-generated template app: 0.1–0.2 s when it
runs, up to date otherwise.
- An app module without Kotlin sources resolves nothing and starts no
process for the Kotlin pass.
- With Kotlin sources: about 3.5 s when an app source changes (test app,
32 `.kt` and 121 `.java` files), up to date otherwise.

It cannot break a build. Showing these classes to the generator exposes
limits that only library classes could reach before, so every call site
that involves an app-module class (as base, as a listed interface, or
anywhere in their supertypes) is fenced:

- The generator is told which of its inputs hold the app's classes
(`sbg-app-classes.txt`). An error while generating a binding for such a
call site skips that call site with one line in `runSbg.log`; it no
longer ends the run. Call sites that involve no app class are generated
exactly as before.
- The shared class of an app interface is never prebuilt when the
interface has a default method anywhere in its hierarchy, or when a call
site lists a `java.lang.Object` method such as `toString`. A prebuilt
shared class takes those overrides from one call site only; the runtime
decides default methods per instance and never routes Object methods of
such a class to JS.
- `runSbg` then compiles the bindings of those call sites on their own
(`sbg-app-bindings.txt`) and deletes the ones `javac` rejects, for
example a base with a package-private abstract method, a non-public type
in a signature, or a non-static inner class. If it cannot tell a bad
binding from an incomplete classpath (no compiler, the runtime's classes
missing, an error with no file), it deletes nothing and the app's
compile decides, as without this step. Nothing is compiled when no
binding involves an app class. With `-PfailOnCompilationWarnings=true`
the check uses the same lint settings and `-Werror` as the app's
compile.
- The step is skipped for a build whose app module declares an
annotation processor (`annotationProcessor` or `kapt`), because a
processor can change a class's constructors and methods in ways a
compile without it cannot see.
- Only the app's own sources are compiled: a source file found inside a
dependency jar is never compiled into the app classes.
- The forked Kotlin compiler has a 10-minute budget and the retry loops
are capped; running out degrades like any other failure.
- `-PskipSbgAppClasses` (or `=true`) turns the step off; `=false` keeps
it on.

Limits of the step:

- It compiles every source under `src/main/java`; sources the app
excludes from its main source set, or adds from other directories, are
not reflected.
- It passes `javac` only the source level, target level and encoding of
the app's compile.

Kotlin limits:

- A Kotlin class with an internal abstract member, or an abstract member
whose JVM name is not a Java identifier (for example a function taking a
value class), is still generated on the device, as are its subclasses. A
prebuilt binding for it would be Java source that does not compile, or
compiles for one build variant only.
- The same kind of abstract member inherited from a library supertype is
not detected. That is already the case for library classes and Java app
classes.
- Compiler plugin options are not passed on.
- Sources whose dependency chain needs more than five compiler rounds
lose all Kotlin coverage.
- With product flavors, the Kotlin task of the variant named in the
requested tasks is used, otherwise the first one of the build type.

#### Content-keyed binding names (opt-in)

Today the class for a JS subclass of a Java class is named after its
call site: `<Base>_<file>_<md5(path)>_<line>_<col>_<name>`. Any edit
earlier in the same chunk renames it, and Vite gives lazy chunks
content-hashed file names, so one edit renames every class in the chunk.

With the option on, the name is `<Base>_[<name>_]h<16 hex>`, where the
hash is FNV-1a 64 over the base class, the sorted implemented interfaces
and the sorted member names. The naming idea comes from the
NativeScript/runtimes monorepo; the member rule, mode switch and
constructor cache here differ from it.

- **Member set.** The implementation object's own enumerable data
properties whose names are valid Java identifiers, minus `constructor`,
`super`, `__parent`, `__child` and an array-valued `interfaces`.
Accessors are excluded and getters are never invoked. Interface
implementations and dotted/`@JavaProxy` names are not content-keyed and
keep accessor overrides as before.
- **Mode switch.** The generator emits
`com.tns.gen.ContentKeyedBindings` when it runs in this mode, and the
runtime uses content names if and only if that class is in the app, so
the two cannot disagree.
- **Call-site identity is kept.** The stack walk still identifies an
extend call inside a runtime and keys the constructor cache, so a call
site that runs twice still returns its first constructor, and call sites
that share a Java class keep their own constructors and implementation
objects.
- **Safeguard for classes Java creates by name.**
- When two named call sites would get the same content name, both keep
their call-site names and the name goes into a collision list in the
marker class.
- Without that list (code the generator never saw), the first call site
in a runtime owns the name and a later one falls back to its call-site
name.
- Anonymous extends share freely. If Java creates an instance of a
shared anonymous class by class name, the first registered
implementation is used and a warning is logged.
- **Fragment warning.** The build warns about extends of `Fragment`
subclasses without a dotted or `@JavaProxy` name, because Android
re-creates fragments by class name. This starts a warning period before
such classes are required to use `@JavaProxy`.

Behaviour that differs with the option on:

- A runtime-generated class overrides every data member, not only
function-valued ones, to match what the generator writes for the same
name.
- A call site hidden from the generator can now load a prebuilt class if
its content matches one.
- A getter that returns a function is no longer an override in a
content-keyed class.

#### Interface proxies (opt-in)

With the option on, an anonymous interface implementation that has no
prebuilt class gets a `java.lang.reflect.Proxy` instead of a generated
dex. No dex is written or injected into the class loader, no blocking GC
precedes first use, and workers need nothing extra. Prebuilt classes are
still preferred.

The proxy matches the generated class it replaces:

- abstract methods call JS, routed by the owning runtime and object id
held in the handler;
- `equals`, `hashCode` and `toString` keep identity semantics;
- a default method the JS object implements (an own function or
accessor) is called in JS, by the same per-instance record the generated
class uses, including its limit of 64 default method names;
- any other default method runs its Java body through a JNI non-virtual
call;
- a default method desugared for minSdk 21 is abstract at runtime and
goes to JS, as before.

Where no proxy is used:

- If a proxy cannot implement the interface, the class is generated as
before.
- An interface extend with extra `interfaces` keeps its generated
per-call-site class.
- `new I({interfaces: [...]})` gets the proxy of `I` alone, like the
shared class it replaces. Visible differences: `getClass().getName()` is
`$ProxyN`, and no class exists under `com.tns.gen.<Interface>`.

Measured on a debuggable build (API 33 phone):

| | Prebuilt | Runtime dex | Proxy |
|---|---|---|---|
| Java→JS call, no arguments | ~1.5 µs | ~1.4 µs | ~3.0 µs |
| Java→JS call, `int` return | ~2.4 µs | ~2.4 µs | ~4.5 µs |
| First `new` of a never-seen interface | n/a | ~20 ms | ~0.9 ms |

#### Results

These numbers were measured before the rebase onto the current `main`
and before the Kotlin pass.

- **Test app, classes generated at runtime on a clean launch:** 104
before, 24 after the app-module step. What remains is deliberate (call
sites hidden from the generator) or a known parser limit (aliased bases,
non-literal implementation objects).
- **Test app, prebuilt binding classes with content keys on:** 112
instead of 147, from sharing.
- **Content keys off:** the test app's generated bindings were
byte-identical before and after the content-key commits. The always-on
parser and generator fixes do change bindings; see the next section.

#### Behaviour changes with both opt-ins off

- **TypeScript classes without an explicit constructor are now
prebuilt.** Their class is no longer generated on the device, so a
method added to the prototype outside the class body is no longer an
override. Classes with an explicit constructor already behaved this way.
- **Quoted keys and `X.prototype["m"] = ...` are overrides now**, so a
JS method the generator used to miss is called from Java.
- **TypeScript static members are no longer listed as overrides.**
- **A source file the old parser crashed on is parsed in full**, so its
call sites get bindings.
- **App-module types can be prebuilt** (previous section), and library
Kotlin classes with default constructor arguments get bindings.
- **An implementation object reused for a second interface that another
object already extended throws** "This object is used to extend another
class". `main` returned the other object's constructor, which ran the
wrong implementation.

#### Verification

- Full suite on an API 33 arm64 phone, on the final commit: 1773 specs,
0 failures with the defaults, with `-PskipSbgAppClasses`, with
`-PskipSbgAppClasses -PuseContentBindings`, and with all opt-ins on.
Seven commits earlier (1772 specs): the same with the defaults at minSdk
24.
- The build survives the shapes that broke it: the test app now contains
each one (Kotlin default arguments, self-referencing bounds,
package-private abstract methods, non-public types in signatures, an
inner class base, app interfaces with default methods), the net dropped
exactly the five bindings `javac` rejects, and each type still works
from JS.
- Full suite on an API 28 arm64 emulator, on the final commit: 1773
specs, 0 failures with the defaults at minSdk 21 and 24 and with all
opt-ins on. This is `main` with #2118, #2121 and #2122 plus this PR on
Android 9; the three `ConcurrentHashMap` iterator specs that failed
there before #2122 pass.
- `:runtime:testDebugUnitTest` (66), generator JUnit tests (62) and JS
parser tests (10) pass.
- Two independent review passes looked for regressions with both opt-ins
off. The first reproduced the build failures listed above; the second
re-ran those reproductions against the fenced generator, found
library-only bindings byte-identical to `main` on two real bundles, and
its remaining notes are the last four fences.
- Kotlin pass, on the test app: a second build with no change is up to
date; a Kotlin source that does not compile on its own is left out with
one line and the build passes; `-PskipSbgAppClasses` skips both
languages; debug and release Java compile together in one invocation.
- Before the rebase, a CLI-generated app (CLI 9.0.6, core 9.1.4,
webpack) built with the packaged runtime in six configurations and
launched on the phone in three:
  - app Java classes and interfaces were prebuilt;
- a Java class depending on Kotlin was skipped with one info line and
the build passed;
- with content keys on, core's dialog and tab fragments were served from
content-named prebuilt classes;
- no class the app created was generated at runtime because of a name
disagreement.

Not verified:

- API levels other than 28 and 33, and any level below 24, so the proxy
handler's API 24 guard for default methods has not run on a device where
it applies. x86_64 is left to CI.
- The app-module step's fences in a CLI-generated app. In particular,
the trial compile needs the runtime's classes on the generator's
dependency list; that was verified in the test app and read from the
build script for a real app, where a miss makes the check skip itself.
- The Kotlin pass in a CLI-generated app. It ships on by default in the
template every app receives, but has only run in the test app and
scratch projects; the Java pass was checked in a CLI-generated app.
- The Kotlin pass with Kotlin versions other than 2.4.10, with Gradle 9
or AGP 9, and in an app with product flavors (checked in a scratch
project only).
- Release or R8 builds. The existing `-keep class com.tns.gen.**` rule
covers the marker class, but no minified app was built. Proxy costs are
debug-build numbers.
- Vite bundles. No Vite-built Android app was available; the parser
handles the ES5 shape both transforms emit, checked on webpack output
only.
- Fragment re-creation by class name with content keys on in a real app.
Specs cover Java-initiated construction in the test app.

#### Left out on purpose

- **Union of default/Object-method overrides across interface call
sites.** A prebuilt interface class takes those overrides only from the
first call site the parser saw. A union would be worse: on the phone, an
instance without the method throws `AbstractMethodError` for library
default methods. The first-row behaviour is an existing bug this PR does
not change.
- **Caching the `()V` constructor of interface classes.** Unmeasured
gain, and it needs mutable state shared across isolates.
- **Native ES classes from plugins that skip the `@NativeClass`
transform.** The parser still does not see them.

#### Follow-ups

- `@nativescript/core`'s `DialogFragmentImpl` and
`TabFragmentImplementation`, and plugins that declare fragments, need a
`@JavaProxy` name before content keys become the default.
- Flip both opt-ins to defaults in a minor release.
- Generator limits that are now fenced for app-module types but not
fixed, so those call sites stay on the device:
  - self-referencing type bounds (a raw-supertype binding would work);
- bases `javac` rejects a binding for (package-private abstract methods,
non-public types in signatures, non-static inner classes);
  - method names Java cannot spell, wherever the supertype comes from;
- a missing supertype of a library base still fails the build, as on
`main`.
- A prebuilt library interface class still takes its default-method
overrides from the first call site, and the first default-overriding
request in a process decides which class serves the interface. Both
exist on `main`.

### Related Pull Requests

- Closes #2019 together with #2117, which is merged: this PR has the
truncated-jar and single-read items and `Interface.extend` on a nested
interface.
- Rebased onto #2117, #2118, #2121, #2119 and #2122.
- Builds on #2101.

### Does your pull request have [unit
tests](https://github.com/NativeScript/NativeScript/blob/master/running-tests.md)?

Yes.

- Test app specs: runtime-generation report, `Interface.extend` (main
and worker), app-module Java and Kotlin bindings prebuilt and generated,
content-keyed names (hash vectors pinned on both sides, real
bundler-shaped fixtures, sharing, collision fallback, Java-initiated
construction, worker), interface proxies (return types, identity
methods, default methods implemented in JS and not, fallback, threads,
worker, GC), the report's `-defaults` lines, and two extends of one
interface that both implement a default method.
- Generator tests: `ContentKeyTest`, `ContentKeyedGeneratorTest`,
`GetInterfaceNamesTest`.
- Parser tests: a new `content_members` case.

The specs pass with each opt-in on and off, and the default-method and
extra-interface specs from `main` check the proxy path when proxies are
on; CI runs the defaults only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant