Skip to content

Record classfile-derived API for un-loadable Java classes (#837)#1

Closed
jozanek wants to merge 15 commits into
fix/issue-837-inner-class-illegalaccessfrom
feat/classfile-java-api-unloadable
Closed

Record classfile-derived API for un-loadable Java classes (#837)#1
jozanek wants to merge 15 commits into
fix/issue-837-inner-class-illegalaccessfrom
feat/classfile-java-api-unloadable

Conversation

@jozanek

@jozanek jozanek commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Stacked on the sbt#837 crash-fix branch (upstream PR sbt#1714); the diff here is Phase 2 only. To be retargeted to develop for upstream once sbt#1714 merges.

sbt#1714 stops the crash and records products + member-ref + inheritance deps for Java classes that can't be reflectively loaded (e.g. compiled with --add-exports), but records no api.ClassLike for them — so name-hashing can miss dependents when such a class's own public shape changes.

This adds ClassfileToAPI, which builds the class+module api.ClassLike pair directly from the classfile (no reflection) for un-loadable classes, wired into JavaAnalyze via a readClassfileAPI callback (no-op default; production wires it in AnalyzingJavaCompiler).

Conservative fold — deterministic, and only needs to change when the class's public shape changes (need not match the reflection hash byte-for-byte):

  • members (erased descriptor types), parents, static/instance split
  • static final constant values (Singleton encoding, like ClassToAPI)
  • generic Signature (raw), checked exceptions (throws), declared annotation types — folded into a synthetic annotation
  • main-class detection fixed to require the method be named main
  • best-effort: a malformed descriptor or any extraction failure logs + skips, never fails the compile

Out of scope (Phase 3 full classfile-API parser): generic parsing vs raw folding, annotation element values, enum-children modeling.

Tests in ClassfileToAPISpecification (deterministic + shape-sensitive hash, full JavaAnalyze path, static/instance split, malformed-descriptor degradation, main detection).

eed3si9n and others added 13 commits June 17, 2026 01:09
Co-authored-by: eugene yokota <eed3si9n@gmail.com>
…lity (sbt#1720)

Co-authored-by: Jozef Koval <jozef.koval@beone.com>
…exports (sbt#1714)

The crash is ClassToAPI reflectively loading an inner class whose superclass is inaccessible (a module-internal type reached via --add-exports); the IllegalAccessError propagated out and aborted the whole compile.

- ClassToAPI.loadInnerClass now catches IllegalAccessError alongside 

---------

Co-authored-by: Jozef Koval <jozef.koval@beone.com>
@jozanek jozanek force-pushed the feat/classfile-java-api-unloadable branch from eec8263 to f587ec7 Compare June 20, 2026 22:52
@jozanek

jozanek commented Jun 20, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the upstream PR sbt#1729 (rebased onto the post-sbt#1714 develop).

@jozanek jozanek closed this Jun 20, 2026
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.

4 participants