Community
Participate
Working Groups
Using CDT 8.1.0.201111131105 int main() { int a; switch(a) { case 0: { } // Use 'Add break statement' quick fix here default: break; } return 0; } java.lang.NullPointerException at org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CaseBreakQuickFixBreak.modifyAST(CaseBreakQuickFixBreak.java:81) at org.eclipse.cdt.codan.ui.AbstractAstRewriteQuickFix.apply(AbstractAstRewriteQuickFix.java:52) at org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution.run(AbstractCodanCMarkerResolution.java:93) at org.eclipse.cdt.internal.ui.text.correction.MarkerResolutionProposal.apply(MarkerResolutionProposal.java:43) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:935) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:881) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey(CompletionProposalPopup.java:1307) at org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey(ContentAssistant.java:807) at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:491) at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:65) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
Created attachment 223936 [details] proposed fix It seems to be a small error in the ast parsing. The proposed patch fixes the described bug, as well this closely related one: int main() { int a; switch (a) { case 0: { int b; } // quickfix here default: break; } return 0; } ... case 0: { int b; // break statement gets added here } // instead of here default: break; ...
(In reply to comment #1) > Created attachment 223936 [details] > proposed fix > > It seems to be a small error in the ast parsing. > > The proposed patch fixes the described bug, as well this closely related one: > > int main() { > int a; > switch (a) { > case 0: > { > int b; > } // quickfix here > default: > break; > } > return 0; > } > ... > case 0: > { > int b; > // break statement gets added here > } > // instead of here > default: > break; > ... I think it's more conventional to place the break inside the compound-statement.
Patch: https://git.eclipse.org/r/14640
*** cdt git genie on behalf of Nathan Ridge *** Bug 363884 - NPE using 'Add break statement' quick fix Change-Id: I240b196d04b5f032bfaa9666db595b788b7a1d02 Signed-off-by: Nathan Ridge <zeratul976@xxxxxxxxxxx> Reviewed-on: <a href="https://git.eclipse.org/r/14640">https://git.eclipse.org/r/14640</a> Reviewed-by: Sergey Prigogin <eclipse.sprigogin@xxxxxxxxx> IP-Clean: Sergey Prigogin <eclipse.sprigogin@xxxxxxxxx> Tested-by: Sergey Prigogin <eclipse.sprigogin@xxxxxxxxx> [*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=33fcecc5b0666e24f6dcb965bed7f3166c726e03
Fixed in 8.2.1 and master. Thanks!
Verified in 20130821-2252 (RC1). However, I did find another problem when I kept the comment in the test code, see bug 416283.