Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 432593

Summary: [formatter]Infinite loop in CodeFormatter / Scribe
Product: [Eclipse Project] JDT Reporter: AndrĂ© Pankraz <andre>
Component: CoreAssignee: Manoj N Palat <manoj.palat>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: manoj.palat, srikanth_sankaran
Version: 4.4   
Target Milestone: 4.5 M7   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Source to Paste into Eclipse with 1.5 Source Project Setting
none
workaround wip none

Description André Pankraz CLA 2014-04-11 04:30:48 EDT
Created attachment 241873 [details]
Source to Paste into Eclipse with 1.5 Source Project Setting

The following test starts an infinite loop with the attached document in CodeFormatter. I can also paste this into eclipse and get the same problem.

If I deactivate the option 1.5, it runs without the loop.
the attached file is not syntactically correct, but shouldn't create such a loop anyway.
I have Kepler SR2 64 bit with JDK 8 extension.


void test() throws IOException {
		StringBuffer src = new StringBuffer();
		for (String line : Files
				.readAllLines(Paths
						.get(".../reformatExample.txt"))) {
			src.append(line);
		}
		String source = src.toString();
		final Map<String, String> options = JavaCore.getOptions();
		options.put(JavaCore.COMPILER_SOURCE, "1.5");
		final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
		final TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, source, 0,
				source.length(), 0, "\r\n");
		assert edit != null;
	}
Comment 1 Manoj N Palat CLA 2014-04-28 04:38:39 EDT
Problem dates back to Helios - 3.6.2 (atleast - yet to check earlier) - able to reproduce. Too late to get into M7, but would continue on this to get this into 4.4
Comment 2 Manoj N Palat CLA 2014-05-08 04:01:22 EDT
moving to 4.5
Comment 3 Manoj N Palat CLA 2014-07-28 01:33:46 EDT
Created attachment 245419 [details]
workaround wip

This workaround avoids infinite loop by graceful(?) bail-out after trying out for some n times - wip
Comment 4 Manoj N Palat CLA 2014-08-05 04:12:01 EDT
Moving it out of M1 since no solution found yet. Would commit the workaround post M1.
Comment 5 Manoj N Palat CLA 2014-09-11 02:40:38 EDT
moving out of M2
Comment 6 Manoj N Palat CLA 2015-03-23 03:49:50 EDT
Fixed via formatter redesign bug 303519 commit - see bug 303519 comment 106 as well.

test case committed via : http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=aa1251a9bb09d2814faa35f8263b76de31ef315e
Comment 7 Sasikanth Bharadwaj CLA 2015-04-27 07:57:34 EDT
Verified for M7 using I20150426-2000 build