Fix NPE in resolveClasspath
Caused by unusual projects that do not use JRE classpath container to point to system libraries.
This commit is contained in:
@@ -36,12 +36,14 @@ public class ClasspathUtil {
|
|||||||
private static Set<String> getSystemLibraryPaths(IJavaProject javaProject) {
|
private static Set<String> getSystemLibraryPaths(IJavaProject javaProject) {
|
||||||
try {
|
try {
|
||||||
IClasspathEntry jreContainer = getJreContainer(javaProject.getRawClasspath());
|
IClasspathEntry jreContainer = getJreContainer(javaProject.getRawClasspath());
|
||||||
IClasspathEntry[] resolvedJreEntries = ((JavaProject)javaProject).resolveClasspath(new IClasspathEntry[] {jreContainer});
|
if (jreContainer!=null) {
|
||||||
Set<String> paths = new HashSet<>();
|
IClasspathEntry[] resolvedJreEntries = ((JavaProject)javaProject).resolveClasspath(new IClasspathEntry[] {jreContainer});
|
||||||
for (IClasspathEntry systemEntry : resolvedJreEntries) {
|
Set<String> paths = new HashSet<>();
|
||||||
paths.add(systemEntry.getPath().toString());
|
for (IClasspathEntry systemEntry : resolvedJreEntries) {
|
||||||
|
paths.add(systemEntry.getPath().toString());
|
||||||
|
}
|
||||||
|
return paths;
|
||||||
}
|
}
|
||||||
return paths;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -49,10 +51,12 @@ public class ClasspathUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static IClasspathEntry getJreContainer(IClasspathEntry[] rawClasspath) {
|
private static IClasspathEntry getJreContainer(IClasspathEntry[] rawClasspath) {
|
||||||
for (IClasspathEntry cpe : rawClasspath) {
|
if (rawClasspath!=null) {
|
||||||
if (cpe.getEntryKind()==IClasspathEntry.CPE_CONTAINER) {
|
for (IClasspathEntry cpe : rawClasspath) {
|
||||||
if (cpe.getPath().segment(0).equals(JRE_CONTAINER_ID)) {
|
if (cpe.getEntryKind()==IClasspathEntry.CPE_CONTAINER) {
|
||||||
return cpe;
|
if (cpe.getPath().segment(0).equals(JRE_CONTAINER_ID)) {
|
||||||
|
return cpe;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user