Fix NoClassDefFoundError during analysis of inner classes#1660
Merged
eed3si9n merged 2 commits intosbt:developfrom Mar 21, 2026
Merged
Conversation
966552b to
f614b98
Compare
Fixes sbt/sbt#117 ClassToAPI used Java reflection (c.getClasses, c.getDeclaredClasses) to discover inner classes during post-compile analysis. When an inner class references types not on the classpath (e.g. optional dependencies like JBoss VFS in Spring), these reflection calls throw NoClassDefFoundError, crashing compilation. The fix tries reflection first (preserving exact existing semantics), and falls back to parsing the classfile's InnerClasses attribute when reflection fails. The fallback logs a warning and gracefully skips any inner classes that can't be loaded. This is a revival of sbt#516 by @eed3si9n, rebased onto the current codebase with tests added. Co-Authored-By: Eugene Yokota <[email protected]> Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
f614b98 to
bb0d02e
Compare
Replace getDeclaredClasses/getClasses with classfile InnerClasses attribute parsing. Load each inner class individually so one broken class doesn't take out the rest. Walk parent classfiles for inherited public inner classes. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes sbt/sbt#117 — the oldest open bug in sbt, filed July 22, 2011.
ClassToAPIused Java reflection (c.getClasses,c.getDeclaredClasses) to discover inner classes during post-compile analysis. When an inner class references types not on the classpath (e.g., optional dependencies like JBoss VFS in Spring), these reflection calls throwNoClassDefFoundError, crashing compilation.InnerClassesattribute directly from bytecode instead of using reflection, and gracefully skip any inner classes that can't be loaded via the classloader.ClassToAPI.processsucceeds. Also added parser-level tests forInnerClassesattribute parsing.This is a revival of #516 by @eed3si9n, rebased onto the current codebase with the tests that were requested at the time.
Changes
ClassFile.scalainnerClassesto trait,InnerClassInfocase class,isInnerClassesonAttributeInfoParser.scalaInnerClassesclassfile attribute intoArray[InnerClassInfo]ClassToAPI.scalaParserSpecification.scalaInnerClassesattribute parsingClassToAPISpecification.scalaTest plan
zincClassfile3/testtests pass (26/26)zincApiInfo3/testtests pass (42/42), including existing inner class extraction testsClassToAPI.processdoesn't throw when inner class references a missing typeInnerClassesattribute from JDK classes🤖 Generated with Claude Code