Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 325681

Summary: [compiler] syntax error in role file may cause NPE in RoleModel.getTeamModel()
Product: [Tools] Objectteams Reporter: Stephan Herrmann <stephan.herrmann>
Component: OTJAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 0.7   
Target Milestone: 0.7.1   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
test and fix none

Description Stephan Herrmann CLA 2010-09-18 11:41:50 EDT
I observed several NPEs while editing CreateMethodMappingCompletionProposal.
On narrowing down the cause I see that the back reference from a role file
type to its enclosing team type may break when the role file contains
a (specific kind of) syntax error.

The culprit is in Parser.buildInitialRecoveryState(), where nulling the
package declaration of the enclosing CUD causes grief. Investigating.
Comment 1 Stephan Herrmann CLA 2010-09-18 19:17:45 EDT
I filed bug 325690 against JDT/Core for that part that causes entry into 
the parser with garbled source (Parser.parseMemberValue(..))
Comment 2 Stephan Herrmann CLA 2010-09-18 20:41:34 EDT
Created attachment 179196 [details]
test and fix

OK, here is what happened: after bug 325690 struck the parser would
be called with garbage and on hitting a syntax error, it would
wipe out the package declaration from the CU to start over,
yet the current source would contain only a small fragment of the
file (supposedly an annotation, but it was off).

Later, that CU without a package declaration would fail in 
RoleFileHelper.getTeamOfRoleFile(..) thus the role file didn't
get enclosingType set. Still later RoleModel.getTeamModel would
dereference _ast.enclosingType and throw NPE.

Fixed by making Parser.buildInitialRecoveryState() sensitive
to what initial goal we are parsing for. Only when going for
compilation unit or package declaration do we reset the package
declaration now.
Comment 3 Stephan Herrmann CLA 2010-09-18 20:44:05 EDT
Patch has been committed as r826 / r827.
Comment 4 Stephan Herrmann CLA 2010-09-23 17:42:03 EDT
Verified using I201009211735