diff --git a/crates/ide-sdk/src/java.rs b/crates/ide-sdk/src/java.rs index 281cb3388..9ff86a706 100644 --- a/crates/ide-sdk/src/java.rs +++ b/crates/ide-sdk/src/java.rs @@ -1629,7 +1629,7 @@ pub fn usages_bundle(data_dir: &Path) -> Option { install_bundle( data_dir, "java-usages", - "1.18.0", + "1.19.0", include_bytes!("../../../java/java-usages/openidea-java-usages.jar"), ) } diff --git a/java/java-usages/MANIFEST.MF b/java/java-usages/MANIFEST.MF index 432e6faa8..b0de4c680 100644 --- a/java/java-usages/MANIFEST.MF +++ b/java/java-usages/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: OpenIDEA Java usages Bundle-SymbolicName: ai.openidea.usages;singleton:=true -Bundle-Version: 1.18.0 +Bundle-Version: 1.19.0 Bundle-RequiredExecutionEnvironment: JavaSE-21 Require-Bundle: org.eclipse.jdt.ls.core,org.eclipse.jdt.core, org.eclipse.jdt.core.manipulation,org.eclipse.core.runtime, diff --git a/java/java-usages/openidea-java-usages.jar b/java/java-usages/openidea-java-usages.jar index 13e77472c..c17b6e429 100644 Binary files a/java/java-usages/openidea-java-usages.jar and b/java/java-usages/openidea-java-usages.jar differ diff --git a/java/java-usages/src/ai/openidea/archives/RefreshArchivesCommand.java b/java/java-usages/src/ai/openidea/archives/RefreshArchivesCommand.java index 1c3137e23..855f7ca3d 100644 --- a/java/java-usages/src/ai/openidea/archives/RefreshArchivesCommand.java +++ b/java/java-usages/src/ai/openidea/archives/RefreshArchivesCommand.java @@ -12,6 +12,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; import org.eclipse.jdt.core.IJavaModel; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IPackageFragmentRoot; @@ -20,12 +21,17 @@ import org.eclipse.jdt.ls.core.internal.IDelegateCommandHandler; import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; import org.eclipse.jdt.ls.core.internal.ProjectUtils; import org.eclipse.lsp4j.TextDocumentIdentifier; +import org.osgi.framework.Bundle; /** * Re-reads library archives replaced in place (a SNAPSHOT installed again keeps its path). The * arguments are the archives' file system paths. Their package fragment roots are closed, which * drops the class files read from the old archive, and jdtls' decompiled sources (cached by class * handle, which a replaced archive keeps) are dropped, so the classes are read again. + * + *

Every call (each project reload) also drops the annotation processors' class loaders: they + * keep the processor path's jars open, so after a dependency on that path was installed again the + * next build failed with "Unable to load annotation processor factory" until jdtls restarted (#4105). */ public final class RefreshArchivesCommand implements IDelegateCommandHandler { @Override @@ -43,6 +49,7 @@ public final class RefreshArchivesCommand implements IDelegateCommandHandler { } IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); model.refreshExternalArchives(null, monitor); + resetAnnotationProcessors(); Set archives = new HashSet<>(); for (Object argument : arguments) { if (argument instanceof String path) archives.add(Path.fromOSString(path)); @@ -62,6 +69,19 @@ public final class RefreshArchivesCommand implements IDelegateCommandHandler { return closed; } + /** JDT APT caches a class loader per project over the factory path; the next build creates new ones. */ + private static void resetAnnotationProcessors() { + try { + Bundle apt = Platform.getBundle("org.eclipse.jdt.apt.core"); + if (apt == null) return; + Class loader = apt.loadClass("org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader"); + Object instance = loader.getMethod("getLoader").invoke(null); + loader.getMethod("resetAll").invoke(instance); + } catch (ReflectiveOperationException | RuntimeException e) { + JavaLanguageServerPlugin.logException("Resetting annotation processors", e); + } + } + /** jdtls keeps decompiled sources in a static per-decompiler LRU with no API to drop them. */ private static void clearDecompilerCache() { try {