Repository navigation
Switch Spotless's Java formatter from eclipse() to googleJavaFormat() - #9
Merged
Merged
Conversation
diffplug/spotless#2850 is a currently-open upstream bug: Spotless's removeUnusedImports() step throws NoClassDefFoundError under the Gradle configuration cache on JDK 21/25 when used standalone (i.e. without googleJavaFormat() also configured) -- reproducible on this project with a fresh daemon and a fresh config-cache, on every file, including a `clean build` in one invocation (the documented trigger). Empirically, keeping removeUnusedImports() but adding googleJavaFormat() alongside it avoids the crash entirely: Spotless routes unused-import removal through GoogleJavaFormatStep's own integrated code path instead of RemoveUnusedImportsStep's standalone one, which is what's actually broken. This means accepting google-java-format's own constraints, most notably its hardcoded column limit -- it has no configuration option for this by deliberate upstream policy (see google/google-java-format#425 and #57, both rejected). GOOGLE style is fixed at 100 columns (AOSP at 90); this project moves from its former custom 120-column eclipse() config to the 100-column GOOGLE default, which is the closer match to the existing 2-space-indent convention. Changes: - build.gradle: googleJavaFormat('1.28.0').reflowLongStrings() replaces eclipse().configFile(...); reflowLongStrings splits long string literals across lines instead of leaving them over the column limit (found one such case in DType.java). - config/checkstyle/checkstyle.xml: LineLength's max lowered from 120 to 100 to match; the JavadocParagraph.allowNewlineParagraph=true deviation is removed since it existed only to match eclipse()'s <p>-on-its-own-line Javadoc output, and google-java-format's own <p> placement already satisfies the stricter upstream default (verified: checkstyle passes with the deviation removed). AbbreviationAsWordInName remains the one documented deviation. - config/spotless/eclipse-java-google-style-120col.xml deleted (no longer referenced anywhere). - README.md's code style section updated to match. - Ran spotlessApply across all three modules: 39 files reformatted to google-java-format's style, no manual edits needed beyond the above config changes. Verified: `./gradlew clean build` (the exact sequence that used to crash) now passes end to end -- Spotless, Checkstyle, jmlx-core/jmlx-ffi tests, jmlx-ffi's forked loaderGuardTest, and :jmlx-examples:run on real GPU hardware. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
perNyfelt
added a commit
that referenced
this pull request
Aug 13, 2026
Pure spotlessApply output, no logic changes: main picked up PR #9's switch from eclipse() to googleJavaFormat() while this branch was still open, so the files this branch touches needed reformatting to match. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
perNyfelt
added a commit
that referenced
this pull request
Aug 13, 2026
…on, freeze ordering Bugs: - Fn's constructor rollback only closed the arena on failure, never freeing plainClosure/vgClosure -- despite the commit message on the previous fix claiming otherwise. mlx_closure_new_func heap-allocates a std::function that only mlx_closure_free releases; arena.close() only reclaims the 8-byte struct holding its ctx pointer, so the std::function and everything it captured leaked on this path. It also closed the arena while a closure could still be holding the (now-dangling) upcall stub pointer -- exactly the ordering close()'s own javadoc calls load-bearing, inverted. Fixed by hoisting plain/vg to locals declared before the try, and freeing both (vg then plain, matching close()'s order) before closing the arena in the catch block. mlx_closure_free/ mlx_closure_value_and_grad_free both no-op on a null ctx, so no extra ctx guard is needed beyond the plain "was this local ever assigned" check. - Missing NativeLoader.clearLastNativeError() before mlx_closure_new_func, the statusless call whose failure is detected via a null-ctx check. Without clearing first, NativeOps.nativeFailure could attach a stale message from an unrelated earlier statusless failure -- the exact misattribution NativeOps.checked's own javadoc documents, and the same pattern every other null-ctx site in the codebase already follows (MLX.java, MLXRandom.java). Suggestions: - ModuleGrad's constructor still froze tree before the one remaining fallible step (MLXGrad.valueAndGrad, which can throw), leaving tree permanently frozen if that call fails -- the same defect as before, just a narrower window. this::body is never invoked during construction, so freeze() can safely move to the very end. - unpackVector went back to returning MLXArray[] instead of List<MLXArray>: the List-returning version only existed to feed Result's List-typed fields, but the upcall path immediately undid it with a toArray() round-trip. Now the array is used directly in onClosureInvoked, and List.of(...) wraps it only at apply()'s two Result-construction sites. - gradle.properties' org.gradle.jvmargs addition (from the previous review round) is removed entirely rather than pinning explicit memory defaults alongside it, per the reviewer's flag that it silently replaces Gradle's default daemon JVM args wholesale. Since main switched Spotless to googleJavaFormat() (PR #9), the removeUnusedImports NoClassDefFoundError this was working around no longer reproduces at all -- verified with a fresh daemon and a fresh configuration cache -- so the whole workaround, memory-config risk included, is simply unnecessary now. Also includes rebasing this branch onto main (which merged PR #9 while this was open) and the resulting spotlessApply reformat of the files this branch touches, kept as a separate preceding commit. Verified: `./gradlew clean build` passes end to end; MLXGradTest (11/11) and ModuleGradTest (5/5) pass; :jmlx-examples:run verified on GPU hardware. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
6 tasks done
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
removeUnusedImports()step throwsNoClassDefFoundErrorunder the Gradle configuration cache on JDK 21/25 when used standalone. AddinggoogleJavaFormat()alongside it routes unused-import removal through a different, working code path.eclipse()config to google-java-format's 100-column GOOGLE style default.build.gradle:googleJavaFormat('1.28.0').reflowLongStrings()replaceseclipse().configFile(...).config/checkstyle/checkstyle.xml:LineLengthmax lowered 120→100; removed theJavadocParagraph.allowNewlineParagraph=truedeviation (only existed to matcheclipse()'s Javadoc output — google-java-format's own<p>placement already satisfies the stricter upstream default).config/spotless/eclipse-java-google-style-120col.xml.spotlessApplyacross all three modules (39 files reformatted).Test plan
./gradlew clean build(the exact sequence that used to crash) passes end to end./gradlew spotlessCheck/checkstyleMain/checkstyleTest/checkstyleTestFixturesall pass:jmlx-core:test,:jmlx-ffi:test,:jmlx-ffi:loaderGuardTestall pass:jmlx-examples:run(HelloMLX) verified end-to-end on real GPU hardware🤖 Generated with Claude Code