Repository navigation
Read the version of a build's formatter once in IntelliJ IDEA, and close its jars - #264
Merged
abashev merged 1 commit intoNov 23, 2026
Conversation
FormatterProvider asks whether the build's formatter is older than the plugin for every Reformat and every Optimize imports, before it asks its cache. computeFormatterVersion answered by opening the jars of the implementation class path with new JarFile until it found the one with the formatter's service, and it closed none of them: each stayed open until the garbage collector got to it, and on Windows a jar the IDE holds open is one that a Gradle build cannot replace or delete. Inside the IDE's JVM a call takes milliseconds, so opening the jars for each one shows. FormatterVersions reads the version with the jar in try-with- resources, and keeps it for a class path for as long as its jars keep their size and time, as InProcessFormatters keeps a formatter: a jar rebuilt in place is read again, and the jars are not opened for every file. The Jar record that keys both moves out of InProcessFormatters. The class path's URIs become paths with Path.of, as FormatterProvider makes them for formatting, rather than with URI.getPath. A formatter jar whose manifest states no Implementation-Version failed every format with a NullPointerException. It has no version now, as one whose version does not parse, and the plugin formats with the formatter bundled with it. A class path without the formatter still fails, with the class path in the message. FormatterVersionsTest writes the jars it reads. A jar overwritten with zeros of its size and time still gives the version read before, and one rebuilt in place gives its new one. On Linux the test looks in /proc/self/fd for the jars once they are read, and fails when the JarFile is not closed. Fixes #258.
abashev
deleted the
abashev/intellij-plugin-every-format-opens-the-builds-fo
branch
November 23, 2026 18:25
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.
Closes #258. Based on
21.X.X; no other open pull request touches these files.FormatterProvider.getasks whether the build's formatter is older than the plugin for every Reformat and every Optimize imports, before it asks its cache. In a project whose.idea/open-java-format.xmlhas animplementationClassPath,computeFormatterVersionanswered by opening the class path's jars withnew JarFileuntil it found the one with the formatter's service, and it closed none of them. Since #259 formats inside the IDE's JVM, a call takes milliseconds, and opening the jars for each one shows.FormatterVersionsreads the manifest with the jar in try-with-resources.InProcessFormatterskeeps a loaded formatter, for up to four class paths. A jar rebuilt in place is read again. TheJarrecord that keys both moves out ofInProcessFormattersinto a file of its own.Path.of, asFormatterProvidermakes them for formatting, rather than withURI.getPath.A project without an
implementationClassPath, which formats with the formatter bundled with the plugin, opened no jar before and opens none now.What changes for users
Implementation-Versionfailed every format with aNullPointerException. It now has no version, as one whose version does not parse, and the plugin formats with the formatter bundled with it.IllegalStateExceptionthat names the class path, where it was aRuntimeExceptionsaying "Couldn't find implementation JAR". Failures are not kept, so such a class path is still read for every call, with its jars closed.Tests
FormatterVersionsTestwrites the jars it reads:/proc/self/fdholds none of the jars once they are read. Only Linux lists a process's open files as paths in the file system, so the test runs on Linux only, which is where CI builds the plugin. I ran the class in aneclipse-temurin:21-jdkcontainer: all five pass, and this one fails with the jar opened outside try-with-resources.With the change, JDK 21:
./gradlew :open-java-format-idea-plugin:checkpasses, 134 tests.Not tried in a running IDE.