Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 c203787e1 -> 0a6ee3e3a


Template.name (getName()) was renamed to Template.lookupName (getLookupName()), 
and Template.sourceName (Template.getSourceName()) doesn't fall back to the 
lookup name anymore when it's null (however, Template.getSourceOrLookupName() 
was added for that). There's no Template.name anymore, because since sourceName 
was introduced, and hence the concept of tempalte name was split into the 
lookup and the source name, it's meaning wasn't clean (but it meant the lookup 
name). TemplateException and ParseException now also have the same properites: 
getTemplateSourceName(), getTemplateLookupName(), and even 
getSourceOrLookupName(). Location information in error messages show 
getSourceOrLookupName().


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/0a6ee3e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/0a6ee3e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/0a6ee3e3

Branch: refs/heads/3
Commit: 0a6ee3e3ad1be37c9fa8c229aa7eeac9acf94485
Parents: c203787
Author: ddekany <[email protected]>
Authored: Sat Apr 15 23:45:35 2017 +0200
Committer: ddekany <[email protected]>
Committed: Sat Apr 15 23:45:35 2017 +0200

----------------------------------------------------------------------
 .../apache/freemarker/core/ASTDirImport.java    |   2 +-
 .../apache/freemarker/core/ASTDirInclude.java   |   2 +-
 .../freemarker/core/ASTExpBuiltInVariable.java  |   4 +-
 .../freemarker/core/ASTExpStringLiteral.java    |   2 +-
 .../freemarker/core/BuiltInsForStringsMisc.java |   4 +-
 .../org/apache/freemarker/core/Environment.java |   2 +-
 .../org/apache/freemarker/core/MessageUtil.java |  21 +---
 .../apache/freemarker/core/ParseException.java  | 103 +++++++++--------
 .../org/apache/freemarker/core/Template.java    | 111 ++++++++++---------
 .../freemarker/core/TemplateException.java      |  33 +++++-
 .../core/debug/RmiDebuggedEnvironmentImpl.java  |   2 +-
 .../core/debug/RmiDebuggerService.java          |   2 +-
 .../TemplateLookupStrategy.java                 |   2 +-
 .../core/util/OptInTemplateClassResolver.java   |   2 +-
 .../freemarker/dom/JaxenXPathSupport.java       |   4 +-
 src/main/javacc/FTL.jj                          |  16 +--
 src/manual/en_US/FM3-CHANGE-LOG.txt             |   8 +-
 .../freemarker/core/ConfigurationTest.java      |  24 ++--
 .../EnvironmentGetTemplateVariantsTest.java     |   4 +-
 .../apache/freemarker/core/ExceptionTest.java   |   6 +-
 .../core/TemplateConstructorsTest.java          |  24 ++--
 .../core/TemplateLookupStrategyTest.java        |  35 +++---
 .../DefaultTemplateResolverTest.java            |   6 +-
 .../TemplateNameFormatTest.java                 |   2 +-
 24 files changed, 234 insertions(+), 187 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/ASTDirImport.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/ASTDirImport.java 
b/src/main/java/org/apache/freemarker/core/ASTDirImport.java
index 72009a8..38e88bf 100644
--- a/src/main/java/org/apache/freemarker/core/ASTDirImport.java
+++ b/src/main/java/org/apache/freemarker/core/ASTDirImport.java
@@ -49,7 +49,7 @@ final class ASTDirImport extends ASTDirective {
         final String importedTemplateName = 
importedTemplateNameExp.evalAndCoerceToPlainText(env);
         final String fullImportedTemplateName;
         try {
-            fullImportedTemplateName = 
env.toFullTemplateName(getTemplate().getName(), importedTemplateName);
+            fullImportedTemplateName = 
env.toFullTemplateName(getTemplate().getLookupName(), importedTemplateName);
         } catch (MalformedTemplateNameException e) {
             throw new _MiscTemplateException(e, env,
                     "Malformed template name ", new 
_DelayedJQuote(e.getTemplateName()), ":\n",

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/ASTDirInclude.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/ASTDirInclude.java 
b/src/main/java/org/apache/freemarker/core/ASTDirInclude.java
index 46f71f3..2088d62 100644
--- a/src/main/java/org/apache/freemarker/core/ASTDirInclude.java
+++ b/src/main/java/org/apache/freemarker/core/ASTDirInclude.java
@@ -66,7 +66,7 @@ final class ASTDirInclude extends ASTDirective {
         final String includedTemplateName = 
includedTemplateNameExp.evalAndCoerceToPlainText(env);
         final String fullIncludedTemplateName;
         try {
-            fullIncludedTemplateName = 
env.toFullTemplateName(getTemplate().getName(), includedTemplateName);
+            fullIncludedTemplateName = 
env.toFullTemplateName(getTemplate().getLookupName(), includedTemplateName);
         } catch (MalformedTemplateNameException e) {
             throw new _MiscTemplateException(e, env,
                     "Malformed template name ", new 
_DelayedJQuote(e.getTemplateName()), ":\n",

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/ASTExpBuiltInVariable.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/freemarker/core/ASTExpBuiltInVariable.java 
b/src/main/java/org/apache/freemarker/core/ASTExpBuiltInVariable.java
index 9110fd3..ca34a7d 100644
--- a/src/main/java/org/apache/freemarker/core/ASTExpBuiltInVariable.java
+++ b/src/main/java/org/apache/freemarker/core/ASTExpBuiltInVariable.java
@@ -200,12 +200,12 @@ final class ASTExpBuiltInVariable extends ASTExpression {
             return env.getCurrentVisitorNode();
         }
         if (name == MAIN_TEMPLATE_NAME || name == MAIN_TEMPLATE_NAME_CC) {
-            return 
SimpleScalar.newInstanceOrNull(env.getMainTemplate().getName());
+            return 
SimpleScalar.newInstanceOrNull(env.getMainTemplate().getLookupName());
         }
         // [FM3] Some of these two should be removed.
         if (name == CURRENT_TEMPLATE_NAME || name == CURRENT_TEMPLATE_NAME_CC
                 || name == TEMPLATE_NAME || name == TEMPLATE_NAME_CC) {
-            return 
SimpleScalar.newInstanceOrNull(env.getCurrentTemplate().getName());
+            return 
SimpleScalar.newInstanceOrNull(env.getCurrentTemplate().getLookupName());
         }
         if (name == PASS) {
             return ASTDirMacro.DO_NOTHING_MACRO;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/ASTExpStringLiteral.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/ASTExpStringLiteral.java 
b/src/main/java/org/apache/freemarker/core/ASTExpStringLiteral.java
index e0363e4..96c15df 100644
--- a/src/main/java/org/apache/freemarker/core/ASTExpStringLiteral.java
+++ b/src/main/java/org/apache/freemarker/core/ASTExpStringLiteral.java
@@ -78,7 +78,7 @@ final class ASTExpStringLiteral extends ASTExpression 
implements TemplateScalarM
                     parser.tearDownStringLiteralMode(parentTkMan);
                 }
             } catch (ParseException e) {
-                e.setTemplateName(parentTemplate.getSourceName());
+                e.setTemplate(parentTemplate);
                 throw e;
             }
             constantValue = null;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java 
b/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java
index b33ede0..21c2a9d 100644
--- a/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java
+++ b/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java
@@ -124,7 +124,7 @@ class BuiltInsForStringsMisc {
      * transform model that evaluates the template in place.
      * The template inherits the configuration and environment of the executing
      * template. By default, its name will be equal to 
-     * <tt>executingTemplate.getName() + "$anonymous_interpreted"</tt>. You can
+     * <tt>executingTemplate.getLookupName() + "$anonymous_interpreted"</tt>. 
You can
      * specify another parameter to the method call in which case the
      * template name suffix is the specified id instead of 
"anonymous_interpreted".
      */
@@ -171,7 +171,7 @@ class BuiltInsForStringsMisc {
                 ParsingConfiguration pCfg = 
parentTemplate.getParsingConfiguration();
                 // pCfg.outputFormat+autoEscapingPolicy is exceptional: it's 
inherited from the lexical context
                 interpretedTemplate = new Template(
-                        (parentTemplate.getName() != null ? 
parentTemplate.getName() : "nameless_template") + "->" + id,
+                        (parentTemplate.getLookupName() != null ? 
parentTemplate.getLookupName() : "nameless_template") + "->" + id,
                         null,
                         new StringReader(templateSource),
                         parentTemplate.getConfiguration(), 
parentTemplate.getTemplateConfiguration(),

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/Environment.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/Environment.java 
b/src/main/java/org/apache/freemarker/core/Environment.java
index 3834f99..220f305 100644
--- a/src/main/java/org/apache/freemarker/core/Environment.java
+++ b/src/main/java/org/apache/freemarker/core/Environment.java
@@ -2808,7 +2808,7 @@ public final class Environment extends 
MutableProcessingConfiguration<Environmen
             // As we have an already normalized name, we use it. 2.3.x note: 
We should use the template.sourceName as
             // namespace key, but historically we use the looked up name 
(template.name); check what lazy import does if
             // that will be oms, as that can't do the template lookup, yet the 
keys must be the same.
-            templateName = loadedTemplate.getName();
+            templateName = loadedTemplate.getLookupName();
         } else {
             lazyImport = true;
             // We can't cause a template lookup here (see 
TemplateLookupStrategy), as that can be expensive. We exploit

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/MessageUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/MessageUtil.java 
b/src/main/java/org/apache/freemarker/core/MessageUtil.java
index 5401ce2..6a2bc2f 100644
--- a/src/main/java/org/apache/freemarker/core/MessageUtil.java
+++ b/src/main/java/org/apache/freemarker/core/MessageUtil.java
@@ -60,16 +60,8 @@ class MessageUtil {
         return formatLocation("in", template, line, column);
     }
 
-    static String formatLocationForSimpleParsingError(String 
templateSourceName, int line, int column) {
-        return formatLocation("in", templateSourceName, line, column);
-    }
-
-    static String formatLocationForDependentParsingError(Template template, 
int line, int column) {
-        return formatLocation("on", template, line, column);
-    }
-
-    static String formatLocationForDependentParsingError(String 
templateSourceName, int line, int column) {
-        return formatLocation("on", templateSourceName, line, column);
+    static String formatLocationForSimpleParsingError(String 
templateSourceOrLookupName, int line, int column) {
+        return formatLocation("in", templateSourceOrLookupName, line, column);
     }
 
     static String formatLocationForEvaluationError(Template template, int 
line, int column) {
@@ -78,15 +70,12 @@ class MessageUtil {
 
     static String formatLocationForEvaluationError(ASTDirMacro macro, int 
line, int column) {
         Template t = macro.getTemplate();
-        return formatLocation("at", t != null ? t.getSourceName() : null, 
macro.getName(), macro.isFunction(), line, column);
-    }
-
-    static String formatLocationForEvaluationError(String templateSourceName, 
int line, int column) {
-        return formatLocation("at", templateSourceName, line, column);
+        return formatLocation("at", t != null ? t.getSourceOrLookupName() : 
null, macro.getName(), macro.isFunction(),
+                line, column);
     }
 
     private static String formatLocation(String preposition, Template 
template, int line, int column) {
-        return formatLocation(preposition, template != null ? 
template.getSourceName() : null, line, column);
+        return formatLocation(preposition, template != null ? 
template.getSourceOrLookupName() : null, line, column);
     }
 
     private static String formatLocation(String preposition, String 
templateSourceName, int line, int column) {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/ParseException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/ParseException.java 
b/src/main/java/org/apache/freemarker/core/ParseException.java
index ef4d0e8..9e5dad3 100644
--- a/src/main/java/org/apache/freemarker/core/ParseException.java
+++ b/src/main/java/org/apache/freemarker/core/ParseException.java
@@ -24,6 +24,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.freemarker.core.util._NullArgumentException;
 import org.apache.freemarker.core.util._SecurityUtil;
 import org.apache.freemarker.core.util._StringUtil;
 
@@ -77,7 +78,8 @@ public class ParseException extends IOException implements 
FMParserConstants {
      */
     protected String eol = _SecurityUtil.getSystemProperty("line.separator", 
"\n");
 
-    private String templateName;
+    private String templateSourceName;
+    private String templateLookupName;
 
     /**
      * This constructor is used by the method "generateParseException"
@@ -124,11 +126,21 @@ public class ParseException extends IOException 
implements FMParserConstants {
     public ParseException(String description, Template template,
             int lineNumber, int columnNumber, int endLineNumber, int 
endColumnNumber,
             Throwable cause) {
-        this(description,
-                template == null ? null : template.getSourceName(),
-                        lineNumber, columnNumber,
-                        endLineNumber, endColumnNumber,
-                        cause);      
+        super(description);  // but we override getMessage, so it will be 
different
+        try {
+            initCause(cause);
+        } catch (Exception e) {
+            // Suppressed; we can't do more
+        }
+        this.description = description;
+        if (template != null) { // Allowed because sometimes the template is 
set later via setTemplate(Template)
+            templateSourceName = template.getSourceName();
+            templateLookupName = template.getLookupName();
+        }
+        this.lineNumber = lineNumber;
+        this.columnNumber = columnNumber;
+        this.endLineNumber = endLineNumber;
+        this.endColumnNumber = endColumnNumber;
     }
     
     /**
@@ -143,46 +155,28 @@ public class ParseException extends IOException 
implements FMParserConstants {
      */
     public ParseException(String description, Template template, Token tk, 
Throwable cause) {
         this(description,
-                template == null ? null : template.getSourceName(),
-                        tk.beginLine, tk.beginColumn,
-                        tk.endLine, tk.endColumn,
-                        cause);
+                template,
+                tk.beginLine, tk.beginColumn,
+                tk.endLine, tk.endColumn,
+                cause);
     }
 
     /**
      * @since 2.3.20
      */
-    public ParseException(String description, ASTNode tobj) {
-        this(description, tobj, null);
+    public ParseException(String description, ASTNode astNode) {
+        this(description, astNode, null);
     }
 
     /**
      * @since 2.3.20
      */
-    public ParseException(String description, ASTNode tobj, Throwable cause) {
+    public ParseException(String description, ASTNode astNode, Throwable 
cause) {
         this(description,
-                tobj.getTemplate() == null ? null : 
tobj.getTemplate().getSourceName(),
-                        tobj.beginLine, tobj.beginColumn,
-                        tobj.endLine, tobj.endColumn,
-                        cause);
-    }
-
-    private ParseException(String description, String templateName,
-            int lineNumber, int columnNumber,
-            int endLineNumber, int endColumnNumber,
-            Throwable cause) {
-        super(description);  // but we override getMessage, so it will be 
different
-        try {
-            initCause(cause);
-        } catch (Exception e) {
-            // Suppressed; we can't do more
-        }
-        this.description = description; 
-        this.templateName = templateName;
-        this.lineNumber = lineNumber;
-        this.columnNumber = columnNumber;
-        this.endLineNumber = endLineNumber;
-        this.endColumnNumber = endColumnNumber;
+                astNode.getTemplate(),
+                astNode.beginLine, astNode.beginColumn,
+                astNode.endLine, astNode.endColumn,
+                cause);
     }
 
     /**
@@ -190,8 +184,10 @@ public class ParseException extends IOException implements 
FMParserConstants {
      * This is needed as the constructor that JavaCC automatically calls 
doesn't pass in the template, so we
      * set it somewhere later in an exception handler. 
      */
-    public void setTemplateName(String templateName) {
-        this.templateName = templateName;
+    public void setTemplate(Template template) {
+        _NullArgumentException.check("template", template);
+        templateSourceName = template.getSourceName();
+        templateLookupName = template.getLookupName();
         synchronized (this) {
             messageAndDescriptionRendered = false;
             message = null;
@@ -202,7 +198,8 @@ public class ParseException extends IOException implements 
FMParserConstants {
      * Returns the error location plus the error description.
      * 
      * @see #getDescription()
-     * @see #getTemplateName()
+     * @see #getTemplateSourceName()
+     * @see #getTemplateLookupName()
      * @see #getLineNumber()
      * @see #getColumnNumber()
      */
@@ -237,13 +234,28 @@ public class ParseException extends IOException 
implements FMParserConstants {
     }
 
     /**
-     * Returns the name (template-root relative path) of the template whose 
parsing was failed.
-     * Maybe {@code null} if this is a non-stored template. 
-     * 
-     * @since 2.3.20
+     * Returns the {@linkplain Template#getLookupName()} lookup name} of the 
template whose parsing was failed.
+     * Maybe {@code null}, for example if this is a non-stored template.
+     */
+    public String getTemplateLookupName() {
+        return templateLookupName;
+    }
+
+    /**
+     * Returns the {@linkplain Template#getSourceName()} source name} of the 
template whose parsing was failed.
+     * Maybe {@code null}, for example if this is a non-stored template.
+     */
+    public String getTemplateSourceName() {
+        return templateSourceName;
+    }
+
+    /**
+     * Returns the {@linkplain #getTemplateSourceName() template source name}, 
or if that's {@code null} then the
+     * {@linkplain #getTemplateLookupName() template lookup name}. This name 
is primarily meant to be used in error
+     * messages.
      */
-    public String getTemplateName() {
-        return templateName;
+    public String getTemplateSourceOrLookupName() {
+        return getTemplateSourceName() != null ? getTemplateSourceName() : 
getTemplateLookupName();
     }
 
     /**
@@ -285,7 +297,8 @@ public class ParseException extends IOException implements 
FMParserConstants {
         String prefix;
         if (!isInJBossToolsMode()) {
             prefix = "Syntax error "
-                    + 
MessageUtil.formatLocationForSimpleParsingError(templateName, lineNumber, 
columnNumber)
+                    + 
MessageUtil.formatLocationForSimpleParsingError(getTemplateSourceOrLookupName(),
 lineNumber,
+                    columnNumber)
                     + ":\n";  
         } else {
             prefix = "[col. " + columnNumber + "] ";

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/Template.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/Template.java 
b/src/main/java/org/apache/freemarker/core/Template.java
index 6359d67..23082b2 100644
--- a/src/main/java/org/apache/freemarker/core/Template.java
+++ b/src/main/java/org/apache/freemarker/core/Template.java
@@ -95,7 +95,7 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
 
     // TODO [FM3] We want to get rid of these, thenthe same Template object 
could be reused for different lookups.
     // Template lookup parameters:
-    private final String name;
+    private final String lookupName;
     private Locale lookupLocale;
     private Serializable customLookupCondition;
 
@@ -125,36 +125,36 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
     /**
      * Same as {@link #Template(String, String, Reader, Configuration)} with 
{@code null} {@code sourceName} parameter.
      */
-    public Template(String name, Reader reader, Configuration cfg) throws 
IOException {
-        this(name, null, reader, cfg);
+    public Template(String lookupName, Reader reader, Configuration cfg) 
throws IOException {
+        this(lookupName, null, reader, cfg);
     }
 
     /**
      * Convenience constructor for {@link #Template(String, Reader, 
Configuration)
-     * Template(name, new StringReader(reader), cfg)}.
+     * Template(lookupName, new StringReader(reader), cfg)}.
      * 
      * @since 2.3.20
      */
-    public Template(String name, String sourceCode, Configuration cfg) throws 
IOException {
-        this(name, new StringReader(sourceCode), cfg);
+    public Template(String lookupName, String sourceCode, Configuration cfg) 
throws IOException {
+        this(lookupName, new StringReader(sourceCode), cfg);
     }
 
     /**
      * Convenience constructor for {@link #Template(String, String, Reader, 
Configuration, TemplateConfiguration,
-     * Charset) Template(name, null, new StringReader(reader), cfg), tc, null}.
+     * Charset) Template(lookupName, null, new StringReader(reader), cfg), tc, 
null}.
      *
      * @since 2.3.20
      */
-    public Template(String name, String sourceCode, Configuration cfg, 
TemplateConfiguration tc) throws IOException {
-        this(name, null, new StringReader(sourceCode), cfg, tc, null);
+    public Template(String lookupName, String sourceCode, Configuration cfg, 
TemplateConfiguration tc) throws IOException {
+        this(lookupName, null, new StringReader(sourceCode), cfg, tc, null);
     }
 
     /**
-     * Convenience constructor for {@link #Template(String, String, Reader, 
Configuration, Charset) Template(name, null,
+     * Convenience constructor for {@link #Template(String, String, Reader, 
Configuration, Charset) Template(lookupName, null,
      * reader, cfg, sourceEncoding)}.
      */
-    public Template(String name, Reader reader, Configuration cfg, Charset 
sourceEncoding) throws IOException {
-        this(name, null, reader, cfg, sourceEncoding);
+    public Template(String lookupName, Reader reader, Configuration cfg, 
Charset sourceEncoding) throws IOException {
+        this(lookupName, null, reader, cfg, sourceEncoding);
     }
 
     /**
@@ -162,11 +162,15 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
      * performance matters, you should re-use (cache) {@link Template} 
instances instead of re-creating them from the
      * same source again and again. ({@link Configuration#getTemplate(String) 
and its overloads already do such reuse.})
      * 
-     * @param name
-     *            The path of the template file relatively to the (virtual) 
directory that you use to store the
-     *            templates (except if {@link #Template(String, String, 
Reader, Configuration, Charset) sourceName}
-     *            differs from it). Shouldn't start with {@code '/'}. Should 
use {@code '/'}, not {@code '\'}. Check
-     *            {@link #getName()} to see how the name will be used. The 
name should be independent of the actual
+     * @param lookupName
+     *            The name (path) with which the template was get (usually via
+     *            {@link Configuration#getTemplate(String)}), after basic 
normalization. (Basic normalization means
+     *            things that doesn't require accessing the backing storage, 
such as {@code "/a/../b/foo.ftl"}
+     *            becomes to {@code "b/foo.ftl"}).
+     *            This is usually the path of the template file relatively to 
the (virtual) directory that you use to
+     *            store the templates (except if the {@link #getSourceName()}  
sourceName} differs from it).
+     *            Shouldn't start with {@code '/'}. Should use {@code '/'}, 
not {@code '\'}. Check
+     *            {@link #getLookupName()} to see how the name will be used. 
The name should be independent of the actual
      *            storage mechanism and physical location as far as possible. 
Even when the templates are stored
      *            straightforwardly in real files (they often aren't; see 
{@link TemplateLoader}), the name shouldn't be
      *            an absolute file path. Like if the template is stored in 
{@code "/www/templates/forum/main.ftl"}, and
@@ -177,8 +181,8 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
      *            the template root directory (and here again, it's the {@link 
TemplateLoader} that knows what that
      *            "physically" means).
      * @param sourceName
-     *            See {@link #getSourceName()} for the meaning. Can be {@code 
null}, in which case
-     *            {@link #getSourceName()} will return the same as {@link 
#getName()}.
+     *            Often the same as the {@code lookupName}; see {@link 
#getSourceName()} for more. Can be
+     *            {@code null}, in which case error messages will fall back to 
use {@link #getLookupName()}.
      * @param reader
      *            The character stream to read from. The {@link Reader} is 
<em>not</em> closed by this method (unlike
      *            in FreeMarker 2.x.x), so be sure that it's closed somewhere. 
(Except of course, readers like
@@ -190,8 +194,8 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
      * @since 2.3.22
      */
    public Template(
-           String name, String sourceName, Reader reader, Configuration cfg) 
throws IOException {
-       this(name, sourceName, reader, cfg, null);
+           String lookupName, String sourceName, Reader reader, Configuration 
cfg) throws IOException {
+       this(lookupName, sourceName, reader, cfg, null);
    }
 
     /**
@@ -207,9 +211,9 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
      * @since 2.3.22
      */
    public Template(
-           String name, String sourceName, Reader reader, Configuration cfg, 
Charset actualSourceEncoding) throws
+           String lookupName, String sourceName, Reader reader, Configuration 
cfg, Charset actualSourceEncoding) throws
            IOException {
-       this(name, sourceName, reader, cfg, null, actualSourceEncoding);
+       this(lookupName, sourceName, reader, cfg, null, actualSourceEncoding);
    }
 
     /**
@@ -229,10 +233,10 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
      * @since 2.3.24
      */
    public Template(
-           String name, String sourceName, Reader reader,
+           String lookupName, String sourceName, Reader reader,
            Configuration cfg, TemplateConfiguration templateConfiguration,
            Charset actualSourceEncoding) throws IOException {
-       this(name, sourceName, reader, cfg, templateConfiguration, 
actualSourceEncoding, null);
+       this(lookupName, sourceName, reader, cfg, templateConfiguration, 
actualSourceEncoding, null);
     }
 
     /**
@@ -248,10 +252,10 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
      *         mark consumes some resources, so you may want to release it as 
soon as possible.
      */
     public Template(
-            String name, String sourceName, Reader reader,
+            String lookupName, String sourceName, Reader reader,
             Configuration cfg, TemplateConfiguration templateConfiguration,
             Charset actualSourceEncoding, InputStream 
streamToUnmarkWhenEncEstabd) throws IOException, ParseException {
-        this(name, sourceName, reader,
+        this(lookupName, sourceName, reader,
                 cfg, templateConfiguration,
                 null, null,
                 actualSourceEncoding, streamToUnmarkWhenEncEstabd);
@@ -274,7 +278,7 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
      *         Similar to {@code contextOutputFormat}; usually this and the 
that is set together.
      */
    Template(
-            String name, String sourceName, Reader reader,
+            String lookupName, String sourceName, Reader reader,
             Configuration configuration, TemplateConfiguration 
templateConfiguration,
             OutputFormat contextOutputFormat, Integer 
contextAutoEscapingPolicy,
             Charset actualSourceEncoding, InputStream 
streamToUnmarkWhenEncEstabd) throws IOException, ParseException {
@@ -282,7 +286,7 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
         this.cfg = configuration;
         this.tCfg = templateConfiguration;
         this.parsingConfiguration = tCfg != null ? new 
TemplateParsingConfigurationWithFallback(cfg, tCfg) : cfg;
-        this.name = name;
+        this.lookupName = lookupName;
         this.sourceName = sourceName;
 
         setActualSourceEncoding(actualSourceEncoding);
@@ -321,7 +325,7 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
                 throw exc.toParseException(this);
             }
         } catch (ParseException e) {
-            e.setTemplateName(getSourceName());
+            e.setTemplate(this);
             throw e;
         }
         
@@ -337,15 +341,15 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
      * Same as {@link #createPlainTextTemplate(String, String, String, 
Configuration, Charset)} with {@code null}
      * {@code sourceName} argument.
      */
-    static public Template createPlainTextTemplate(String name, String 
content, Configuration config) {
-        return createPlainTextTemplate(name, null, content, config, null);
+    static public Template createPlainTextTemplate(String lookupName, String 
content, Configuration config) {
+        return createPlainTextTemplate(lookupName, null, content, config, 
null);
     }
 
     /**
      * Creates a {@link Template} that only contains a single block of static 
text, no dynamic content.
      * 
-     * @param name
-     *            See {@link #getName} for more details.
+     * @param lookupName
+     *            See {@link #getLookupName} for more details.
      * @param sourceName
      *            See {@link #getSourceName} for more details. If {@code 
null}, it will be the same as the {@code name}.
      * @param content
@@ -359,11 +363,11 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
      *
      * @since 2.3.22
      */
-    static public Template createPlainTextTemplate(String name, String 
sourceName, String content, Configuration config,
+    static public Template createPlainTextTemplate(String lookupName, String 
sourceName, String content, Configuration config,
                Charset sourceEncoding) {
         Template template;
         try {
-            template = new Template(name, sourceName, new StringReader("X"), 
config);
+            template = new Template(lookupName, sourceName, new 
StringReader("X"), config);
         } catch (IOException e) {
             throw new BugException("Plain text template creation failed", e);
         }
@@ -538,8 +542,9 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
 
 
     /**
-     * The usually path-like (or URL-like) identifier of the template, or 
possibly {@code null} for non-stored
-     * templates. It usually looks like a relative UN*X path; it should use 
{@code /}, not {@code \}, and shouldn't
+     * The usually path-like (or URL-like) normalized identifier of the 
template, with which the template was get
+     * (usually via {@link Configuration#getTemplate(String)}), or possibly 
{@code null} for non-stored templates.
+     * It usually looks like a relative UN*X path; it should use {@code /}, 
not {@code \}, and shouldn't
      * start with {@code /} (but there are no hard guarantees). It's not a 
real path in a file-system, it's just a name
      * that a {@link TemplateLoader} used to load the backing resource (in 
simple cases; actually that name is
      * {@link #getSourceName()}, but see it there). Or, it can also be a name 
that was never used to load the template
@@ -564,25 +569,31 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
      * notation, so an absolute path like {@code "/baaz.ftl"} in that template 
will be resolved too
      * {@code "someSchema://baaz.ftl"}.
      */
-    public String getName() {
-        return name;
+    public String getLookupName() {
+        return lookupName;
     }
 
     /**
      * The name that was actually used to load this template from the {@link 
TemplateLoader} (or from other custom
      * storage mechanism). This is what should be shown in error messages as 
the error location. This is usually the
-     * same as {@link #getName()}, except when localized lookup, template 
acquisition ({@code *} step in the name), or
-     * other {@link TemplateLookupStrategy} transforms the requested name 
({@link #getName()}) to a different final
-     * {@link TemplateLoader}-level name. For example, when you get a template 
with name {@code "foo.ftl"} then because
-     * of localized lookup, it's possible that something like {@code 
"foo_en.ftl"} will be loaded behind the scenes.
-     * While the template name will be still the same as the requested 
template name ({@code "foo.ftl"}), errors should
-     * point to {@code "foo_de.ftl"}. Note that relative paths are always 
resolved relatively to the {@code name}, not
-     * to the {@code sourceName}.
-     * 
-     * @since 2.3.22
+     * same as {@link #getLookupName()}, except when localized lookup, 
template acquisition ({@code *} step in the
+     * name), or other {@link TemplateLookupStrategy} transforms the requested 
name ({@link #getLookupName()}) to a
+     * different final {@link TemplateLoader}-level name. For example, when 
you get a template with name {@code "foo
+     * .ftl"} then because of localized lookup, it's possible that something 
like {@code "foo_en.ftl"} will be loaded
+     * behind the scenes. While the template name will be still the same as 
the requested template name ({@code "foo
+     * .ftl"}), errors should point to {@code "foo_de.ftl"}. Note that 
relative paths are always resolved relatively
+     * to the {@code name}, not to the {@code sourceName}.
      */
     public String getSourceName() {
-        return sourceName != null ? sourceName : getName();
+        return sourceName;
+    }
+
+    /**
+     * Returns the {@linkplain #getSourceName() source name}, or if that's 
{@code null} then the
+     * {@linkplain #getLookupName() lookup name}. This name is primarily meant 
to be used in error messages.
+     */
+    public String getSourceOrLookupName() {
+        return getSourceName() != null ? getSourceName() : getLookupName();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/TemplateException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/TemplateException.java 
b/src/main/java/org/apache/freemarker/core/TemplateException.java
index 064fe4e..3ca9914 100644
--- a/src/main/java/org/apache/freemarker/core/TemplateException.java
+++ b/src/main/java/org/apache/freemarker/core/TemplateException.java
@@ -53,6 +53,7 @@ public class TemplateException extends Exception {
     private boolean blamedExpressionStringCalculated;
     private String blamedExpressionString;
     private boolean positionsCalculated;
+    private String templateLookupName;
     private String templateSourceName;
     private Integer lineNumber; 
     private Integer columnNumber; 
@@ -195,7 +196,8 @@ public class TemplateException extends Exception {
                 // Line number blow 0 means no info, negative means position 
in ?eval-ed value that we won't use here.
                 if (templateObject != null && templateObject.getBeginLine() > 
0) {
                     final Template template = templateObject.getTemplate();
-                    templateSourceName = template != null ? 
template.getSourceName() : null;
+                    templateLookupName = template.getLookupName();
+                    templateSourceName = template.getSourceName();
                     lineNumber = 
Integer.valueOf(templateObject.getBeginLine());
                     columnNumber = 
Integer.valueOf(templateObject.getBeginColumn());
                     endLineNumber = 
Integer.valueOf(templateObject.getEndLine());
@@ -453,9 +455,9 @@ public class TemplateException extends Exception {
     }
 
     /**
-     * Returns the source name ({@link Template#getSourceName()}) of the 
template where the error has occurred, or
+     * Returns the {@linkplain Template#getSourceName() source name} of the 
template where the error has occurred, or
      * {@code null} if the information isn't available. This is what should be 
used for showing the error position.
-     * 
+     *
      * @since 2.3.22
      */
     public String getTemplateSourceName() {
@@ -466,7 +468,30 @@ public class TemplateException extends Exception {
             return templateSourceName;
         }
     }
-    
+
+    /**
+     * Returns the {@linkplain Template#getLookupName()} () lookup name} of 
the template where the error has
+     * occurred, or {@code null} if the information isn't available. Do not 
use this for showing the error position;
+     * use {@link #getTemplateSourceName()}.
+     */
+    public String getTemplateLookupName() {
+        synchronized (lock) {
+            if (!positionsCalculated) {
+                calculatePosition();
+            }
+            return templateLookupName;
+        }
+    }
+
+    /**
+     * Returns the {@linkplain #getTemplateSourceName() template source name}, 
or if that's {@code null} then the
+     * {@linkplain #getTemplateLookupName() template lookup name}. This name 
is primarily meant to be used in error
+     * messages.
+     */
+    public String getTemplateSourceOrLookupName() {
+        return getTemplateSourceName() != null ? getTemplateSourceName() : 
getTemplateLookupName();
+    }
+
     /**
      * 1-based column number of the failing section, or {@code null} if the 
information is not available.
      * 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/debug/RmiDebuggedEnvironmentImpl.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/freemarker/core/debug/RmiDebuggedEnvironmentImpl.java
 
b/src/main/java/org/apache/freemarker/core/debug/RmiDebuggedEnvironmentImpl.java
index c42af46..ce49afb 100644
--- 
a/src/main/java/org/apache/freemarker/core/debug/RmiDebuggedEnvironmentImpl.java
+++ 
b/src/main/java/org/apache/freemarker/core/debug/RmiDebuggedEnvironmentImpl.java
@@ -233,7 +233,7 @@ class RmiDebuggedEnvironmentImpl extends RmiDebugModelImpl 
implements DebuggedEn
 
         DebugTemplateModel(Template template) {
             super(template);
-            name = new SimpleScalar(template.getName());
+            name = new SimpleScalar(template.getLookupName());
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/debug/RmiDebuggerService.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/freemarker/core/debug/RmiDebuggerService.java 
b/src/main/java/org/apache/freemarker/core/debug/RmiDebuggerService.java
index afa0ec0..e44d398 100644
--- a/src/main/java/org/apache/freemarker/core/debug/RmiDebuggerService.java
+++ b/src/main/java/org/apache/freemarker/core/debug/RmiDebuggerService.java
@@ -125,7 +125,7 @@ extends
     
     @Override
     void registerTemplateSpi(Template template) {
-        String templateName = template.getName();
+        String templateName = template.getLookupName();
         synchronized (templateDebugInfos) {
             TemplateDebugInfo tdi = createTemplateDebugInfo(templateName);
             tdi.templates.add(new TemplateReference(templateName, template, 
refQueue));

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/templateresolver/TemplateLookupStrategy.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/freemarker/core/templateresolver/TemplateLookupStrategy.java
 
b/src/main/java/org/apache/freemarker/core/templateresolver/TemplateLookupStrategy.java
index ef2ad04..25efdf0 100644
--- 
a/src/main/java/org/apache/freemarker/core/templateresolver/TemplateLookupStrategy.java
+++ 
b/src/main/java/org/apache/freemarker/core/templateresolver/TemplateLookupStrategy.java
@@ -38,7 +38,7 @@ import org.apache.freemarker.core.Template;
  * <li>A template lookup strategy meant to operate solely with template names, 
not with {@link TemplateLoader}-s
  * directly. Basically, it's a mapping between the template names that 
templates and API-s like
  * {@link Configuration#getTemplate(String)} see, and those that the 
underlying {@link TemplateLoader} sees.
- * <li>A template lookup strategy doesn't influence the template's name 
({@link Template#getName()}), which is the
+ * <li>A template lookup strategy doesn't influence the template's name 
({@link Template#getLookupName()}), which is the
  * normalized form of the template name as it was requested (with {@link 
Configuration#getTemplate(String)}, etc.). It
  * only influences the so called source name of the template ({@link 
Template#getSourceName()}). The template's name is
  * used as the basis for resolving relative inclusions/imports in the 
template. The source name is pretty much only used

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/core/util/OptInTemplateClassResolver.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/freemarker/core/util/OptInTemplateClassResolver.java 
b/src/main/java/org/apache/freemarker/core/util/OptInTemplateClassResolver.java
index 8fd7b38..e1edfcb 100644
--- 
a/src/main/java/org/apache/freemarker/core/util/OptInTemplateClassResolver.java
+++ 
b/src/main/java/org/apache/freemarker/core/util/OptInTemplateClassResolver.java
@@ -123,7 +123,7 @@ public class OptInTemplateClassResolver implements 
TemplateClassResolver {
     protected String safeGetTemplateName(Template template) {
         if (template == null) return null;
         
-        String name = template.getName();
+        String name = template.getLookupName();
         if (name == null) return null;
 
         // Detect exploits, return null if one is suspected:

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/java/org/apache/freemarker/dom/JaxenXPathSupport.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/dom/JaxenXPathSupport.java 
b/src/main/java/org/apache/freemarker/dom/JaxenXPathSupport.java
index f578158..3e52836 100644
--- a/src/main/java/org/apache/freemarker/dom/JaxenXPathSupport.java
+++ b/src/main/java/org/apache/freemarker/dom/JaxenXPathSupport.java
@@ -205,7 +205,7 @@ class JaxenXPathSupport implements XPathSupport {
     // [FM3] Look into this "hidden" feature
     static Template getTemplate(String systemId) throws IOException {
         Environment env = Environment.getCurrentEnvironment();
-        String templatePath = env.getCurrentTemplate().getName();
+        String templatePath = env.getCurrentTemplate().getLookupName();
         int lastSlash = templatePath.lastIndexOf('/');
         templatePath = lastSlash == -1 ? "" : templatePath.substring(0, 
lastSlash + 1);
         systemId = env.toFullTemplateName(templatePath, systemId);
@@ -221,7 +221,7 @@ class JaxenXPathSupport implements XPathSupport {
         }
         InputSource is = new InputSource();
         is.setPublicId(publicId);
-        is.setSystemId(raw.getName());
+        is.setSystemId(raw.getLookupName());
         is.setCharacterStream(new StringReader(sw.toString()));
         return is;
     }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/main/javacc/FTL.jj
----------------------------------------------------------------------
diff --git a/src/main/javacc/FTL.jj b/src/main/javacc/FTL.jj
index 14a2fe7..dc6079f 100644
--- a/src/main/javacc/FTL.jj
+++ b/src/main/javacc/FTL.jj
@@ -193,27 +193,27 @@ public class FMParser {
     }
 
     private OutputFormat getFormatFromStdFileExt() {
-        String sourceName = template.getSourceName();
-        if (sourceName == null) {
+        String name = template.getSourceOrLookupName();
+        if (name == null) {
             return null;
         }
 
-        int ln = sourceName.length();
+        int ln = name.length();
         if (ln < 5) return null;
 
-        char c = sourceName.charAt(ln - 5);
+        char c = name.charAt(ln - 5);
         if (c != '.') return null;
 
-        c = sourceName.charAt(ln - 4);
+        c = name.charAt(ln - 4);
         if (c != 'f' && c != 'F') return null;
 
-        c = sourceName.charAt(ln - 3);
+        c = name.charAt(ln - 3);
         if (c != 't' && c != 'T') return null;
 
-        c = sourceName.charAt(ln - 2);
+        c = name.charAt(ln - 2);
         if (c != 'l' && c != 'L') return null;
 
-        c = sourceName.charAt(ln - 1);
+        c = name.charAt(ln - 1);
         try {
             // Note: We get the output formats by name, so that custom 
overrides take effect.
             if (c == 'h' || c == 'H') {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/manual/en_US/FM3-CHANGE-LOG.txt
----------------------------------------------------------------------
diff --git a/src/manual/en_US/FM3-CHANGE-LOG.txt 
b/src/manual/en_US/FM3-CHANGE-LOG.txt
index 6964df3..96774bf 100644
--- a/src/manual/en_US/FM3-CHANGE-LOG.txt
+++ b/src/manual/en_US/FM3-CHANGE-LOG.txt
@@ -205,4 +205,10 @@ the FreeMarer 3 changelog here:
   sourceEncoding used during parsing.)
 - Made TemplateModel classes used by the parser for literals Serializable. 
(Without this attribute values set in the #ftl
   header wouldn't be always Serializable, which in turn will sabotage making 
Template-s Serializable in the future.)
-- Removed hasCustomFormats() from configuration related API-s (we don't need 
it anymore)
\ No newline at end of file
+- Removed hasCustomFormats() from configuration related API-s (we don't need 
it anymore)
+- Template.name (getName()) was renamed to Template.lookupName 
(getLookupName()), and Template.sourceName (Template.getSourceName())
+  doesn't fall back to the lookup name anymore when it's null (however, 
Template.getSourceOrLookupName() was added for that). There's
+  no Template.name anymore, because since sourceName was introduced, and hence 
the concept of tempalte name was split into the
+  lookup and the source name, it's meaning wasn't clean (but it meant the 
lookup name). TemplateException and ParseException 
+  now also have the same properites: getTemplateSourceName(), 
getTemplateLookupName(), and even getSourceOrLookupName().
+  Location information in error messages show getSourceOrLookupName().
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/test/java/org/apache/freemarker/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/ConfigurationTest.java 
b/src/test/java/org/apache/freemarker/core/ConfigurationTest.java
index 6d83128..9c8b264 100644
--- a/src/test/java/org/apache/freemarker/core/ConfigurationTest.java
+++ b/src/test/java/org/apache/freemarker/core/ConfigurationTest.java
@@ -277,7 +277,7 @@ public class ConfigurationTest extends TestCase {
         // 1 args:
         {
             Template t = cfg.getTemplate(tFtl);
-            assertEquals(tFtl, t.getName());
+            assertEquals(tFtl, t.getLookupName());
             assertEquals(tFtl, t.getSourceName());
             assertEquals(Locale.GERMAN, t.getLocale());
             assertNull(t.getCustomLookupCondition());
@@ -285,7 +285,7 @@ public class ConfigurationTest extends TestCase {
         }
         {
             Template t = cfg.getTemplate(tUtf8Ftl);
-            assertEquals(tUtf8Ftl, t.getName());
+            assertEquals(tUtf8Ftl, t.getLookupName());
             assertEquals(tUtf8Ftl, t.getSourceName());
             assertEquals(Locale.GERMAN, t.getLocale());
             assertNull(t.getCustomLookupCondition());
@@ -295,7 +295,7 @@ public class ConfigurationTest extends TestCase {
         // 2 args:
         {
             Template t = cfg.getTemplate(tFtl, Locale.GERMAN);
-            assertEquals(tFtl, t.getName());
+            assertEquals(tFtl, t.getLookupName());
             assertEquals(tFtl, t.getSourceName());
             assertEquals(Locale.GERMAN, t.getLocale());
             assertNull(t.getCustomLookupCondition());
@@ -303,7 +303,7 @@ public class ConfigurationTest extends TestCase {
         }
         {
             Template t = cfg.getTemplate(tFtl, (Locale) null);
-            assertEquals(tFtl, t.getName());
+            assertEquals(tFtl, t.getLookupName());
             assertEquals(tFtl, t.getSourceName());
             assertEquals(Locale.GERMAN, t.getLocale());
             assertNull(t.getCustomLookupCondition());
@@ -311,7 +311,7 @@ public class ConfigurationTest extends TestCase {
         }
         {
             Template t = cfg.getTemplate(tFtl, Locale.US);
-            assertEquals(tFtl, t.getName());
+            assertEquals(tFtl, t.getLookupName());
             assertEquals(tEnFtl, t.getSourceName());
             assertEquals(Locale.US, t.getLocale());
             assertNull(t.getCustomLookupCondition());
@@ -319,7 +319,7 @@ public class ConfigurationTest extends TestCase {
         }
         {
             Template t = cfg.getTemplate(tUtf8Ftl, Locale.US);
-            assertEquals(tUtf8Ftl, t.getName());
+            assertEquals(tUtf8Ftl, t.getLookupName());
             assertEquals(tUtf8Ftl, t.getSourceName());
             assertEquals(Locale.US, t.getLocale());
             assertNull(t.getCustomLookupCondition());
@@ -327,7 +327,7 @@ public class ConfigurationTest extends TestCase {
         }
         {
             Template t = cfg.getTemplate(tFtl, hu);
-            assertEquals(tFtl, t.getName());
+            assertEquals(tFtl, t.getLookupName());
             assertEquals(tHuFtl, t.getSourceName());
             assertEquals(hu, t.getLocale());
             assertNull(t.getCustomLookupCondition());
@@ -335,7 +335,7 @@ public class ConfigurationTest extends TestCase {
         }
         {
             Template t = cfg.getTemplate(tUtf8Ftl, hu);
-            assertEquals(tUtf8Ftl, t.getName());
+            assertEquals(tUtf8Ftl, t.getLookupName());
             assertEquals(tUtf8Ftl, t.getSourceName());
             assertEquals(hu, t.getLocale());
             assertNull(t.getCustomLookupCondition());
@@ -352,7 +352,7 @@ public class ConfigurationTest extends TestCase {
         assertNull(cfg.getTemplate("missing.ftl", hu, custLookupCond, true));
         {
             Template t = cfg.getTemplate(tFtl, hu, custLookupCond, false);
-            assertEquals(tFtl, t.getName());
+            assertEquals(tFtl, t.getLookupName());
             assertEquals(tHuFtl, t.getSourceName());
             assertEquals(hu, t.getLocale());
             assertEquals(custLookupCond, t.getCustomLookupCondition());
@@ -361,7 +361,7 @@ public class ConfigurationTest extends TestCase {
         }
         {
             Template t = cfg.getTemplate(tFtl, null, custLookupCond, false);
-            assertEquals(tFtl, t.getName());
+            assertEquals(tFtl, t.getLookupName());
             assertEquals(tFtl, t.getSourceName());
             assertEquals(Locale.GERMAN, t.getLocale());
             assertEquals(custLookupCond, t.getCustomLookupCondition());
@@ -459,7 +459,7 @@ public class ConfigurationTest extends TestCase {
         {
             cfg.setTemplateNameFormat(DefaultTemplateNameFormatFM2.INSTANCE);
             final Template template = cfg.getTemplate("a/./../b.ftl");
-            assertEquals("a/b.ftl", template.getName());
+            assertEquals("a/b.ftl", template.getLookupName());
             assertEquals("a/b.ftl", template.getSourceName());
             assertEquals("In a/b.ftl", template.toString());
         }
@@ -467,7 +467,7 @@ public class ConfigurationTest extends TestCase {
         {
             cfg.setTemplateNameFormat(DefaultTemplateNameFormat.INSTANCE);
             final Template template = cfg.getTemplate("a/./../b.ftl");
-            assertEquals("b.ftl", template.getName());
+            assertEquals("b.ftl", template.getLookupName());
             assertEquals("b.ftl", template.getSourceName());
             assertEquals("In b.ftl", template.toString());
         }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/test/java/org/apache/freemarker/core/EnvironmentGetTemplateVariantsTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/freemarker/core/EnvironmentGetTemplateVariantsTest.java
 
b/src/test/java/org/apache/freemarker/core/EnvironmentGetTemplateVariantsTest.java
index f29c655..a82b29c 100644
--- 
a/src/test/java/org/apache/freemarker/core/EnvironmentGetTemplateVariantsTest.java
+++ 
b/src/test/java/org/apache/freemarker/core/EnvironmentGetTemplateVariantsTest.java
@@ -201,8 +201,8 @@ public class EnvironmentGetTemplateVariantsTest extends 
TemplateTest {
             public void execute(Environment env, Map params, TemplateModel[] 
loopVars, TemplateDirectiveBody body)
                     throws TemplateException, IOException {
                 Writer out = env.getOut();
-                final String r = "<ct=" + env.getCurrentTemplate().getName() + 
" mt="
-                        + env.getMainTemplate().getName() + ">";
+                final String r = "<ct=" + 
env.getCurrentTemplate().getLookupName() + " mt="
+                        + env.getMainTemplate().getLookupName() + ">";
                 out.write(r);
                 env.setGlobalVariable("lastTNamesResult", new SimpleScalar(r));
             }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/test/java/org/apache/freemarker/core/ExceptionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/ExceptionTest.java 
b/src/test/java/org/apache/freemarker/core/ExceptionTest.java
index 6430eba..e70869e 100644
--- a/src/test/java/org/apache/freemarker/core/ExceptionTest.java
+++ b/src/test/java/org/apache/freemarker/core/ExceptionTest.java
@@ -80,7 +80,8 @@ public class ExceptionTest extends TestCase {
             t.process(null, _NullWriter.INSTANCE);
             fail();
         } catch (TemplateException e) {
-            assertEquals("foo.ftl", t.getName());
+            assertEquals("foo.ftl", t.getLookupName());
+            assertEquals("foo.ftl", e.getTemplateLookupName());
             assertEquals("foo_en.ftl", e.getTemplateSourceName());
             assertEquals(3, (int) e.getLineNumber());
             assertEquals(6, (int) e.getColumnNumber());
@@ -104,7 +105,8 @@ public class ExceptionTest extends TestCase {
             fail();
         } catch (ParseException e) {
             System.out.println(e.getMessage());
-            assertEquals("foo_en.ftl", e.getTemplateName());
+            assertEquals("foo_en.ftl", e.getTemplateSourceName());
+            assertEquals("foo.ftl", e.getTemplateLookupName());
             assertEquals(3, e.getLineNumber());
             assertEquals(5, e.getColumnNumber());
             assertEquals(3, e.getEndLineNumber());

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java 
b/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
index f0fe11f..93a57b1 100644
--- a/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
+++ b/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
@@ -44,50 +44,50 @@ public class TemplateConstructorsTest {
         final Charset sourceEncoding = StandardCharsets.UTF_16LE;
         {
             Template t = new Template(name, createReader(), cfg);
-            assertEquals(name, t.getName());
-            assertEquals(name, t.getSourceName());
+            assertEquals(name, t.getLookupName());
+            assertNull(t.getSourceName());
             assertEquals(CONTENT, t.toString());
             assertNull(t.getActualSourceEncoding());
         }
         {
             Template t = new Template(name, CONTENT, cfg);
-            assertEquals(name, t.getName());
-            assertEquals(name, t.getSourceName());
+            assertEquals(name, t.getLookupName());
+            assertNull(t.getSourceName());
             assertEquals(CONTENT, t.toString());
             assertNull(t.getActualSourceEncoding());
         }
         {
             Template t = new Template(name, CONTENT_FORCE_UTF8, cfg);
-            assertEquals(name, t.getName());
-            assertEquals(name, t.getSourceName());
+            assertEquals(name, t.getLookupName());
+            assertNull(t.getSourceName());
             // assertEquals(CONTENT_FORCE_UTF8, t.toString()); // FIXME the 
#ftl header is missing from the dump, why?
             assertNull(t.getActualSourceEncoding()); // Because it was created 
from a String
         }
         {
             Template t = new Template(name, createReader(), cfg, 
sourceEncoding);
-            assertEquals(name, t.getName());
-            assertEquals(name, t.getSourceName());
+            assertEquals(name, t.getLookupName());
+            assertNull(t.getSourceName());
             assertEquals(CONTENT, t.toString());
             assertEquals(StandardCharsets.UTF_16LE, 
t.getActualSourceEncoding());
         }
         {
             Template t = new Template(name, sourceName, createReader(), cfg);
-            assertEquals(name, t.getName());
+            assertEquals(name, t.getLookupName());
             assertEquals(sourceName, t.getSourceName());
             assertEquals(CONTENT, t.toString());
             assertNull(t.getActualSourceEncoding());
         }
         {
             Template t = new Template(name, sourceName, createReader(), cfg, 
sourceEncoding);
-            assertEquals(name, t.getName());
+            assertEquals(name, t.getLookupName());
             assertEquals(sourceName, t.getSourceName());
             assertEquals(CONTENT, t.toString());
             assertEquals(StandardCharsets.UTF_16LE, 
t.getActualSourceEncoding());
         }
         {
             Template t = Template.createPlainTextTemplate(name, CONTENT, cfg);
-            assertEquals(name, t.getName());
-            assertEquals(name, t.getSourceName());
+            assertEquals(name, t.getLookupName());
+            assertNull(t.getSourceName());
             assertEquals(CONTENT, t.toString());
             assertNull(t.getActualSourceEncoding());
         }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/test/java/org/apache/freemarker/core/TemplateLookupStrategyTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/freemarker/core/TemplateLookupStrategyTest.java 
b/src/test/java/org/apache/freemarker/core/TemplateLookupStrategyTest.java
index 062d8e1..95a396d 100644
--- a/src/test/java/org/apache/freemarker/core/TemplateLookupStrategyTest.java
+++ b/src/test/java/org/apache/freemarker/core/TemplateLookupStrategyTest.java
@@ -74,7 +74,7 @@ public class TemplateLookupStrategyTest {
         
         {
             final Template t = cfg.getTemplate("test.ftl", locale);
-            assertEquals("test.ftl", t.getName());
+            assertEquals("test.ftl", t.getLookupName());
             assertEquals("aa/test.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
             assertNull(t.getCustomLookupCondition());
@@ -156,7 +156,7 @@ public class TemplateLookupStrategyTest {
             {
                 final Locale locale = new Locale("aa", "BB", "CC_DD");
                 final Template t = cfg.getTemplate("test.ftl", locale);
-                assertEquals("test.ftl", t.getName());
+                assertEquals("test.ftl", t.getLookupName());
                 assertEquals("test_aa_BB_CC_DD.ftl", t.getSourceName());
                 assertEquals(locale, t.getLocale());
                 assertNull(t.getCustomLookupCondition());
@@ -169,7 +169,7 @@ public class TemplateLookupStrategyTest {
             {
                 final Locale locale = new Locale("aa", "BB", "CC_XX");
                 final Template t = cfg.getTemplate(templateName, locale);
-                assertEquals("test.ftl", t.getName());
+                assertEquals("test.ftl", t.getLookupName());
                 assertEquals("test_aa_BB_CC.ftl", t.getSourceName());
                 assertEquals(locale, t.getLocale());
                 assertNull(t.getCustomLookupCondition());
@@ -181,7 +181,7 @@ public class TemplateLookupStrategyTest {
             {
                 final Locale locale = new Locale("aa", "BB", "XX_XX");
                 final Template t = cfg.getTemplate(templateName, locale);
-                assertEquals("test.ftl", t.getName());
+                assertEquals("test.ftl", t.getLookupName());
                 assertEquals("test_aa_BB.ftl", t.getSourceName());
                 assertEquals(locale, t.getLocale());
                 assertNull(t.getCustomLookupCondition());
@@ -196,7 +196,7 @@ public class TemplateLookupStrategyTest {
                 cfg.setLocalizedLookup(false);
                 final Locale locale = new Locale("aa", "BB", "XX_XX");
                 final Template t = cfg.getTemplate(templateName, locale);
-                assertEquals("test.ftl", t.getName());
+                assertEquals("test.ftl", t.getLookupName());
                 assertEquals("test.ftl", t.getSourceName());
                 assertEquals(locale, t.getLocale());
                 assertNull(t.getCustomLookupCondition());
@@ -211,7 +211,7 @@ public class TemplateLookupStrategyTest {
             {
                 final Locale locale = new Locale("aa", "XX", "XX_XX");
                 final Template t = cfg.getTemplate(templateName, locale);
-                assertEquals("test.ftl", t.getName());
+                assertEquals("test.ftl", t.getLookupName());
                 assertEquals("test_aa.ftl", t.getSourceName());
                 assertEquals(locale, t.getLocale());
                 assertNull(t.getCustomLookupCondition());
@@ -225,7 +225,7 @@ public class TemplateLookupStrategyTest {
             {
                 final Locale locale = new Locale("xx", "XX", "XX_XX");
                 final Template t = cfg.getTemplate(templateName, locale);
-                assertEquals("test.ftl", t.getName());
+                assertEquals("test.ftl", t.getLookupName());
                 assertEquals("test.ftl", t.getSourceName());
                 assertEquals(locale, t.getLocale());
                 assertNull(t.getCustomLookupCondition());
@@ -240,7 +240,7 @@ public class TemplateLookupStrategyTest {
             {
                 final Locale locale = new Locale("xx", "BB", "CC_DD");
                 final Template t = cfg.getTemplate(templateName, locale);
-                assertEquals("test.ftl", t.getName());
+                assertEquals("test.ftl", t.getLookupName());
                 assertEquals("test.ftl", t.getSourceName());
                 assertEquals(locale, t.getLocale());
                 assertNull(t.getCustomLookupCondition());
@@ -268,7 +268,7 @@ public class TemplateLookupStrategyTest {
         
         {
             final Template t = cfg.getTemplate("/./moo/../x/y/*/sub/i.ftl", 
locale);
-            assertEquals("x/y/*/sub/i.ftl", t.getName());
+            assertEquals("x/y/*/sub/i.ftl", t.getLookupName());
             assertEquals("x/sub/i.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
             assertNull(t.getCustomLookupCondition());
@@ -283,7 +283,7 @@ public class TemplateLookupStrategyTest {
 
         {
             final Template t = cfg.getTemplate("a/b/*/./sub/i.ftl", locale);
-            assertEquals("a/b/*/sub/i.ftl", t.getName());
+            assertEquals("a/b/*/sub/i.ftl", t.getLookupName());
             assertEquals("sub/i.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
             assertNull(t.getCustomLookupCondition());
@@ -334,7 +334,7 @@ public class TemplateLookupStrategyTest {
             final Locale locale = new Locale("xx");
             final Domain domain = new Domain("foo.com");
             final Template t = cfg.getTemplate("t.ftl", locale, domain);
-            assertEquals("t.ftl", t.getName());
+            assertEquals("t.ftl", t.getLookupName());
             assertEquals("@foo.com/t.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
             assertEquals(domain, t.getCustomLookupCondition());
@@ -357,7 +357,7 @@ public class TemplateLookupStrategyTest {
             final Locale locale = new Locale("xx");
             final Domain domain = new Domain("bar.com");
             final Template t = cfg.getTemplate("t.ftl", locale, domain);
-            assertEquals("t.ftl", t.getName());
+            assertEquals("t.ftl", t.getLookupName());
             assertEquals("@bar.com/t.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
             assertEquals(domain, t.getCustomLookupCondition());
@@ -382,7 +382,7 @@ public class TemplateLookupStrategyTest {
             final Locale locale = new Locale("xx", "YY");
             final Domain domain = new Domain("baaz.com");
             final Template t = cfg.getTemplate("t.ftl", locale, domain);
-            assertEquals("t.ftl", t.getName());
+            assertEquals("t.ftl", t.getLookupName());
             assertEquals("@default/t.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
             assertEquals(domain, t.getCustomLookupCondition());
@@ -407,7 +407,7 @@ public class TemplateLookupStrategyTest {
             final Locale locale = new Locale("xx", "YY");
             final Domain domain = new Domain("nosuch.com");
             final Template t = cfg.getTemplate("i.ftl", locale, domain);
-            assertEquals("i.ftl", t.getName());
+            assertEquals("i.ftl", t.getLookupName());
             assertEquals("@default/i_xx.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
             assertEquals(domain, t.getCustomLookupCondition());
@@ -427,7 +427,7 @@ public class TemplateLookupStrategyTest {
             final Locale locale = new Locale("xx", "YY");
             final Domain domain = new Domain("nosuch.com");
             final Template t = cfg.getTemplate("i.ftl", locale, domain);
-            assertEquals("i.ftl", t.getName());
+            assertEquals("i.ftl", t.getLookupName());
             assertEquals("@default/i.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
             assertEquals(domain, t.getCustomLookupCondition());
@@ -573,7 +573,7 @@ public class TemplateLookupStrategyTest {
         
         {
             Template t = cfg.getTemplate("test.txt", new Locale("aa", "BB"), 
null, false);
-            assertEquals("test.txt", t.getName());
+            assertEquals("test.txt", t.getLookupName());
             assertEquals("test_aa.txt", t.getSourceName());
             assertEquals(
                     ImmutableList.of(
@@ -596,7 +596,8 @@ public class TemplateLookupStrategyTest {
             cfg.getTemplate("test.ftl", new Locale("aa", "BB"));
             fail();
         } catch (ParseException e) {
-            assertEquals("test_aa.ftl", e.getTemplateName());
+            assertEquals("test_aa.ftl", e.getTemplateSourceName());
+            assertEquals("test.ftl", e.getTemplateLookupName());
         }
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java
 
b/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java
index c33a7ae..e402ba2 100644
--- 
a/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java
+++ 
b/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java
@@ -284,7 +284,7 @@ public class DefaultTemplateResolverTest {
         
         {
             Template t = cfg.getTemplate("utf-8.ftl");
-            assertEquals("utf-8.ftl", t.getName());
+            assertEquals("utf-8.ftl", t.getLookupName());
             assertEquals("utf-8_en.ftl", t.getSourceName());
             assertEquals(StandardCharsets.UTF_8, t.getActualSourceEncoding());
             assertEquals("Béka", t.toString());
@@ -302,7 +302,7 @@ public class DefaultTemplateResolverTest {
             tl.clearEvents();
             
             Template t = cfg.getTemplate("iso-8859-1.ftl");
-            assertEquals("iso-8859-1.ftl", t.getName());
+            assertEquals("iso-8859-1.ftl", t.getLookupName());
             assertEquals("iso-8859-1_en_US.ftl", t.getSourceName());
             assertEquals(StandardCharsets.ISO_8859_1, 
t.getActualSourceEncoding());
             assertEquals("Béka", t.toString());
@@ -329,7 +329,7 @@ public class DefaultTemplateResolverTest {
         
         {
             Template t = cfg.getTemplate("foo.ftl");
-            assertEquals("foo.ftl", t.getName());
+            assertEquals("foo.ftl", t.getLookupName());
             assertEquals("foo_en.ftl", t.getSourceName());
             assertNull(t.getActualSourceEncoding());
             assertEquals("ő", t.toString());

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0a6ee3e3/src/test/java/org/apache/freemarker/core/templateresolver/TemplateNameFormatTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/freemarker/core/templateresolver/TemplateNameFormatTest.java
 
b/src/test/java/org/apache/freemarker/core/templateresolver/TemplateNameFormatTest.java
index 8e01035..013fd64 100644
--- 
a/src/test/java/org/apache/freemarker/core/templateresolver/TemplateNameFormatTest.java
+++ 
b/src/test/java/org/apache/freemarker/core/templateresolver/TemplateNameFormatTest.java
@@ -234,7 +234,7 @@ public class TemplateNameFormatTest {
             final String name = "foo\\bar.ftl";
             
             Template t = cfg.getTemplate(name, Locale.US);
-            assertEquals(name, t.getName());
+            assertEquals(name, t.getLookupName());
             assertEquals(name, t.getSourceName());
             assertEquals(
                     ImmutableList.of(

Reply via email to