Bug 331736 - [dom] tests should check for malformed nodes - may catch a parser bug
Summary: [dom] tests should check for malformed nodes - may catch a parser bug
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-02 18:29 EST by Stephan Herrmann CLA
Modified: 2011-01-25 08:01 EST (History)
2 users (show)

See Also:


Attachments
test changes and parser fix (12.65 KB, patch)
2010-12-02 18:35 EST, Stephan Herrmann CLA
no flags Details | Diff
Proposed fix + regression tests (22.58 KB, patch)
2010-12-08 15:40 EST, 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 Stephan Herrmann CLA 2010-12-02 18:29:02 EST
I was initially alerted because a DOM bug in the OT branch was not 
detected by the jdt.core.tests.model suite.
I found that non of the tests of the ASTConverter* tests checked the
created nodes for isMalformed(), except when expecting true.

I added a corresponding check to ConverterTestSetup.checkSourceRange(..)
to catch as many test nodes as possible.
For 18 test cases I had to set the expectation explicitly to true (malformed),
and I checked that these indeed test sources with syntax errors.
All other tests still pass.

However, from these 18 cases one test revealed that malformed AST was
wrongly flagged (plus duplicates in other testclasses):
  ASTConverterTest.test0339()
Here the example class has a syntax error and in this situation a regular
interface method has a wrong source position:
  		int doQuery(boolean x);
It shows that in recovery mode the MethodDeclaration.bodyEnd is set on the
';' whereas it normally points to the ')'. As a result the ASTConverter
signals this method as malformed, because it can't find the ';' at bodyEnd+1.
Comment 1 Stephan Herrmann CLA 2010-12-02 18:35:15 EST
Created attachment 184424 [details]
test changes and parser fix

This patch contains the test changes and the fix in the parser.
Comment 2 Stephan Herrmann CLA 2010-12-02 18:41:25 EST
Olivier, do you want to give it a quick look?
This one should be easy and not take much of your time :)
Comment 3 Olivier Thomann CLA 2010-12-06 10:23:47 EST
Targeting M5 as there is a change in the parser.
Comment 4 Olivier Thomann CLA 2010-12-06 12:07:22 EST
I only see:
org.eclipse.jdt.internal.compiler.ast.JavadocArgumentExpression.internalResolveType(Scope)
that might require more work.

I wrote a small test case that produced:
java.lang.NullPointerException
at org.eclipse.jdt.internal.compiler.ast.JavadocArgumentExpression.internalResolveType(JavadocArgumentExpression.java:53)
at org.eclipse.jdt.internal.compiler.ast.JavadocArgumentExpression.resolveType(JavadocArgumentExpression.java:97)
at org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend.internalResolveType(JavadocMessageSend.java:64)
at org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend.resolveType(JavadocMessageSend.java:200)
at org.eclipse.jdt.internal.compiler.ast.Javadoc.resolveReference(Javadoc.java:367)
at org.eclipse.jdt.internal.compiler.ast.Javadoc.resolve(Javadoc.java:269)
at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveJavadoc(AbstractMethodDeclaration.java:440)
at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:420)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1147)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1257)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:540)
at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:899)
at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:944)
at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:202)
at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:268)
at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:190)
at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:89)
at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:788)
at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1244)
at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:126)
at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.access$0(JavaReconcilingStrategy.java:108)
at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:89)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:87)
at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.initialReconcile(JavaReconcilingStrategy.java:178)
at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.initialReconcile(CompositeReconcilingStrategy.java:114)
at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.initialReconcile(JavaCompositeReconcilingStrategy.java:133)
at org.eclipse.jface.text.reconciler.MonoReconciler.initialProcess(MonoReconciler.java:105)
at org.eclipse.jdt.internal.ui.text.JavaReconciler.initialProcess(JavaReconciler.java:398)
at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:173)


So I'll target 6pm build and not 1pm.
Comment 5 Olivier Thomann CLA 2010-12-06 12:07:45 EST
Sorry wrong bug.
Comment 6 Olivier Thomann CLA 2010-12-07 09:07:10 EST
This is a problem with the ASTConverter that doesn't expect recovered nodes.
In this case the method inside the interface is well formed, but it is built during the error recovery because of the syntax error at the end of the code.

I'll investigate.
Comment 7 Stephan Herrmann CLA 2010-12-07 09:48:07 EST
(In reply to comment #6)
> This is a problem with the ASTConverter that doesn't expect recovered nodes.

So you mean it's OK if recovery sets different source positions even for a
valid element than normal parsing would do?

For normal abstract methods (bodyEnd+1) points to ';', which is not true for
recovered methods.
Comment 8 Olivier Thomann CLA 2010-12-08 08:55:42 EST
(In reply to comment #7)
> So you mean it's OK if recovery sets different source positions even for a
> valid element than normal parsing would do?
> For normal abstract methods (bodyEnd+1) points to ';', which is not true for
> recovered methods.
Once you end up with recovery in headers, the method inside the interface is handled through error recovery. So this is why its bodyEnd and declaration source end values are the same.

I don't want to play too much inside the recovery just to handle this case. I think we can do a pretty local fix inside the ASTConverter.

Investigating.
Comment 9 Olivier Thomann CLA 2010-12-08 15:40:56 EST
Created attachment 184817 [details]
Proposed fix + regression tests

This patch makes changes only inside the ASTConverter by handling differently the case where bodyEnd == declarationSourceEnd.
I am not sure we need to do more than that for now.
Comment 10 Olivier Thomann CLA 2010-12-10 13:21:28 EST
Stephan, I would release that patch for now.
No need to spend lot of time on this issue.

Comment ?
Comment 11 Olivier Thomann CLA 2010-12-13 09:43:20 EST
Released for 3.7M5.
Comment 12 Ayushman Jain CLA 2011-01-25 08:01:08 EST
Verified for 3.7M5 using code inspection.