Bug 331821 - Cannot delete source folder using '!' as the first character
Summary: Cannot delete source folder using '!' as the first character
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-03 22:21 EST by pesckal CLA
Modified: 2011-01-25 04:07 EST (History)
4 users (show)

See Also:
amj87.iitr: review+


Attachments
Errors logged as a result of bug (3.34 KB, text/plain)
2010-12-03 22:26 EST, pesckal CLA
no flags Details
Proposed patch (4.58 KB, patch)
2010-12-09 06:53 EST, Jay Arthanareeswaran CLA
no flags Details | Diff
Patch with test (5.84 KB, patch)
2010-12-09 13:19 EST, Jay Arthanareeswaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description pesckal CLA 2010-12-03 22:21:39 EST
Build Identifier: M20100909-0800

A source folder that uses an exclamation point as the first character cannot be deleted from a Java project.

Reproducible: Always

Steps to Reproduce:
1. Create a new Java project
2. Create a new source folder named '!', a single exclamation point
3. Delete the source folder named '!'
Comment 1 pesckal CLA 2010-12-03 22:26:21 EST
Created attachment 184525 [details]
Errors logged as a result of bug
Comment 2 Jay Arthanareeswaran CLA 2010-12-06 04:26:36 EST
Reproduced in HEAD. The bug occurs when a name starting with '!' is used for source folders. Looks like the '!' is considered as a token instead of part of the element name, which results in the error. Will see what needs to be done here.
Comment 3 Jay Arthanareeswaran CLA 2010-12-09 05:48:05 EST
Whenever a package fragment root name (source folder in this case) starts with any of the memento token names, an escape character is added. Apart from '!', this can also be seen for ^, < etc. However, only '!' causes any problem because of the check we have in JavaProject#getHandleFromMemento().

The calls to escapeMementoName from several places including PackageFragmentRoot.getHandleMemento() add the escape character to the element's name if they begin with any of these special characters. I doubt this is what we want. Investigating further.
Comment 4 Jay Arthanareeswaran CLA 2010-12-09 06:33:59 EST
(In reply to comment #3)
> Whenever a package fragment root name (source folder in this case) starts with
> any of the memento token names, an escape character is added. Apart from '!',
> this can also be seen for ^, < etc. However, only '!' causes any problem
> because of the check we have in JavaProject#getHandleFromMemento().
> 
> The calls to escapeMementoName from several places including
> PackageFragmentRoot.getHandleMemento() add the escape character to the
> element's name if they begin with any of these special characters. I doubt this
> is what we want. Investigating further.

That's a wrong understanding of the escape characters in the context of memento. The actual cause is MementoTokenizer#nextToken strips out the escape character. Hence, JavaProject#getHandleFromMemento is unable to determine what the '!' represents (a token or the element name)
Comment 5 Jay Arthanareeswaran CLA 2010-12-09 06:53:41 EST
Created attachment 184844 [details]
Proposed patch

Only the fix in the patch. Tests to be added.
Comment 6 Jay Arthanareeswaran CLA 2010-12-09 13:19:30 EST
Created attachment 184880 [details]
Patch with test

Test added in MementoTests#testBug331821()
Comment 7 Jay Arthanareeswaran CLA 2010-12-13 08:42:35 EST
Srikanth, can you review this patch, please?
Comment 8 Srikanth Sankaran CLA 2010-12-14 03:36:53 EST
Ayush, can I request you to review this please ? (I am tied up this
week and the next.) Thanks.
Comment 9 Ayushman Jain CLA 2010-12-20 09:11:03 EST
It looks like the fix changes the semantics in org.eclipse.jdt.internal.core.JavaProject.getHandleFromMemento(String, MementoTokenizer, WorkingCopyOwner), where earlier we were consciously trying to break only in cases where the token starts with '!' or '<', we now only break when the token itself is '!' or '<'. This would be ok if this is what we'd intended to do, but i'm not sure.

Also, the line just below the while loop
if (token != null && token.charAt(0) == JEM_PACKAGEFRAGMENT)

also needs to be written as 

if (token != null && token == MementoTokenizer.PACKAGEFRAGMENT)
Comment 10 Jay Arthanareeswaran CLA 2010-12-20 22:41:02 EST
(In reply to comment #9)
> It looks like the fix changes the semantics in
> org.eclipse.jdt.internal.core.JavaProject.getHandleFromMemento(String,...

The code is only trying to extract the package fragment root from the supplied string. Apparently this particular implementation of getHandleFromMemento is not interested in the occurrence count. I have changed only the condition that determine whether the token is any of the two concerned. The rest of the code remains. 

> Also, the line just below the while loop
> if (token != null && token.charAt(0) == JEM_PACKAGEFRAGMENT)...

This could have been a problem too. But I just checked and it appears neither eclipse nor Windows allow '<' (represents JEM_PACKAGEFRAGMENT) in folder names.
Comment 11 Ayushman Jain CLA 2010-12-21 01:54:41 EST
(In reply to comment #10)
> [..]
> > Also, the line just below the while loop
> > if (token != null && token.charAt(0) == JEM_PACKAGEFRAGMENT)...
> 
> This could have been a problem too. But I just checked and it appears neither
> eclipse nor Windows allow '<' (represents JEM_PACKAGEFRAGMENT) in folder names.

If it is not allowed, why are we checking for it at two places in this particular method? Shouldn't the two checks be removed? Or if not, they should both be token == MementoTokenizer.PACKAGEFRAGMENT ?
Comment 12 Jay Arthanareeswaran CLA 2010-12-21 02:36:37 EST
(In reply to comment #11)
> If it is not allowed, why are we checking for it at two places in this
> particular method? Shouldn't the two checks be removed? Or if not, they should
> both be token == MementoTokenizer.PACKAGEFRAGMENT ?

What I meant was, the character '<' cannot be part of a folder name. However, the memento we are dealing with might have the PACKAGEFRAGMENT delimiter, which is represented by '<' and with an escape character.

For e.g. the memento could be something like "=TestProject/!<com.abc" and since '<' is not allowed as part of the folder name (and package fragment name), it is considered as the token delimiter

By the way, I happened to look at 
PackageFragmentRoot.getHandleFromMemento(String, MementoTokenizer, WorkingCopyOwner), which might have to be fixed as well.
Comment 13 Jay Arthanareeswaran CLA 2010-12-21 03:04:41 EST
(In reply to comment #12)
> By the way, I happened to look at 
> PackageFragmentRoot.getHandleFromMemento(String, MementoTokenizer,
> WorkingCopyOwner), which might have to be fixed as well.

We don't allow '!' and other delimiters in package names. So, this is alright.
Comment 14 Ayushman Jain CLA 2010-12-21 03:43:39 EST
(In reply to comment #13)
> (In reply to comment #12)
> > By the way, I happened to look at 
> > PackageFragmentRoot.getHandleFromMemento(String, MementoTokenizer,
> > WorkingCopyOwner), which might have to be fixed as well.
> 
> We don't allow '!' and other delimiters in package names. So, this is alright.

Ok. Good to go then!
Comment 15 Jay Arthanareeswaran CLA 2010-12-22 00:57:53 EST
Released in HEAD for 3.7M5.
Comment 16 Satyam Kandula CLA 2011-01-25 04:07:32 EST
Verified for 3.7M5 using build I20110124-1800