Bug 103320 - Method-local subtype with instance initializer break JDOM
Summary: Method-local subtype with instance initializer break JDOM
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 103336 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-07-11 10:35 EDT by Rajeev Sudra CLA
Modified: 2005-09-26 12:46 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rajeev Sudra CLA 2005-07-11 10:35:09 EDT
1) Begin with a plugin project with a java annotated emf model that can be 
successfully reloaded.

2) Add a non-emf model class in any package such as:

public class EmfReloadBug {
 public void buggyMethod() {
  Object o = new Object() {
   {
    System.out.println("EMF reload does not like this method local subtype 
instance init");
   }
  }
 }
}

3) Try to reload the genmodel. the package selection page for the reload 
wizard is empty and throws the following exception:

org.eclipse.jdt.core.jdom.DOMException: Attempt to add child to node that 
cannot have children
Comment 1 Ed Merks CLA 2005-07-11 10:55:13 EDT
This is a problem in JDOM.  It looks familiar.  It think last time this came up
they said they wouldn't fix it and that we should use AST, which we plan to do
but haven't done yet:  https://bugs.eclipse.org/bugs/show_bug.cgi?id=78076

org.eclipse.jdt.core.jdom.DOMException: Attempt to add child to node that cannot
have children
	at org.eclipse.jdt.internal.core.jdom.DOMNode.basicAddChild(DOMNode.java:344)
	at
org.eclipse.jdt.internal.core.jdom.AbstractDOMBuilder.addChild(AbstractDOMBuilder.java:129)
	at org.eclipse.jdt.internal.core.jdom.DOMBuilder.addChild(DOMBuilder.java:139)
	at
org.eclipse.jdt.internal.core.jdom.DOMBuilder.acceptInitializer(DOMBuilder.java:99)
	at
org.eclipse.jdt.internal.compiler.DocumentElementParser.consumeClassBodyDeclaration(DocumentElementParser.java:116)
	at org.eclipse.jdt.internal.compiler.parser.Parser.consumeRule(Parser.java:4743)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:8490)
	at
org.eclipse.jdt.internal.compiler.DocumentElementParser.parseType(DocumentElementParser.java:1285)
	at org.eclipse.jdt.internal.core.jdom.DOMBuilder.createType(DOMBuilder.java:266)
	at org.eclipse.jdt.core.jdom.DOMFactory.createType(DOMFactory.java:158)
	at org.eclipse.jdt.internal.core.jdom.DOMType.getDetailedNode(DOMType.java:392)
	at org.eclipse.jdt.internal.core.jdom.DOMNode.becomeDetailed(DOMNode.java:390)
	at org.eclipse.jdt.internal.core.jdom.DOMMember.getComment(DOMMember.java:218)
	at
org.eclipse.emf.importer.java.builder.JavaEcoreBuilder.analyzeType(JavaEcoreBuilder.java:692)
Comment 2 Ed Merks CLA 2005-07-11 10:59:52 EDT
Assigning bug to owner of component...
Comment 3 Dave Steinberg CLA 2005-07-11 11:53:01 EDT
*** Bug 103336 has been marked as a duplicate of this bug. ***
Comment 4 Olivier Thomann CLA 2005-07-11 12:57:09 EDT
I am unfamiliar with EMF. Could you please provide steps to reach step 1?
Thanks.
Comment 5 Ed Merks CLA 2005-07-11 13:12:51 EDT
The problem doesn't need EMF to reproduce.  You should be able to reproduce it
just building the JDOM for the sample code below and then calling getComment on
the type.
Comment 6 Olivier Thomann CLA 2005-07-11 13:31:43 EDT
Reproduced. The problem comes from the fact that the DOMBuilder has no support
for anonymous type. It tries to add the initializer inside the anonymous in the
enclosing method and this is illegal.
The fix would be to ignore initializers inside methods.
Comment 7 Olivier Thomann CLA 2005-07-11 14:06:44 EDT
I believe the fix is to run the DocumentElementParser only in diet mode. There
is no need to look into method bodies since it is illegal to add a child to a
method node.
Comment 8 Olivier Thomann CLA 2005-07-13 13:53:16 EDT
Do you need a fix for 3.1.1 or will you update to DOM/AST before that?
Comment 9 Ed Merks CLA 2005-07-13 13:59:00 EDT
We won't move to AST until Eclipse 3.2, and even at that point, the old code
will remain and be deprecated...
Comment 10 Philipe Mulet CLA 2005-07-13 16:22:32 EDT
+1 for 3.1.1 then.
Comment 11 Olivier Thomann CLA 2005-07-14 14:43:05 EDT
Fixed and released in both HEAD and 3.1 maintenance stream.
Regression tests added in internal JDOM tests packages.
Comment 12 Ed Merks CLA 2005-07-14 14:50:59 EDT
Thanks so much for fixing this and so quickly too!  It's much appreciated!!
Comment 13 Olivier Thomann CLA 2005-07-14 14:53:27 EDT
No problem. As soon as we provide a new preview of 3.1.1 branch, you should give
it a try.
Comment 14 David Audel CLA 2005-09-26 12:46:23 EDT
Verified using M20050923-1430 for 3.1.1