Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 48283fc

Browse files
committedApr 14, 2020
add defensive checks to fix excess logging
Java Model Exception: Java Model Status [<project> does not exist] at org.eclipse.jdt.internal.core.JavaElement.newNotPresentException(JavaElement.java:575) at org.eclipse.jdt.internal.core.JavaModelManager.getPerProjectInfoCheckExistence(JavaModelManager.java:2528) at org.eclipse.jdt.internal.core.JavaProject.getPerProjectInfo(JavaProject.java:2395) at org.eclipse.jdt.internal.core.JavaProject.getOutputLocation(JavaProject.java:2209) at org.eclipse.jdt.internal.launching.RuntimeClasspathEntry.getLocation(RuntimeClasspathEntry.java:517) at org.codehaus.jdt.groovy.internal.compiler.GroovyClassLoaderFactory.getAbsoluteLocation(GroovyClassLoaderFactory.java:207) at org.codehaus.jdt.groovy.internal.compiler.GroovyClassLoaderFactory.calculateClasspath(GroovyClassLoaderFactory.java:191) Java Model Exception: Java Model Status [<project> does not exist] at org.eclipse.jdt.internal.core.JavaElement.newNotPresentException(JavaElement.java:575) at org.eclipse.jdt.internal.core.JavaModelManager.getPerProjectInfoCheckExistence(JavaModelManager.java:2528) at org.eclipse.jdt.internal.core.JavaProject.getPerProjectInfo(JavaProject.java:2395) at org.eclipse.jdt.internal.core.JavaProject.getRawClasspath(JavaProject.java:2424) at org.codehaus.groovy.eclipse.core.model.GroovyRuntime.findClasspathEntry(GroovyRuntime.java:156) at org.codehaus.groovy.eclipse.actions.AbstractClasspathContainerAction.selectionChanged(AbstractClasspathContainerAction.java:85)
1 parent 21adc2c commit 48283fc

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed
 

‎base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/GroovyClassLoaderFactory.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.eclipse.jdt.core.IClasspathEntry;
4949
import org.eclipse.jdt.core.IJavaProject;
5050
import org.eclipse.jdt.core.JavaCore;
51+
import org.eclipse.jdt.core.JavaModelException;
5152
import org.eclipse.jdt.groovy.core.util.ReflectionUtils;
5253
import org.eclipse.jdt.internal.compiler.Compiler;
5354
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
@@ -204,21 +205,24 @@ private static IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeCla
204205
}
205206

206207
private static String getAbsoluteLocation(IRuntimeClasspathEntry classpathEntry) {
207-
String location = classpathEntry.getLocation();
208+
if (classpathEntry.getType() == IRuntimeClasspathEntry.PROJECT) {
209+
try {
210+
// entry.getLocation() logs if project.getOutputLocation() throws, so test it first
211+
((IJavaProject) JavaCore.create(classpathEntry.getResource())).getOutputLocation();
212+
} catch (NullPointerException | JavaModelException ignore) {
213+
return classpathEntry.getResource().getLocation().toOSString();
214+
}
215+
}
208216

209-
Path path = new Path(location);
210-
if (!path.toFile().exists()) {
217+
String location = classpathEntry.getLocation();
218+
if (!new File(location).exists()) {
219+
IPath path = new Path(location);
211220
IProject project = findProject(path.segment(0));
212221
IResource resource = (path.segmentCount() == 1 ? project : project.getFile(path.removeFirstSegments(1)));
213-
214-
IPath rawLocation = resource.getRawLocation();
215-
if (rawLocation != null) {
216-
location = rawLocation.toOSString();
217-
} else if (resource.getLocation() != null) {
222+
if (resource.getLocation() != null) {
218223
location = resource.getLocation().toOSString();
219224
}
220225
}
221-
222226
return location;
223227
}
224228

‎ide/org.codehaus.groovy.eclipse.core/src/org/codehaus/groovy/eclipse/core/model/GroovyRuntime.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.eclipse.jdt.core.JavaModelException;
3838
import org.eclipse.jdt.groovy.core.util.ArrayUtils;
3939
import org.eclipse.jdt.internal.core.ClasspathEntry;
40+
import org.eclipse.jdt.internal.core.JavaProject;
4041
import org.eclipse.jdt.launching.JavaRuntime;
4142

4243
/**
@@ -153,7 +154,7 @@ public static void removeClasspathEntry(final IJavaProject javaProject, final IC
153154
}
154155

155156
public static Optional<IClasspathEntry> findClasspathEntry(final IJavaProject javaProject, final Predicate<IClasspathEntry> p) throws JavaModelException {
156-
return Arrays.stream(javaProject.getRawClasspath()).filter(p).findFirst();
157+
return JavaProject.hasJavaNature(javaProject.getProject()) ? Arrays.stream(javaProject.getRawClasspath()).filter(p).findFirst() : Optional.empty();
157158
}
158159

159160
//--------------------------------------------------------------------------

‎ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/actions/AbstractClasspathContainerAction.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public void selectionChanged(final IAction action, final ISelection selection) {
6767
if (selection instanceof IStructuredSelection) {
6868
Object selected = ((IStructuredSelection) selection).getFirstElement();
6969
if (selected instanceof IProject) {
70-
IProject projSelected = (IProject) selected;
71-
if (GroovyNature.hasGroovyNature(projSelected)) {
72-
targetProject = JavaCore.create(projSelected);
70+
IProject selectedProject = (IProject) selected;
71+
if (GroovyNature.hasGroovyNature(selectedProject)) {
72+
targetProject = JavaCore.create(selectedProject);
7373
}
7474
} else if (selected instanceof IJavaProject) {
7575
IJavaProject selectedProject = (IJavaProject) selected;

0 commit comments

Comments
 (0)
Please sign in to comment.