Bug 246921 - NPE in ChangeGenerator when extracting constant
Summary: NPE in ChangeGenerator when extracting constant
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 5.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 5.0.1   Edit
Assignee: Emanuel Graf CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2008-09-10 17:27 EDT by Tom Ball CLA
Modified: 2010-05-28 12:54 EDT (History)
3 users (show)

See Also:


Attachments
Patch to test for modifications to files outside of workspace (1.23 KB, patch)
2008-09-10 17:28 EDT, Tom Ball CLA
cdtdoug: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Ball CLA 2008-09-10 17:27:51 EDT
Build ID: trunk

Steps To Reproduce:
1. Create a C hello-world sample project
2. Select the zero from "return 0;"
3. Right-click, Refactor->Extract Constant...
4. Click Next


More information:
The NPE is in ChangeGenerator.synthTreatment(), when it hits a modification against a file that isn't in the workspace (in this case, /usr/stdio.h).  The fix is to check for null, and if true, throw an UnhandledASTModificationException.  (The exception appears to be handled correctly by the caller.)
Comment 1 Tom Ball CLA 2008-09-10 17:28:41 EDT
Created attachment 112255 [details]
Patch to test for modifications to files outside of workspace
Comment 2 Emanuel Graf CLA 2008-09-11 04:50:28 EDT
Your patch look good but I can't reproduce the behavior you have descriped. When you invoke Extract constant in the c file create by the new project wizard the refactoring tried to replace all the 0 in stdio.h? That's not intended and does not happens when i try this. 
Comment 3 Tom Ball CLA 2008-09-11 11:31:17 EDT
I was only able to reproduce this on a HEAD build from last week, not current as of yesterday or the last release binary.  Since you've been working hard on getting 5.0.1 ready, perhaps there was a small window between commits where this bug surfaced but which is now closed.  It doesn't hurt to verify that the file is in the workspace, but it appears that the test isn't required anymore, either.  So use your discretion as to whether to accept the patch or close this issue as "cannot reproduce".

Thanks for following up on this so quickly.
Comment 4 Emanuel Graf CLA 2008-09-11 15:33:02 EDT
I applied your patch to 5.0 and HEAD.