Community
Participate
Working Groups
Build ID: I20080523-0100 Steps To Reproduce: 1. Copy the code below in a new java editor 2. Select all, and ctrl+I (Correct Indentation) 3. The global assignment statement should be aligned with the "if", while it is aligned with the "try" More information: import java.io.File; public class TestCorrectIndentation { private boolean _GLOBAL; public void foo() { try { File file = new File("foo"); if (file.exists()) try { // do stuff } catch (RuntimeException ex) { System.err.println("Impossible faire une URL pour le fichier " + file); } // one level of increment should not be there _GLOBAL = _GLOBAL && test(); } finally { // nothing } } private boolean test() { // TODO Auto-generated method stub return false; } }
Can reproduce using 3.4 RC4. Simpler test case: public class Bug237081 { public void foo() { if (true) try { } catch (RuntimeException ex) { } foo(); } }
Rajesh, please check if this is still the case with your recent patches.
(In reply to comment #2) > Rajesh, please check if this is still the case with your recent patches. Yes, this is a pre-existing issue that is not yet solved by the latest patch.
Created attachment 189069 [details] Patch with test.
Deepak, please do the first review and make sure we don't introduce the known regressions (see bug 65317 comment 32).
Patch works when there is only a catch block. But what happens if there is a finally block ? :) --------------------------------------------------------------------- public class Bug237081 { public void foo() { if (true) try { } catch (RuntimeException ex) { } finally { } foo(); } } -------------------------------------------------------------------- Please also add a test for the finally case.
Actually, there is a bigger issue here - that of multiple catch blocks. If the user does ctrl+I on a line which has catch block(s) before it and after it, then the algorithm has to scan not only backwards but also forwards to ascertain where the caret is. Will need to spend more time on this.
(In reply to comment #7) > Actually, there is a bigger issue here - that of multiple catch blocks. If the > user does ctrl+I on a line which has catch block(s) before it and after it, > then the algorithm has to scan not only backwards but also forwards to > ascertain where the caret is. > Will need to spend more time on this. hmm... I think the patch works fine. Do you have an example code snippet ?
(In reply to comment #8) > (In reply to comment #7) > > Actually, there is a bigger issue here - that of multiple catch blocks. If the > > user does ctrl+I on a line which has catch block(s) before it and after it, > > then the algorithm has to scan not only backwards but also forwards to > > ascertain where the caret is. > > Will need to spend more time on this. > > hmm... I think the patch works fine. Do you have an example code snippet ? I see the same i.e. the patch works fine for multiple catch blocks but not yet for a finally block.
Created attachment 189249 [details] Patch with tests. The earlier comment was in the context of how I was implementing 'finally'. Now its a very simple change from the previous patch and seems to work fine. Also added tests.
Patch is good. Committed to HEAD.
.
Build id: 20110218-0911 Problem persists after for,if,while,etc...
(In reply to comment #13) > Build id: 20110218-0911 > Problem persists after for,if,while,etc... Please file a new bug if you see this in I20110912-0800 or newer.