Community
Participate
Working Groups
Using I20090707-0800 but already happens in 3.5.0... I wanted to create a test case for bug 281655 and for this copy the code snippet given in the bug description and pasted it in a project of my runtime workbench workspace. The I got an error dialog from the refactoring and from the error log the attached stack trace... Investigating a little bit it seems that this is due to the fact that I configured my workspace to use the bug 281533 formatter profile which has 0 for tabs and indentation width... I open this bug against JDT/UI instead of JDT/Core as it's clearly specified in the javadoc of method measureIndentUnits(CharSequence line, int tabWidth, int indentWidth) of org.eclipse.jdt.core.formatter.IndentManipulation that: * @exception IllegalArgumentException if: * <ul> * <li>the given <code>indentWidth</code> is lower or equals to zero</li> * <li>the given <code>tabWidth</code> is lower than zero</li> * <li>the given <code>line</code> is null</li> * </ul> Hence callers, org.eclipse.jdt.internal.corext.util.Strings.computeIndentUnits(Strings.java:294) in this peculiar case should not call this method when indentWidth is equals to 0 Note that the exception is raised whatever the pasted CU is, e.g.: class X {}
Created attachment 141289 [details] Stack trace
I would argue that this is better fixed in JDT Core by loosening the spec: clients call that API by feeding the corresponding JDT Core options and since JDT Core allows 0 for the indent it would be fair to also allow it here. Also, if not changed in JDT Core then all clients which followed that pattern have to add some special case code. Moving back to JDT Core for consideration.
I concur with Daniel's comment. We have an inconsistency. If we allow 0 for the indentation level, we must loosen the spec of the method in measureIndentUnits. If indentWidth is 0, we could return 0.
Created attachment 141562 [details] Proposed fix
Released for 3.6M1.
Added regression test org.eclipse.jdt.core.tests.formatter.FormatterRegressionTests#test722
Bug 285565 requests that the rest of the IndentManipulation methods should also accept 0 for indentWidth.
Verified for 3.6M1 by code inspection. This point fix needs to be applied to several other places to address bug 285565