You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IntelliJ plugin: every format opens the build's formatter jars to read the version, and never closes them #258
In a project whose .idea/open-java-format.xml has an implementationClassPath, which the dev.openjavaformat.java-format-idea Gradle plugin writes, the IntelliJ plugin opens formatter jars for every Reformat and every Optimize imports, and never closes them.
FormatterProvider.get builds its cache key with settings.injectedVersionIsOutdated(), so that runs before the cache is asked. It calls PalantirJavaFormatSettings.computeFormatterVersion, which goes through the class path with new JarFile(uri.getPath()) until it finds the jar with META-INF/services/com.palantir.javaformat.java.FormatterService, and reads Implementation-Version from its manifest:
JarFilejar = newJarFile(uri.getPath());
// Identify the implementation jar by the service it produces.if (jar.getEntry("META-INF/services/" + FormatterService.class.getName()) != null) {
No JarFile is closed: each stays open until the garbage collector gets to it.
Open files. The jars pile up between garbage collections. On Windows an open jar cannot be replaced or deleted, so a Gradle build or a cache cleanup can fail on a jar the IDE holds.
A project without an implementationClassPath, which formats with the formatter bundled with the plugin, opens nothing: computeFormatterVersion returns before it.
Proposal
Close each jar: try (var jar = new JarFile(...)).
Remember the version for a class path instead of reading it for every call, keyed by the jars with their size and modification time, as InProcessFormatters of IntelliJ plugin: format in the IDE's JVM, without a new JVM for each call #223 keeps a loaded formatter per set of jars. A jar rebuilt in place is then still noticed.
Activity