Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » IFolder.create throws ResourceException (already exists)
IFolder.create throws ResourceException (already exists) [message #244631] Mon, 18 June 2007 19:12 Go to next message
Eclipse UserFriend
Originally posted by: monikakrug.expires-2007-06-30.arcornews.de

IJavaProject javaProject = JavaCore.create(project);
IFolder binDir = project.getFolder("bin");
if (!binDir.exists())
{
binDir.create(false /*force*/, true /*local*/, null /*monitor*/);
}

The line "binDir.create" occasionally (usually in 1 or 2 out of 34
testcases, but sometimes in none) throws this exception:
org.eclipse.core.internal.resources.ResourceException: Resource
/Project03/bin already exists.

I don't get it. I check if it exists and only call create if it doesn't.
There is no other thread running that could be creating the directory
just in the moment between the check and the create call.

What could be causing this?

Monika.
Re: IFolder.create throws ResourceException (already exists) [message #244646 is a reply to message #244631] Tue, 19 June 2007 06:05 Go to previous messageGo to next message
Eclipse UserFriend
Monika Krug wrote:

> IJavaProject javaProject = JavaCore.create(project);
> IFolder binDir = project.getFolder("bin");
> if (!binDir.exists())
> {
> binDir.create(false /*force*/, true /*local*/, null /*monitor*/);
> }
>
> The line "binDir.create" occasionally (usually in 1 or 2 out of 34
> testcases, but sometimes in none) throws this exception:
> org.eclipse.core.internal.resources.ResourceException: Resource
> /Project03/bin already exists.
>
> I don't get it. I check if it exists and only call create if it
> doesn't. There is no other thread running that could be creating the
> directory just in the moment between the check and the create call.
>
> What could be causing this?

Out of the box (i.e. if not changed by the user) the 'bin' folder is the
output folder where JDT Core puts its stuff (e.g. class files). This
folder belongs to JDT Core and they delete, create and modify it. You
should not mess with that folder unless you really want to run into
trouble ;-)

Dani

>
> Monika.
Re: IFolder.create throws ResourceException (already exists) [message #244651 is a reply to message #244646] Tue, 19 June 2007 06:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: monikakrug.expires-2007-06-30.arcornews.de

Daniel Megert schrieb:

> Out of the box (i.e. if not changed by the user) the 'bin' folder is the
> output folder where JDT Core puts its stuff (e.g. class files). This
> folder belongs to JDT Core and they delete, create and modify it. You
> should not mess with that folder unless you really want to run into
> trouble ;-)

So when I create a Java project, does the bin folder get created
automatically? The book I am reading ("Contributing to Eclipse:
Principles, Patterns, and Plug-ins") shows the process of creating a
Java project: creating the project, setting the Java nature, creating
the Java project, adding the JRE container to the classpath - then goes
on with creating the bin folder, adding it to the classpath, creating
the src folder, adding it to the build path. But the book is on Eclipse
2. Has this changed in version 3?

Monika.
Re: IFolder.create throws ResourceException (already exists) [message #244662 is a reply to message #244651] Tue, 19 June 2007 07:22 Go to previous messageGo to next message
Eclipse UserFriend
Monika Krug wrote:

> Daniel Megert schrieb:
>
>> Out of the box (i.e. if not changed by the user) the 'bin' folder is
>> the output folder where JDT Core puts its stuff (e.g. class files).
>> This folder belongs to JDT Core and they delete, create and modify
>> it. You should not mess with that folder unless you really want to
>> run into trouble ;-)
>
>
> So when I create a Java project, does the bin folder get created
> automatically? The book I am reading ("Contributing to Eclipse:
> Principles, Patterns, and Plug-ins") shows the process of creating a
> Java project: creating the project, setting the Java nature, creating
> the Java project, adding the JRE container to the classpath - then
> goes on with creating the bin folder, adding it to the classpath,
> creating the src folder, adding it to the build path. But the book is
> on Eclipse 2. Has this changed in version 3?

I guess it only tries to explain what goes on behind the scenes. If you
want to create a Java project you don't need to create the output
folder(s) yourself. That was always like that. If you do want to create
them you must ensure not to get in conflict with JDT Core.

Dani

>
> Monika.
Re: IFolder.create throws ResourceException (already exists) [message #244698 is a reply to message #244662] Tue, 19 June 2007 12:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: monikakrug.expires-2007-06-30.arcornews.de

Daniel Megert schrieb:

> I guess it only tries to explain what goes on behind the scenes. If you
> want to create a Java project you don't need to create the output
> folder(s) yourself. That was always like that. If you do want to create
> them you must ensure not to get in conflict with JDT Core.

I looked at my source code again, it actually is like this:

IFolder binDir = project.getFolder("bin");
if (!binDir.exists())
{
binDir.create(true /* force */, true /* local */, null);
}
IPath binPath = binDir.getFullPath();
IJavaProject javaProject = JavaCore.create(project);
javaProject.setOutputLocation(binPath, null);

The IJavaProject is only created after creating the "bin" directory. So
the JDT Core should not be concerned with it in the binDir.create line.

Monika.
Re: IFolder.create throws ResourceException (already exists) [message #244717 is a reply to message #244698] Wed, 20 June 2007 03:44 Go to previous messageGo to next message
Eclipse UserFriend
Monika Krug wrote:
> Daniel Megert schrieb:
>
> I looked at my source code again, it actually is like this:
>
> IFolder binDir = project.getFolder("bin");
> if (!binDir.exists())
> {
> binDir.create(true /* force */, true /* local */, null);
> }
> IPath binPath = binDir.getFullPath();
> IJavaProject javaProject = JavaCore.create(project);
> javaProject.setOutputLocation(binPath, null);
>
> The IJavaProject is only created after creating the "bin" directory. So
> the JDT Core should not be concerned with it in the binDir.create line.


JavaCore#create(...) doesn't create the Java project on disk, it just
creates the handle to the Java project. So it looks like the Java
project already exists, thus the Java builder maybe already be running.

Jerome
Re: IFolder.create throws ResourceException (already exists) [message #244727 is a reply to message #244698] Wed, 20 June 2007 03:53 Go to previous messageGo to next message
Eclipse UserFriend
Monika Krug wrote:

> Daniel Megert schrieb:
>
>> I guess it only tries to explain what goes on behind the scenes. If
>> you want to create a Java project you don't need to create the output
>> folder(s) yourself. That was always like that. If you do want to
>> create them you must ensure not to get in conflict with JDT Core.
>
>
> I looked at my source code again, it actually is like this:
>
> IFolder binDir = project.getFolder("bin");
> if (!binDir.exists())
> {
> binDir.create(true /* force */, true /* local */, null);
> }
> IPath binPath = binDir.getFullPath();
> IJavaProject javaProject = JavaCore.create(project);
> javaProject.setOutputLocation(binPath, null);
>
> The IJavaProject is only created after creating the "bin" directory.
> So the JDT Core should not be concerned with it in the binDir.create
> line.

Correct.

You are talking about test cases - might it be possible that you reuse
the same project name for different tests? If so, I assume you delete
the project and/or folder on tearDown. Make sure that the deletion is
successful (it can fail sometimes if the OS is still locking some
files). In JDT we loop until it is successfully deleted. Also note that
exists() is a handle method i.e. if the workspace model does not contain
the folder it will return 'false' even if the folder exists in the OS
and then fails when you try to create it.

Dani

>
> Monika.
Re: IFolder.create throws ResourceException (already exists) [message #244732 is a reply to message #244727] Wed, 20 June 2007 05:34 Go to previous message
Eclipse UserFriend
Originally posted by: monikakrug.expires-2007-06-30.arcornews.de

Daniel Megert schrieb:
> Monika Krug wrote:
>
>> Daniel Megert schrieb:
>>
>>> I guess it only tries to explain what goes on behind the scenes. If
>>> you want to create a Java project you don't need to create the output
>>> folder(s) yourself. That was always like that. If you do want to
>>> create them you must ensure not to get in conflict with JDT Core.
>>
>>
>> I looked at my source code again, it actually is like this:
>>
>> IFolder binDir = project.getFolder("bin");
>> if (!binDir.exists())
>> {
>> binDir.create(true /* force */, true /* local */, null);
>> }
>> IPath binPath = binDir.getFullPath();
>> IJavaProject javaProject = JavaCore.create(project);
>> javaProject.setOutputLocation(binPath, null);
>>
>> The IJavaProject is only created after creating the "bin" directory.
>> So the JDT Core should not be concerned with it in the binDir.create
>> line.
>
> Correct.
>
> You are talking about test cases - might it be possible that you reuse
> the same project name for different tests? If so, I assume you delete
> the project and/or folder on tearDown. Make sure that the deletion is
> successful (it can fail sometimes if the OS is still locking some
> files). In JDT we loop until it is successfully deleted. Also note that
> exists() is a handle method i.e. if the workspace model does not contain
> the folder it will return 'false' even if the folder exists in the OS
> and then fails when you try to create it.

Hmm, I often run a test that creates some dozen projects, then delete
all of them manually (inside Eclipse), then run the test again that
creates projects with the same names again. So I guess they could be
still existing on the file system.

I removed the lines that create the bin folder and make it the output
folder (so all of the lines above except for the one that creates the
Java project) and the bin folder gets created anyway and is the
outputfolder, as you said it would be. Thanks for the advice.

Monika.

--
All wars are civil wars, because all men are brothers ... Each one owes
infinitely more to the human race than to the particular country in
which he was born. - Francois Fenelon, theologian and writer (1651-1715)

E-mail address is valid until 4 weeks after the expiration date. Use
@arcor.de instead.
Previous Topic:References menu generating class not found error after refactoring
Next Topic:How to dis/enable a TreeItem in a TreeView?
Goto Forum:
  


Current Time: Tue May 06 21:03:33 EDT 2025

Powered by FUDForum. Page generated in 0.06978 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top