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

Bug 377919

Summary: [templates] "Template Evaluation Error" error-dialog is displayed when formatter adds newline in code template
Product: [Eclipse Project] JDT Reporter: Andre Bargull <andrebargull+eclipse>
Component: TextAssignee: JDT-Text-Inbox <jdt-text-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, tobias.gierke
Version: 3.8Keywords: helpwanted
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
log-file with stacktrace none

Description Andre Bargull CLA 2012-04-27 10:32:54 EDT
Build Identifier: Version: Indigo Service Release 2 Build id: 20120216-1857

The following "Template Evaluation Error" is displayed when the formatter adds a newline in a generated code template:
---
First position: 'object1, object2' at 251, this position: 'object1,
    ' at 345
---


Reproducible: Always

Steps to Reproduce:
Changed 'systrace' template to include actual parameters,
Preferences > Java > Editor > Templates > 'systrace':
---
System.out.println("${enclosing_type}.${enclosing_method}(${enclosing_method_arguments}) = " + java.util.Arrays.deepToString(new Object[]{${enclosing_method_arguments}}));
---


Code to reproduce:
---
package bugs;

public class EclipseTemplateEvalError {
  public void someLongMethodName(Object object1, Object object2) {
    // Enter 'systrace' and hit ctrl+space
  }
}
---
Comment 1 Dani Megert CLA 2012-04-30 05:37:49 EDT
Works for me using latest 3.8 build (I20120429-2000). If you can still reproduce with a latest 3.8 or 4.2 build then please reopen and also attach your formatter profile. Also, check of there's anything in the .log.
Comment 2 Andre Bargull CLA 2012-04-30 09:49:56 EDT
Does "formatter profile" refer to the current code formatter settings (under Preferences > Java > Code Style > Formatter) or that something else? If it's the former, the active profile is left as-is, that means "Eclipse [built-in]" is still selected. 

Apart from that, bugzilla seems to have split the example 'systrace' template into several lines. Actually that should be one single line. 

Also when trying to reproduce the bug, make sure that the parameters are emitted by the template engine across multiple lines. Like in:
---
deepToString(new Object[]{object1, <newline> object2})
---
where <newline> is the line-separator.
Comment 3 Andre Bargull CLA 2012-04-30 09:56:54 EDT
Created attachment 214802 [details]
log-file with stacktrace

The "BadLocationException" stacktrace entry from the log file is the important one for this bug. I'm not sure how the other exception (AssertionFailedException) got into the log-file. 

Version used to reproduce the error message: "Eclipse 4.2.0 Integration Build: I20120429-1800"
Comment 4 Dani Megert CLA 2012-04-30 10:47:35 EDT
> Apart from that, bugzilla seems to have split the example 'systrace' template
> into several lines. Actually that should be one single line. 

That's the key. I can reproduce now.
Comment 5 Tobias Gierke CLA 2014-09-11 04:26:47 EDT
Any news on this ? This bug is still present in Luna , Build id: 20140612-0600
Comment 6 Dani Megert CLA 2014-10-21 03:55:41 EDT
(In reply to Tobias Gierke from comment #5)
> Any news on this ? This bug is still present in Luna , Build id:
> 20140612-0600

No one is working on this. A high quality patch is welcome.
Comment 7 Eclipse Genie CLA 2019-06-03 13:19:45 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 8 Dani Megert CLA 2019-06-04 10:40:14 EDT
This works for me using https://download.eclipse.org/eclipse/downloads/drops4/S-4.12RC1a-201905310245/