Bug 418681 - [templates] Template "${name:newName(name)}" causes stack overflow when evaluated
Summary: [templates] Template "${name:newName(name)}" causes stack overflow when evalu...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.3.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-04 10:02 EDT by Johannes Dorn CLA
Modified: 2022-07-12 13:13 EDT (History)
3 users (show)

See Also:


Attachments
.log file (374.44 KB, application/octet-stream)
2013-10-04 10:02 EDT, Johannes Dorn CLA
no flags Details
Mac OS X crash report (165.01 KB, text/plain)
2013-10-04 11:11 EDT, Johannes Dorn CLA
no flags Details
Screen shots Attached. (46.84 KB, image/png)
2013-10-05 01:06 EDT, Martin Mathew CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Dorn CLA 2013-10-04 10:02:08 EDT
Created attachment 236114 [details]
.log file

Hi,

inserting a template that has the following statement will crash Eclipse to desktop:

${foo:newName(foo)}


This happens only if the id and the parameter name are identical. A statement like below will work:

${foo:newName(bar)}


I would assume that the first statement should be legal and work correctly. If it is for some reason not a legal statement, the template editor should report an error and not let me save the template. At the very least, Eclipse should not crash completely.

I have attached the .log file for such a crash.
Comment 1 Dani Megert CLA 2013-10-04 10:39:04 EDT
> I have attached the .log file for such a crash.

Are you sure this is related to the crash? If so, can you please delete the .log, apply the template and then attach that .log.

Please also look for a VM dump which probably gives more hints than the .log.

In which editor do you apply the template?
Comment 2 Johannes Dorn CLA 2013-10-04 11:11:01 EDT
Created attachment 236119 [details]
Mac OS X crash report
Comment 3 Johannes Dorn CLA 2013-10-04 11:12:10 EDT
I've been unable to create a vm dump for this.
You can find a Mac OS X crash report attached.
Comment 4 Martin Mathew CLA 2013-10-05 01:06:55 EDT
Created attachment 236135 [details]
Screen shots Attached.

Could not test in Mac OS. Tested in Windows 7 using Eclipse build: I20130916-0900, attaching the error dialog displayed while inserting the template into the Java editor. The program goes into an infinite loop. Below is the stack trace:

java.lang.StackOverflowError
	at org.eclipse.jface.text.templates.TemplateVariableType.getName(TemplateVariableType.java:52)
	at org.eclipse.jface.text.templates.TemplateVariable.getType(TemplateVariable.java:141)
	at org.eclipse.jface.text.templates.TemplateContextType.resolve(TemplateContextType.java:269)
	at org.eclipse.jdt.internal.corext.template.java.JavaContext.getTemplateVariable(JavaContext.java:764)
	at org.eclipse.jdt.internal.corext.template.java.NameResolver.resolve(NameResolver.java:57)
	at org.eclipse.jface.text.templates.TemplateContextType.resolve(TemplateContextType.java:273)
	at org.eclipse.jdt.internal.corext.template.java.JavaContext.getTemplateVariable(JavaContext.java:764)
Comment 5 Dani Megert CLA 2013-10-07 05:17:43 EDT
Sorry I didn't spot this at the first read: you define a new id 'foo' and try to find a variable of type 'foo'. This seems to confuse the resolver, leading to a stack overflow - it does not crash the VM (at least on Windows with Oracle JRE 7).


java.lang.StackOverflowError
	at java.util.Collections$UnmodifiableList.get(Collections.java:1211)
	at org.eclipse.jdt.internal.corext.template.java.NameResolver.resolve(NameResolver.java:55)
	at org.eclipse.jface.text.templates.TemplateContextType.resolve(TemplateContextType.java:273)
	at org.eclipse.jdt.internal.corext.template.java.JavaContext.getTemplateVariable(JavaContext.java:764)
	at org.eclipse.jdt.internal.corext.template.java.NameResolver.resolve(NameResolver.java:57)
	at org.eclipse.jface.text.templates.TemplateContextType.resolve(TemplateContextType.java:273)
	at org.eclipse.jdt.internal.corext.template.java.JavaContext.getTemplateVariable(JavaContext.java:764)
	at org.eclipse.jdt.internal.corext.template.java.NameResolver.resolve(NameResolver.java:57)
	at org.eclipse.jface.text.templates.TemplateContextType.resolve(TemplateContextType.java:273)
	at org.eclipse.jdt.internal.corext.template.java.JavaContext.getTemplateVariable(JavaContext.java:764)
	at org.eclipse.jdt.internal.corext.template.java.NameResolver.resolve(NameResolver.java:57)
	at org.eclipse.jface.text.templates.TemplateContextType.resolve(TemplateContextType.java:273)
	at 
...
Comment 6 Eclipse Genie CLA 2020-06-05 20:06:08 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 7 Eclipse Genie CLA 2022-07-12 13:13:32 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.