Skip to content

Commit

Permalink
fix(utils): Improve robustness in createFolder
Browse files Browse the repository at this point in the history
The `createFolder` util method should not throw an Exception when the
folder already exists.

A first step toward this behavior has been added with
00ca0df

It looks however incomplete as I have a case in my integration of me
where an ResourceException is thrown like below:

```
org.eclipse.core.internal.resources.ResourceException(/procurement-app/target)[374]:
java.lang.Exception: Resource '/procurement-app/target' already exists.
 	at org.eclipse.core.internal.resources.ResourceException.provideStackTrace(ResourceException.java:42)
 	at org.eclipse.core.internal.resources.ResourceException.<init>(ResourceException.java:38)
 	at org.eclipse.core.internal.resources.Resource.checkDoesNotExist(Resource.java:346)
 	at org.eclipse.core.internal.resources.Resource.checkDoesNotExist(Resource.java:333)
 	at org.eclipse.core.internal.resources.Folder.assertCreateRequirements(Folder.java:40)
 	at org.eclipse.core.internal.resources.Folder.create(Folder.java:101)
 	at org.eclipse.core.internal.resources.Folder.create(Folder.java:129)
 	at org.eclipse.m2e.core.internal.M2EUtils.createFolder(M2EUtils.java:61)
 	at org.eclipse.m2e.core.project.configurator.AbstractLifecycleMapping.configure(AbstractLifecycleMapping.java:87)
 	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.lambda$6(ProjectConfigurationManager.java:504)
 	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:394)
 	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:275)
 	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.updateProjectConfiguration(ProjectConfigurationManager.java:498)
 	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.configureNewMavenProjects(ProjectConfigurationManager.java:279)
 	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.lambda$1(ProjectConfigurationManager.java:166)
 	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:394)
 	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:275)
 	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:214)
 	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.importProjects(ProjectConfigurationManager.java:139)
 	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.importProjects(ProjectConfigurationManager.java:130)
```

`374` is the code status for `PATH_OCCUPIED` which is used
[here](https://github.com/eclipse-platform/eclipse.platform/blob/master/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Resource.java#L345)

Also ignoring this status should improve robustness.

Signed-off-by: Romain Bioteau <[email protected]>
  • Loading branch information
rbioteau committed Dec 8, 2023
1 parent 412b8a1 commit 22cfa08
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public static void createFolder(IFolder folder, boolean derived, IProgressMonito
}
} catch(CoreException ex) {
//Don't fail if the resource already exists, in case of a race condition
if(ex.getStatus().getCode() != IResourceStatus.RESOURCE_EXISTS) {
int code = ex.getStatus().getCode();
if(code != IResourceStatus.RESOURCE_EXISTS && code != IResourceStatus.PATH_OCCUPIED) {
throw ex;
}
}
Expand Down

0 comments on commit 22cfa08

Please sign in to comment.