Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.1-beta-1
-
Fix Version/s: 1.5.2
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
This code has a problem at least in the last <% %>:
class A {
def static engine = new groovy.text.SimpleTemplateEngine()
def static templt = engine.createTemplate('''
<html>
<body>
<% if(a == 1) %>
a == 1
<% else %>
a != 1
<% %>
</body>
</html>
''')
}
a = new A()
println a.templt.make([a: 1])
it produces:
Caught: java.lang.ExceptionInInitializerError
at t.class$(t.groovy)
at t.run(t.groovy:16)
at t.main(t.groovy)
which gives no clue that the problem is in the template body (I suppose I always have to use if-statement with curly brackets).
It is almost impossible to track this error in a real environment with big template sitting not even in the code but somewhere else.
If I replace the hole <bod...</body> with <body><%></body> the error is the same.
If I change template variable declaration to non-static, the error is a bit better but still not good:
Caught: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
failed, Script1.groovy: 5: unexpected token: ; @ line 5, column 33.
1 error
at A.<init>(t.groovy:3)
at t.run(t.groovy:16)
at t.main(t.groovy)
Where this Script1.groovy comes from? I have no ';' in my code ...
And when such code is used in Netbeans application, you can even see class not found exceptions which makes you think in a completely different direction.