Skip to content

Commit 70e8b8e

Browse files
committed
Fix IllegalArgumentException in getFolder() for ancestor resource dirs
When a resource <directory> resolves to an ancestor of the project (e.g., from a child module, or <directory>..</directory>), projectLocation.relativize(folderPath) produces '..'. Then project.getFolder('..') normalizes to IPath '/', triggering IllegalArgumentException: Path must include project and resource name: /. Add a guard to detect when the relativized path starts with '..' and return the project, so the caller (addResourceDirs) skips the resource directory. This follows the same pattern as the existing workaround. Fixes #1790 Signed-off-by: Changyong Gong <chagon@microsoft.com>
1 parent 7e13152 commit 70e8b8e

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

org.eclipse.m2e.jdt/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-SymbolicName: org.eclipse.m2e.jdt;singleton:=true
5-
Bundle-Version: 2.5.100.qualifier
5+
Bundle-Version: 2.5.200.qualifier
66
Bundle-Localization: plugin
77
Export-Package: org.eclipse.m2e.jdt,
88
org.eclipse.m2e.jdt.internal;x-friends:="org.eclipse.m2e.jdt.ui",

org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,14 @@ protected IContainer getFolder(IProject project, String path) throws CoreExcepti
10031003
}
10041004
if(!project.exists(relativePath) && Files.exists(folderPath)
10051005
&& !ResourcesPlugin.getWorkspace().getRoot().getLocation().toPath().equals(folderPath)) {
1006-
String linkName = projectLocation.relativize(folderPath).toString().replace("/", "_");
1006+
Path relativized = projectLocation.relativize(folderPath);
1007+
if(relativized.startsWith("..")) {
1008+
// Resource directory is outside (ancestor or sibling of) the project.
1009+
// Cannot create a valid linked folder for paths that escape the project tree.
1010+
// Return the project itself so the caller skips this resource directory.
1011+
return project;
1012+
}
1013+
String linkName = relativized.toString().replace("/", "_");
10071014
IFolder folder = project.getFolder(linkName);
10081015
createLinkWithRetry(folder, folderPath.toUri());
10091016
folder.setPersistentProperty(LINKED_MAVEN_RESOURCE, "true");

0 commit comments

Comments
 (0)