Bug 140476 - JDOM: IDOMType.setSuperInterfaces(new String [0]) fails to remove existing implements clause
Summary: JDOM: IDOMType.setSuperInterfaces(new String [0]) fails to remove existing im...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.2.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-06 12:40 EDT by Ed Merks CLA
Modified: 2006-09-12 06:39 EDT (History)
2 users (show)

See Also:


Attachments
JUnit test to reproduce the problem. (3.07 KB, application/zip)
2006-05-06 12:42 EDT, Ed Merks CLA
no flags Details
The patch as an attachment. (827 bytes, patch)
2006-05-06 12:46 EDT, Ed Merks CLA
no flags Details | Diff
Proposed fix (993 bytes, patch)
2006-05-08 15:49 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Merks CLA 2006-05-06 12:40:08 EDT
It's not possible to remove the existing super interfaces of a class using IDOMType.setSuperInterfaces with an empty array. This results in EMF's JMerger not being able to produce a result that matches the generated results after a model change.  I'll attach a JUnit test to reproduce the problem and here's a patch to fix it:

### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: model/org/eclipse/jdt/internal/core/jdom/DOMType.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/jdom/DOMType.java,v
retrieving revision 1.39
diff -u -r1.39 DOMType.java
--- model/org/eclipse/jdt/internal/core/jdom/DOMType.java	29 Mar 2006 03:13:59 -0000	1.39
+++ model/org/eclipse/jdt/internal/core/jdom/DOMType.java	6 May 2006 16:36:48 -0000
@@ -316,7 +316,7 @@
 				buffer.append(fDocument, fInterfacesRange[0], fInterfacesRange[1] + 1 - fInterfacesRange[0]);
 			}
 		}
-		if (hasInterfaces) {
+		if (hasInterfaces || fSuperInterfaces == EMPTY_SUPERINTERFACES) {
 			if (fImplementsRange[0] < 0) {
 				buffer.append(' ');
 			} else {
Comment 1 Ed Merks CLA 2006-05-06 12:42:25 EDT
Created attachment 40552 [details]
JUnit test to reproduce the problem.
Comment 2 Ed Merks CLA 2006-05-06 12:46:25 EDT
Created attachment 40553 [details]
The patch as an attachment.

The idea is simply to notice that the fSuperInterfaces is the special empty value and hence that the content should be generated as if the appropriate implements clause has already been appended, and since nothing was appended and we don't want anything appended, that's the right handling at this point in the content processing.
Comment 3 Olivier Thomann CLA 2006-05-07 16:51:57 EDT
Isn't EMF supposed to move to DOM API instead of JDOM ?
JDOM is deprecated.
Comment 4 Ed Merks CLA 2006-05-07 19:39:35 EDT
We're still working to get migrated to AST, and will leave the JDOM-based version as the default for the next release.
Comment 5 Olivier Thomann CLA 2006-05-08 15:05:11 EDT
Empty arrays are already supposed to be handled.
I am investigating.
Comment 6 Olivier Thomann CLA 2006-05-08 15:08:25 EDT
I tried your JUnit tests with RC3 and they passed.
What version are you using?
Comment 7 Olivier Thomann CLA 2006-05-08 15:10:04 EDT
Forget my last comment. I forgot the change the test name to include the right prefix. The tests were not run.
Comment 8 Olivier Thomann CLA 2006-05-08 15:49:01 EDT
Created attachment 40639 [details]
Proposed fix

The given patch is considering the two parts after the extends and before the implements and the part after the implements and before the body start.
The previous patch also works because the position of the implements range starts at the wrong location when a comment is located between the extends clause and the implements clause.
This might be fixed in the future. This is why I prefer this one.
Comment 9 Olivier Thomann CLA 2006-05-08 15:49:30 EDT
How important is it to get this into 3.2?
Comment 10 Ed Merks CLA 2006-05-08 16:05:12 EDT
Olivier,

It's not super important that it get in, just a nice to have.  The bug has been there a long time and no one complained directly. It's much more likely that folks add stuff to a model rather than remove stuff, so it's not commonly encountered.  It's really your call as to the risk associated with the fix.  There's always the risk that the fixed behavior will upset someone else relying on the incorrect behavior... 
Comment 11 Olivier Thomann CLA 2006-05-08 22:03:13 EDT
If the bug was noticed a while ago, it should have been reported earlier. Now we are close to RC4. So it is late in the game.
Philippe, this is your call.
Comment 12 Philipe Mulet CLA 2006-05-09 03:51:54 EDT
As Ed said: not critical. Thus it doesn't qualify for RC4.
This isn't a regression, and sitting in deprecated code which has been wrong since ever I suspect.

This being said, we should be able to schedule this for a 3.2.1.
Comment 13 Olivier Thomann CLA 2006-05-16 10:31:52 EDT
Fixed in 3.2.1 branch.
Regression test added in the JDOMTests.
Comment 14 Frederic Fusier CLA 2006-06-12 05:15:30 EDT
Released for 3.2.1
Released for 3.3 M1 while merging TARGET_321 in HEAD
Comment 15 Frederic Fusier CLA 2006-08-08 03:34:15 EDT
Verified for 3.3 M1 using build I20060807-0010.
Comment 16 David Audel CLA 2006-09-12 06:39:40 EDT
Verified for 3.2.1 using build M20060908-1655