Skip to content

Commit

Permalink
add defensive checks to fix excess logging
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
eric-milles committed Apr 14, 2020
1 parent 21adc2c commit 48283fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.groovy.core.util.ReflectionUtils;
import org.eclipse.jdt.internal.compiler.Compiler;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
Expand Down Expand Up @@ -204,21 +205,24 @@ private static IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeCla
}

private static String getAbsoluteLocation(IRuntimeClasspathEntry classpathEntry) {
String location = classpathEntry.getLocation();
if (classpathEntry.getType() == IRuntimeClasspathEntry.PROJECT) {
try {
// entry.getLocation() logs if project.getOutputLocation() throws, so test it first
((IJavaProject) JavaCore.create(classpathEntry.getResource())).getOutputLocation();
} catch (NullPointerException | JavaModelException ignore) {
return classpathEntry.getResource().getLocation().toOSString();
}
}

Path path = new Path(location);
if (!path.toFile().exists()) {
String location = classpathEntry.getLocation();
if (!new File(location).exists()) {
IPath path = new Path(location);
IProject project = findProject(path.segment(0));
IResource resource = (path.segmentCount() == 1 ? project : project.getFile(path.removeFirstSegments(1)));

IPath rawLocation = resource.getRawLocation();
if (rawLocation != null) {
location = rawLocation.toOSString();
} else if (resource.getLocation() != null) {
if (resource.getLocation() != null) {
location = resource.getLocation().toOSString();
}
}

return location;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.groovy.core.util.ArrayUtils;
import org.eclipse.jdt.internal.core.ClasspathEntry;
import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jdt.launching.JavaRuntime;

/**
Expand Down Expand Up @@ -153,7 +154,7 @@ public static void removeClasspathEntry(final IJavaProject javaProject, final IC
}

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

//--------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public void selectionChanged(final IAction action, final ISelection selection) {
if (selection instanceof IStructuredSelection) {
Object selected = ((IStructuredSelection) selection).getFirstElement();
if (selected instanceof IProject) {
IProject projSelected = (IProject) selected;
if (GroovyNature.hasGroovyNature(projSelected)) {
targetProject = JavaCore.create(projSelected);
IProject selectedProject = (IProject) selected;
if (GroovyNature.hasGroovyNature(selectedProject)) {
targetProject = JavaCore.create(selectedProject);
}
} else if (selected instanceof IJavaProject) {
IJavaProject selectedProject = (IJavaProject) selected;
Expand Down

0 comments on commit 48283fc

Please sign in to comment.