Community
Participate
Working Groups
I20071212-1800 AST has a wrong source range for a method parameter with an array-valued annotation: package xy; public class C { void m(@SuppressWarnings({"unused", "bla"}) int arg) { int local; } } The MethodDeclaration [34, 109] has the correct source range, but its body's Block [59, 17] has a wrong range (namely, the range of the ArrayInitializer in the SuppressWarnings annotation). This causes e.g. an NPE when you select "bla", invoke Quick Fix, and select the "Extract to local variable" proposal: Caused by: java.lang.NullPointerException at org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring.insertAt(ExtractTempRefactoring.java:710) at org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring.createAndInsertTempDeclaration(ExtractTempRefactoring.java:645) at org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring.createTempDeclaration(ExtractTempRefactoring.java:737) at org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring.doCreateChange(ExtractTempRefactoring.java:525) at org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring.checkFinalConditions(ExtractTempRefactoring.java:468) at org.eclipse.jdt.internal.ui.text.correction.QuickAssistProcessor$RefactoringCorrectionProposal.createTextChange(QuickAssistProcessor.java:1543) at org.eclipse.jdt.internal.ui.text.correction.proposals.CUCorrectionProposal.createChange(CUCorrectionProposal.java:478) at org.eclipse.jdt.internal.ui.text.correction.proposals.ChangeCorrectionProposal.getChange(ChangeCorrectionProposal.java:229) at org.eclipse.jdt.internal.ui.text.correction.proposals.CUCorrectionProposal.getTextChange(CUCorrectionProposal.java:488) at org.eclipse.jdt.internal.ui.text.correction.proposals.CUCorrectionProposal.getAdditionalProposalInfo(CUCorrectionProposal.java:172) at org.eclipse.jface.text.contentassist.AdditionalInfoController$6.run(AdditionalInfoController.java:162)
Problem comes from the ASTConverter.retrieveStartBlockPosition(int,int) method which stops at the first opening brace although in this case it should not.
Already happens in 3.3 => not a stop ship for 3.4M4
I'll have a look.
The fix is trivial. It could have made it into 3.4M4 if this blocks an important feature from the UI, otherwise it can wait for 3.4M5.
Once fixed, this would be a good candidate for 3.3.2 as it can break any users of the DOM/AST tree.
Created attachment 85291 [details] Proposed fix + regression tests Frédéric, let me know what you think.
Created attachment 85450 [details] New proposed patch I'm OK with the patch you posted previously. I just modified to avoid code duplication and use recovery position when there was no opening brace. I also added tests in the new class I created since I got dom component responsibility (ASTConverterBugsTest) to identify my contributions more easily. All JDT/Core and JDT/UI tests pass with this patch
Released for 3.4M5 in HEAD stream.
Verified for 3.4M5 using build I20080204-0010. A NPE still occurs i entered another bug report (bug 217806)because the source range bug is fixed .