Skip to content

Commit

Permalink
Intermittent Class Loading Issues with Java Core Packages
Browse files Browse the repository at this point in the history
  • Loading branch information
snjeza committed Oct 6, 2024
1 parent e90ec8f commit 573c02d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@
import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.WorkingCopyOwner;
import org.eclipse.jdt.core.manipulation.JavaManipulation;
import org.eclipse.jdt.internal.codeassist.impl.AssistOptions;
Expand Down Expand Up @@ -174,6 +177,27 @@ public void start(BundleContext bundleContext) throws Exception {
if (System.getProperty(AssistOptions.PROPERTY_SubstringMatch) == null) {
System.setProperty(AssistOptions.PROPERTY_SubstringMatch, "false");
}
// https://github.com/redhat-developer/vscode-java/issues/3797
Job initializeAfterLoad = new Job("Initialize After Load") {

@Override
protected IStatus run(IProgressMonitor monitor) {
setPriority(Job.SHORT);
try {
JavaCore.initializeAfterLoad(monitor);
} catch (CoreException e) {
logException(e);
try {
JavaCore.rebuildIndex(monitor);
} catch (CoreException e1) {
logException(e);
}
}
return Status.OK_STATUS;
}

};
initializeAfterLoad.schedule();
}

private void disableServices() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ public IStatus run(IProgressMonitor monitor) {
// https://github.com/redhat-developer/vscode-java/issues/3637 - delay registerWatchers
pm.registerWatchers();
debugTrace(">> watchers registered");
// https://github.com/redhat-developer/vscode-java/issues/3797
pm.checkIndexes();
debugTrace(">> indexes checked");
pm.projectsBuildFinished(monitor);
telemetryManager.onBuildFinished(System.currentTimeMillis());
workspaceDiagnosticsHandler.publishDiagnostics(monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,4 +888,8 @@ private void clearDiagnostics(IProject project) throws CoreException {
}
}
}

public void checkIndexes() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
Expand All @@ -67,6 +68,11 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.core.search.TypeNameRequestor;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.launching.AbstractVMInstall;
import org.eclipse.jdt.launching.IVMInstall;
Expand Down Expand Up @@ -703,4 +709,44 @@ public void projectsBuildFinished(IProgressMonitor monitor) {
public boolean isBuildFinished() {
return buildFinished;
}

@Override
public void checkIndexes() {
Job job = new Job(("Check Indexes")) {

@Override
protected IStatus run(IProgressMonitor monitor) {
IJavaProject[] javaProjects = ProjectUtils.getJavaProjects();
if (javaProjects == null || javaProjects.length <= 0) {
return Status.OK_STATUS;
}
SearchEngine engine = new SearchEngine();
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
boolean found[] = { false };
try {
engine.searchAllTypeNames("java.lang".toCharArray(), SearchPattern.R_EXACT_MATCH, "String".toCharArray(), //$NON-NLS-1$
SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.CLASS, scope, new TypeNameRequestor() {
@Override
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
found[0] = true;
}
}, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
} catch (JavaModelException e) {
// search failed
} catch (OperationCanceledException e) {
return Status.CANCEL_STATUS;
}
if (!found[0]) {
try {
JavaLanguageServerPlugin.logInfo("rebuild indexes");
JavaCore.rebuildIndex(monitor);
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e);
}
}
return Status.OK_STATUS;
}
};
job.schedule();
}
}

0 comments on commit 573c02d

Please sign in to comment.