This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I have a class with a few guarded blocks. I want to insert a new method below the last guarded block. The new method should override a method from a superclass, so I decided to use the Java code hint. I type several chars of the method's name, press Ctrl-Enter and select the proper item from a pop-up menu. After that, the pop-up disappears but the new method is not added. Instead, a notice appears in the IDE's status line: "Cannot apply changes due to guarded block." Here is the layout of the existing code. The arrow marks the line where I am trying to add the new method to: ----------------------------------------- ... // End of variables declaration <-- END OF GUARDED BLOCK --> TRYING TO INSERT NEW METHOD HERE <-- /** * Gets default instance. Do not use directly: reserved for *.settings files only, * ... ----------------------------------------- -- JDK 6u18-b05, 64-bit, server VM Linux (Debian Lenny), 64-bit, Intel CPU
I have also encountered this. I didn't even notice the warning in status bar and was very confused. In my case I was also trying to override a method but place it between generated method and variables declaration section. Both were guarded blocks - depicted by *. I placed my cursor at position 75:2 depicted by | and pressed Alt+Insert to invoke the Generate wizard. 69* private void rbInvoiceActionPerformed(java.awt.event.ActionEvent evt) { 70 rbInvoice.setSelected(true); 71 rbReport.setSelected(false); 72 lbPreview.setIcon(invoicePreviewImage); 73 firePropertyChange("report.type", null, "invoice"); 74* } 75 | 76* // Variables declaration - do not modify 77 private javax.swing.JLabel lbPreview; 78 private javax.swing.JRadioButton rbInvoice; 79 private javax.swing.JRadioButton rbReport; 80* // End of variables declaration Marking with NETFIX keyword to give this bug more visibility and increase its chances to be fixed.
Created attachment 97525 [details] Project reproducing the not working generation of code. Simply open the project, open the ReportTypeWizardStep.java class, place cursor at position 75:1 and use Alt+Insert to override for example setDescription(String description) method. Once you check it and push Generate button nothing happens. :-(
I'd like to NetFIX [1] this bug. Is it possible? [1] http://wiki.netbeans.org/NetFIX"
(In reply to comment #3) > I'd like to NetFIX [1] this bug. Is it possible? You are surely welcome to work on this. It might be relatively simple problem, but may also be pretty complex, and I cannot tell which one without investigating the root cause. I suspect this is a bug in the code generator (part of the java.source module). The approach that I would recommend to fix this (and similar) bugs is: -add a new test case(s) covering the problem (in this case into the GuardedBlockTest in java.source) -debug&fix until the test case (and other test cases in GuardedBlockTest) pass -run: ant -Dtest.config=generator test in java.source directory in the NB checkout. If all tests pass (i.e. build is successful), the patch is a good candidate for review. If some tests fail, investigate why (run "ant init test-generate-html" to get an HTML results page), and either fix the regression or have a reasoning ready why the existing test was incorrect+add a patch that fixes it (it is however not very common to change existing tests). Good luck.
thanks Jan! I'll follow your advice.
Created attachment 117209 [details] Diff file with the fix for this issue Affected files on Java.Source project: * org.netbeans.api.java.source.gen.GuardedBlockTest #testInsertMethodBeforeVariablesBug177824() * org.netbeans.api.java.source.ModificationResult #processDocumentLocked(Document, Difference)
I am sorry, but I do not like the attached patch very much. Catching and ignoring exceptions is rarely the correct solution. In this case, the real question is why the code generator (the CasualDiff and the other diffing parts) tries to modify the guarded block at all, and if that can be prevented. Thanks.
Right Jan. I saw CasualDiff adding an inconsistent CHANGE diff (removing a guarded block) before the correct INSERT diff. I'll work on it. Thanks!
Created attachment 117981 [details] Diff file with the fix for this issue #2 Affected files on Java.Source project: * org.netbeans.api.java.source.gen.GuardedBlockTest #testInsertMethodBeforeVariablesBug177824() * org.netbeans.modules.java.source.save.DiffFacility #makeTokenListMatch(String, String, int):206
is there some update about that submitted patch?
Seems like a reasonable approach (would be better if the difference wouldn't exist in the first place, but as the trailing whitespaces are stripped by pretty.CharBuffer.nlTerm(), this does not seem really viable, at least for now). Can I include your name for the changeset? Thanks.
Yes, you can do that Jan. Regards!
Integrated in the jet-main repository: http://hg.netbeans.org/jet-main/rev/a99f112a1760 Thank you for your contribution.
I'm glad to help! Thank you Jan!
Integrated into 'main-golden', will be available in build *201204260400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/a99f112a1760 User: Roberto Vezzoni <vezzoni@netbeans.org> Log: #177824: do not produce a diff for removed guarded block placeholder whitespaces
Jan, please. I've missed the follow instruction at integrated diff that makes the test case run: suite.addTest(new GuardedBlockTest("testInsertMethodBeforeVariablesBug177824")); That instruction has to be into suite() method on GuardedBlockTest unit test class. It is at 156 line on patched file. Thanks!
Integrated into 'main-golden', will be available in build *201205190400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/d7bb48785985 User: Jan Lahoda <jlahoda@netbeans.org> Log: #177824#c16: better enable all test cases in a test class, and disable the broken ones separately.