You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2026/06/14 15:36:26 UTC

(freemarker) branch 2.3-gae updated: Removed freemarker.debug due to concerns of being flagged for using RMI, and because we believe nobody uses it.

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch 2.3-gae
in repository https://gitbox.apache.org/repos/asf/freemarker.git


The following commit(s) were added to refs/heads/2.3-gae by this push:
     new cbcaa8d6 Removed freemarker.debug due to concerns of being flagged for using RMI, and because we believe nobody uses it.
cbcaa8d6 is described below

commit cbcaa8d64f986e0f9d20738d2c35ec7ff2f35f24
Author: ddekany <dd...@apache.org>
AuthorDate: Sun Jun 14 17:34:19 2026 +0200

    Removed freemarker.debug due to concerns of being flagged for using RMI, and because we believe nobody uses it.
---
 .../src/main/java/freemarker/core/DebugBreak.java  |  31 +-
 .../src/main/java/freemarker/debug/Breakpoint.java |  83 -----
 .../src/main/java/freemarker/debug/DebugModel.java | 105 ------
 .../java/freemarker/debug/DebuggedEnvironment.java |  56 ---
 .../src/main/java/freemarker/debug/Debugger.java   |  95 -----
 .../main/java/freemarker/debug/DebuggerClient.java | 147 --------
 .../java/freemarker/debug/DebuggerListener.java    |  36 --
 .../debug/EnvironmentSuspendedEvent.java           |  67 ----
 .../java/freemarker/debug/impl/DebuggerServer.java | 122 -------
 .../freemarker/debug/impl/DebuggerService.java     |  93 -----
 .../freemarker/debug/impl/RmiDebugModelImpl.java   | 165 ---------
 .../debug/impl/RmiDebuggedEnvironmentImpl.java     | 343 ------------------
 .../freemarker/debug/impl/RmiDebuggerImpl.java     |  90 -----
 .../debug/impl/RmiDebuggerListenerImpl.java        |  66 ----
 .../freemarker/debug/impl/RmiDebuggerService.java  | 395 ---------------------
 .../freemarker/debug/impl/SuppressFBWarnings.java  |  29 --
 .../main/java/freemarker/debug/package-info.java   |  24 --
 .../main/java/freemarker/template/Template.java    |  41 +--
 18 files changed, 20 insertions(+), 1968 deletions(-)

diff --git a/freemarker-core/src/main/java/freemarker/core/DebugBreak.java b/freemarker-core/src/main/java/freemarker/core/DebugBreak.java
index 9ab99ce1..d3e47705 100644
--- a/freemarker-core/src/main/java/freemarker/core/DebugBreak.java
+++ b/freemarker-core/src/main/java/freemarker/core/DebugBreak.java
@@ -19,16 +19,18 @@
 
 package freemarker.core;
 
-import java.io.IOException;
-
-import freemarker.debug.impl.DebuggerService;
 import freemarker.template.TemplateException;
 
+import java.io.IOException;
+
 /**
- * <b>Internal API - subject to change: A debug breakpoint inserted into the template</b> 
- * 
+ * <b>Internal API - subject to change: A debug breakpoint inserted into the template</b>
+ *
+ * <p>Not used anymore: This was used by {@code freemarker.debug} package, which was removed. We left it here in case
+ * some tools that traverse the AST links to this class.</p>
+ *
  * @deprecated This is an internal FreeMarker API with no backward compatibility guarantees, so you shouldn't depend on
- *             it.
+ * it.
  */
 @Deprecated
 public class DebugBreak extends TemplateElement {
@@ -36,15 +38,12 @@ public class DebugBreak extends TemplateElement {
         addChild(nestedBlock);
         copyLocationFrom(nestedBlock);
     }
-    
+
     @Override
     protected TemplateElement[] accept(Environment env) throws TemplateException, IOException {
-        if (!DebuggerService.suspendEnvironment(
-                env, this.getTemplate().getSourceName(), getChild(0).getBeginLine())) {
-            return getChild(0).accept(env);
-        } else {
-            throw new StopException(env, "Stopped by debugger");
-        }
+        // This was conditional before freemarker.debug was removed. DebugBreak was kept to decrease the change of
+        // backward compatibility issues.
+        throw new StopException(env, "Stopped by debugger");
     }
 
     @Override
@@ -57,7 +56,7 @@ public class DebugBreak extends TemplateElement {
                 sb.append(" /-->");
             } else {
                 sb.append(" -->");
-                sb.append(getChild(0).getCanonicalForm());                
+                sb.append(getChild(0).getCanonicalForm());
                 sb.append("<#--/ debug break -->");
             }
             return sb.toString();
@@ -65,7 +64,7 @@ public class DebugBreak extends TemplateElement {
             return "debug break";
         }
     }
-    
+
     @Override
     String getNodeTypeSymbol() {
         return "#debug_break";
@@ -90,5 +89,5 @@ public class DebugBreak extends TemplateElement {
     boolean isNestedBlockRepeater() {
         return false;
     }
-        
+
 }
diff --git a/freemarker-core/src/main/java/freemarker/debug/Breakpoint.java b/freemarker-core/src/main/java/freemarker/debug/Breakpoint.java
deleted file mode 100644
index f572d895..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/Breakpoint.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug;
-
-import java.io.Serializable;
-
-/**
- * Represents a breakpoint location consisting of a template name and a line number.
- */
-public class Breakpoint implements Serializable, Comparable {
-    private static final long serialVersionUID = 1L;
-
-    private final String templateName;
-    private final int line;
-    
-    /**
-     * Creates a new breakpoint.
-     * @param templateName the name of the template
-     * @param line the line number in the template where to put the breakpoint
-     */
-    public Breakpoint(String templateName, int line) {
-        this.templateName = templateName;
-        this.line = line;
-    }
-
-    /**
-     * Returns the line number of the breakpoint
-     */
-    public int getLine() {
-        return line;
-    }
-    /**
-     * Returns the template name of the breakpoint
-     */
-    public String getTemplateName() {
-        return templateName;
-    }
-
-    @Override
-    public int hashCode() {
-        return templateName.hashCode() + 31 * line;
-    }
-    
-    @Override
-    public boolean equals(Object o) {
-        if (o instanceof Breakpoint) {
-            Breakpoint b = (Breakpoint) o;
-            return b.templateName.equals(templateName) && b.line == line;
-        }
-        return false;
-    }
-    
-    @Override
-    public int compareTo(Object o) {
-        Breakpoint b = (Breakpoint) o;
-        int r = templateName.compareTo(b.templateName);
-        return r == 0 ? line - b.line : r;
-    }
-    
-    /**
-     * Returns the template name and the line number separated with a colon
-     */
-    public String getLocationString() {
-        return templateName + ":" + line;
-    }
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/DebugModel.java b/freemarker-core/src/main/java/freemarker/debug/DebugModel.java
deleted file mode 100644
index c86b256e..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/DebugModel.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug;
-
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-import java.util.Date;
-
-import freemarker.template.TemplateModelException;
-
-/**
- * Represents the debugger-side mirror of a TemplateModel object, a Template
- * object, or a Configuration object. The Environment objects are also represented
- * by instances of this model, although not directly but through a separate
- * subinterface {@link DebuggedEnvironment}. The interface is a union of
- * almost all of FreeMarker template models with identical method signatures.
- * For purposes of optimizing network traffic there are bulk retrieval methods
- * for sequences and hashes, as well as a {@link #getModelTypes()} method that
- * returns a bit mask of various {@code TYPE_xxx} constants flagging which
- * template models are implemented by the mirrored object.
- */
-public interface DebugModel extends Remote {
-    public static final int TYPE_SCALAR        =    1;
-    public static final int TYPE_NUMBER        =    2;
-    public static final int TYPE_DATE          =    4;
-    public static final int TYPE_BOOLEAN       =    8;
-    public static final int TYPE_SEQUENCE      =   16;
-    public static final int TYPE_COLLECTION    =   32;
-    public static final int TYPE_HASH          =   64;
-    public static final int TYPE_HASH_EX       =  128;
-    public static final int TYPE_METHOD        =  256;
-    public static final int TYPE_METHOD_EX     =  512;
-    public static final int TYPE_TRANSFORM     = 1024;
-    public static final int TYPE_ENVIRONMENT   = 2048;
-    public static final int TYPE_TEMPLATE      = 4096;
-    public static final int TYPE_CONFIGURATION = 8192;
-    
-    public String getAsString()
-    throws TemplateModelException,
-        RemoteException;
-        
-    public Number getAsNumber()
-    throws TemplateModelException,
-        RemoteException;
-    
-    public boolean getAsBoolean()
-    throws TemplateModelException,
-        RemoteException;
-    
-    public Date getAsDate()
-    throws TemplateModelException,
-        RemoteException;
-    
-    public int getDateType()
-    throws TemplateModelException,
-        RemoteException;
-        
-    public int size()
-    throws TemplateModelException,
-        RemoteException;
-        
-    public DebugModel get(int index)
-    throws TemplateModelException,
-        RemoteException;
-    
-    public DebugModel[] get(int fromIndex, int toIndex)
-    throws TemplateModelException,
-        RemoteException;
-        
-    public DebugModel get(String key)
-    throws TemplateModelException,
-        RemoteException;
-        
-    public DebugModel[] get(String[] keys)
-    throws TemplateModelException,
-        RemoteException;
-    
-    public DebugModel[] getCollection()
-    throws TemplateModelException,
-        RemoteException;
-
-    public String[] keys()
-    throws TemplateModelException,
-        RemoteException;
-    
-    public int getModelTypes()
-    throws RemoteException;
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/DebuggedEnvironment.java b/freemarker-core/src/main/java/freemarker/debug/DebuggedEnvironment.java
deleted file mode 100644
index 6000c8a5..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/DebuggedEnvironment.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug;
-
-import java.rmi.RemoteException;
-
-/**
- * Represents the debugger-side mirror of a debugged 
- * {@link freemarker.core.Environment} object in the remote VM. This interface
- * extends {@link DebugModel}, and the properties of the Environment are exposed
- * as hash keys on it. Specifically, the following keys are supported:
- * "currentNamespace", "dataModel", "globalNamespace", "knownVariables", 
- * "mainNamespace", and "template".
- * <p>The debug model for the template supports keys "configuration" and "name".
- * <p>The debug model for the configuration supports key "sharedVariables".
- * <p>Additionally, all of the debug models for environment, template, and 
- * configuration also support all the setting keys of 
- * {@link freemarker.core.Configurable} objects. 
-
- */
-public interface DebuggedEnvironment extends DebugModel {
-    /**
-     * Resumes the processing of the environment in the remote VM after it was 
-     * stopped on a breakpoint.
-     */
-    public void resume() throws RemoteException;
-    
-    /**
-     * Stops the processing of the environment after it was stopped on
-     * a breakpoint. Causes a {@link freemarker.core.StopException} to be
-     * thrown in the processing thread in the remote VM. 
-     */
-    public void stop() throws RemoteException;
-    
-    /**
-     * Returns a unique identifier for this environment
-     */
-    public long getId() throws RemoteException;
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/Debugger.java b/freemarker-core/src/main/java/freemarker/debug/Debugger.java
deleted file mode 100644
index 464d8e4d..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/Debugger.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug;
-
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * The main debugger interface. Allows management of breakpoints as well as
- * installation of listeners for debug events.
- */
-public interface Debugger extends Remote {
-    public static final int DEFAULT_PORT = 7011;
-
-    /**
-     * Adds a breakpoint
-     * @param breakpoint the breakpoint to add
-     */
-    public void addBreakpoint(Breakpoint breakpoint)
-    throws RemoteException;
-    
-    /**
-     * Removes a single breakpoint
-     * @param breakpoint the breakpoint to remove
-     */
-    public void removeBreakpoint(Breakpoint breakpoint)
-    throws RemoteException;
-
-    /**
-     * Removes all breakpoints for a specific template
-     */
-    public void removeBreakpoints(String templateName)
-    throws RemoteException;
-
-    /**
-     * Removes all breakpoints
-     */
-    public void removeBreakpoints()
-    throws RemoteException;
-
-    /**
-     * Retrieves a list of all {@link Breakpoint} objects.
-     */
-    public List getBreakpoints()
-    throws RemoteException;
-        
-    /**
-     * Retrieves a list of all {@link Breakpoint} objects for the specified
-     * template.
-     */
-    public List getBreakpoints(String templateName)
-    throws RemoteException;
-
-    /**
-     * Retrieves a collection of all {@link DebuggedEnvironment} objects that 
-     * are currently suspended.
-     */
-    public Collection getSuspendedEnvironments()
-    throws RemoteException;
-        
-    /**
-     * Adds a listener for debugger events.
-     * @return an identification token that should be passed to 
-     * {@link #removeDebuggerListener(Object)} to remove this listener.
-     */
-    public Object addDebuggerListener(DebuggerListener listener)
-    throws RemoteException;
-        
-    /**
-     * Removes a previously added debugger listener.
-     * @param id the identification token for the listener that was returned
-     * from a prior call to {@link #addDebuggerListener(DebuggerListener)}.
-     */
-    public void removeDebuggerListener(Object id)
-    throws RemoteException;
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/DebuggerClient.java b/freemarker-core/src/main/java/freemarker/debug/DebuggerClient.java
deleted file mode 100644
index c930e41d..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/DebuggerClient.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.nio.charset.StandardCharsets;
-import java.rmi.RemoteException;
-import java.rmi.server.RemoteObject;
-import java.security.MessageDigest;
-import java.util.Collection;
-import java.util.List;
-
-import freemarker.debug.impl.RmiDebuggerListenerImpl;
-import freemarker.template.utility.UndeclaredThrowableException;
-
-/**
- * A utility class that allows you to connect to the FreeMarker debugger service
- * running on a specific host and port. 
- */
-public class DebuggerClient {
-    private DebuggerClient() {
-    }
-    
-    /**
-     * Connects to the FreeMarker debugger service running on a specific host
-     * and port. The Java VM to which the connection is made must have defined
-     * the system property {@code freemarker.debug.password} in order to enable
-     * the debugger service. Additionally, the {@code freemarker.debug.port}
-     * system property can be set to specify the port where the debugger service
-     * is listening. When not specified, it defaults to 
-     * {@link Debugger#DEFAULT_PORT}.
-     * @param host the host address of the machine where the debugger service is
-     * running.
-     * @param port the port of the debugger service
-     * @param password the password required to connect to the debugger service
-     * @return Debugger a debugger object. null is returned in case incorrect
-     * password was supplied.
-     * @throws IOException if an exception occurs.
-     */
-    public static Debugger getDebugger(InetAddress host, int port, String password)
-    throws IOException {
-        try {
-            try (Socket s = new Socket(host, port)) {
-                ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
-                ObjectInputStream in = new ObjectInputStream(s.getInputStream());
-                int protocolVersion = in.readInt();
-                if (protocolVersion > 220) {
-                    throw new IOException(
-                            "Incompatible protocol version " + protocolVersion +
-                                    ". At most 220 was expected.");
-                }
-                byte[] challenge = (byte[]) in.readObject();
-                MessageDigest md = MessageDigest.getInstance("SHA");
-                md.update(password.getBytes(StandardCharsets.UTF_8));
-                md.update(challenge);
-                out.writeObject(md.digest());
-                return new LocalDebuggerProxy((Debugger) in.readObject());
-                //return (Debugger)in.readObject();
-            }
-        } catch (IOException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new UndeclaredThrowableException(e); 
-        }
-    }
-    
-    private static class LocalDebuggerProxy implements Debugger {
-        private final Debugger remoteDebugger;
-
-        LocalDebuggerProxy(Debugger remoteDebugger) {
-            this.remoteDebugger = remoteDebugger;
-        }
-
-        @Override
-        public void addBreakpoint(Breakpoint breakpoint) throws RemoteException {
-            remoteDebugger.addBreakpoint(breakpoint);
-        }
-
-        @Override
-        public Object addDebuggerListener(DebuggerListener listener)
-        throws RemoteException {
-            if (listener instanceof RemoteObject) {
-                return remoteDebugger.addDebuggerListener(listener);
-            } else {
-                RmiDebuggerListenerImpl remotableListener = 
-                    new RmiDebuggerListenerImpl(listener);
-                return remoteDebugger.addDebuggerListener(remotableListener);
-            }
-        }
-
-        @Override
-        public List getBreakpoints() throws RemoteException {
-            return remoteDebugger.getBreakpoints();
-        }
-
-        @Override
-        public List getBreakpoints(String templateName) throws RemoteException {
-            return remoteDebugger.getBreakpoints(templateName);
-        }
-
-        @Override
-        public Collection getSuspendedEnvironments() throws RemoteException {
-            return remoteDebugger.getSuspendedEnvironments();
-        }
-
-        @Override
-        public void removeBreakpoint(Breakpoint breakpoint) throws RemoteException {
-            remoteDebugger.removeBreakpoint(breakpoint);
-        }
-
-        @Override
-        public void removeBreakpoints(String templateName) throws RemoteException {
-            remoteDebugger.removeBreakpoints(templateName);
-        }
-
-        @Override
-        public void removeBreakpoints() throws RemoteException {
-            remoteDebugger.removeBreakpoints();
-        }
-
-        @Override
-        public void removeDebuggerListener(Object id) throws RemoteException {
-            remoteDebugger.removeDebuggerListener(id);
-        }
-    }
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/DebuggerListener.java b/freemarker-core/src/main/java/freemarker/debug/DebuggerListener.java
deleted file mode 100644
index 2a7e0144..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/DebuggerListener.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug;
-
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-import java.util.EventListener;
-
-/**
- * An interface for components that wish to receive debugging events.
- */
-public interface DebuggerListener extends Remote, EventListener {
-    /**
-     * Called whenever an environment gets suspended (ie hits a breakpoint).
-     * @param e the event object
-     */
-    public void environmentSuspended(EnvironmentSuspendedEvent e)
-    throws RemoteException;
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/EnvironmentSuspendedEvent.java b/freemarker-core/src/main/java/freemarker/debug/EnvironmentSuspendedEvent.java
deleted file mode 100644
index 3b080ab7..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/EnvironmentSuspendedEvent.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug;
-
-import java.util.EventObject;
-
-/**
- * Event describing a suspension of an environment (ie because it hit a
- * breakpoint).
- */
-public class EnvironmentSuspendedEvent extends EventObject {
-    private static final long serialVersionUID = 1L;
-
-    private final String name;
-    private final int line;
-    private final DebuggedEnvironment env;
-
-    public EnvironmentSuspendedEvent(Object source, String templateName, int line, DebuggedEnvironment env) {
-        super(source);
-        this.name = templateName;
-        this.line = line;
-        this.env = env;
-    }
-
-    /**
-     * The name of the template where the execution of the environment
-     * was suspended
-     * @return String the template name
-     */
-    public String getName() {
-        return this.name;
-    }
-
-    /**
-     * The line number in the template where the execution of the environment
-     * was suspended.
-     * @return int the line number
-     */
-    public int getLine() {
-        return line;
-    }
-
-    /**
-     * The environment that was suspended
-     * @return DebuggedEnvironment
-     */
-    public DebuggedEnvironment getEnvironment() {
-        return env;
-    }
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/impl/DebuggerServer.java b/freemarker-core/src/main/java/freemarker/debug/impl/DebuggerServer.java
deleted file mode 100644
index 0faaa249..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/impl/DebuggerServer.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug.impl;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.security.SecureRandom;
-import java.util.Arrays;
-import java.util.Random;
-
-import freemarker.debug.Debugger;
-import freemarker.log.Logger;
-import freemarker.template.utility.SecurityUtilities;
-
-/**
- */
-class DebuggerServer {
-    private static final Logger LOG = Logger.getLogger("freemarker.debug.server");
-    // TODO: Eventually replace with Yarrow    
-    private static final Random R = new SecureRandom();
-    
-    private final byte[] password;
-    private final int port;
-    private final Serializable debuggerStub;
-    private boolean stop = false;
-    private ServerSocket serverSocket;
-    
-    public DebuggerServer(Serializable debuggerStub) {
-        port = SecurityUtilities.getSystemProperty("freemarker.debug.port", Debugger.DEFAULT_PORT).intValue();
-        password = SecurityUtilities.getSystemProperty("freemarker.debug.password", "")
-                .getBytes(StandardCharsets.UTF_8);
-        this.debuggerStub = debuggerStub;
-    }
-    
-    public void start() {
-        new Thread(new Runnable()
-        {
-            @Override
-            public void run() {
-                startInternal();
-            }
-        }, "FreeMarker Debugger Server Acceptor").start();
-    }
-    
-    private void startInternal() {
-        try {
-            serverSocket = new ServerSocket(port);
-            while (!stop) {
-                Socket s = serverSocket.accept();
-                new Thread(new DebuggerAuthProtocol(s)).start();
-            }
-        } catch (IOException e) {
-            LOG.error("Debugger server shut down.", e);
-        }
-    }
-    
-    private class DebuggerAuthProtocol implements Runnable {
-        private final Socket s;
-        
-        DebuggerAuthProtocol(Socket s) {
-            this.s = s;
-        }
-        
-        @Override
-        public void run() {
-            try {
-                ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
-                ObjectInputStream in = new ObjectInputStream(s.getInputStream());
-                byte[] challenge = new byte[512];
-                R.nextBytes(challenge);
-                out.writeInt(220); // protocol version
-                out.writeObject(challenge);
-                MessageDigest md = MessageDigest.getInstance("SHA");
-                md.update(password);
-                md.update(challenge);
-                byte[] response = (byte[]) in.readObject();
-                if (Arrays.equals(response, md.digest())) {
-                    out.writeObject(debuggerStub);
-                } else {
-                    out.writeObject(null);
-                }
-            } catch (Exception e) {
-                LOG.warn("Connection to " + s.getInetAddress().getHostAddress() + " abruply broke", e);
-            }
-        }
-
-    }
-
-    public void stop() {
-        this.stop = true;
-        if (serverSocket != null) {
-            try {
-                serverSocket.close();
-            } catch (IOException e) {
-                LOG.error("Unable to close server socket.", e);
-            }
-        }
-    }
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/impl/DebuggerService.java b/freemarker-core/src/main/java/freemarker/debug/impl/DebuggerService.java
deleted file mode 100644
index 75a09aaf..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/impl/DebuggerService.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug.impl;
-
-import java.rmi.RemoteException;
-import java.util.Collections;
-import java.util.List;
-
-import freemarker.core.Environment;
-import freemarker.template.Template;
-import freemarker.template.utility.SecurityUtilities;
-
-/**
- * This class provides debugging hooks for the core FreeMarker engine. It is
- * not usable for anyone outside the FreeMarker core classes. It is public only
- * as an implementation detail.
- */
-public abstract class DebuggerService {
-    private static final DebuggerService instance = createInstance();
-    
-    private static DebuggerService createInstance() {
-        // Creates the appropriate service class. If the debugging is turned
-        // off, this is a fast no-op service, otherwise it's the real-thing
-        // RMI service.
-        return 
-            SecurityUtilities.getSystemProperty("freemarker.debug.password", null) == null
-            ? new NoOpDebuggerService()
-            : new RmiDebuggerService();
-    }
-
-    public static List getBreakpoints(String templateName) {
-        return instance.getBreakpointsSpi(templateName);
-    }
-    
-    abstract List getBreakpointsSpi(String templateName);
-
-    public static void registerTemplate(Template template) {
-        instance.registerTemplateSpi(template);
-    }
-    
-    abstract void registerTemplateSpi(Template template);
-    
-    public static boolean suspendEnvironment(Environment env, String templateName, int line)
-    throws RemoteException {
-        return instance.suspendEnvironmentSpi(env, templateName, line);
-    }
-    
-    abstract boolean suspendEnvironmentSpi(Environment env, String templateName, int line)
-    throws RemoteException;
-
-    abstract void shutdownSpi();
-
-    public static void shutdown() {
-        instance.shutdownSpi();
-    }
-
-    private static class NoOpDebuggerService extends DebuggerService {
-        @Override
-        List getBreakpointsSpi(String templateName) {
-            return Collections.EMPTY_LIST;
-        }
-        
-        @Override
-        boolean suspendEnvironmentSpi(Environment env, String templateName, int line) {
-            throw new UnsupportedOperationException();
-        }
-        
-        @Override
-        void registerTemplateSpi(Template template) {
-        }
-
-        @Override
-        void shutdownSpi() {
-        }
-    }
-}
\ No newline at end of file
diff --git a/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebugModelImpl.java b/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebugModelImpl.java
deleted file mode 100644
index 54dd7c80..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebugModelImpl.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug.impl;
-
-import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import freemarker.debug.DebugModel;
-import freemarker.template.TemplateBooleanModel;
-import freemarker.template.TemplateCollectionModel;
-import freemarker.template.TemplateDateModel;
-import freemarker.template.TemplateHashModel;
-import freemarker.template.TemplateHashModelEx;
-import freemarker.template.TemplateMethodModel;
-import freemarker.template.TemplateMethodModelEx;
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateModelException;
-import freemarker.template.TemplateModelIterator;
-import freemarker.template.TemplateNumberModel;
-import freemarker.template.TemplateScalarModel;
-import freemarker.template.TemplateSequenceModel;
-import freemarker.template.TemplateTransformModel;
-
-/**
- */
-class RmiDebugModelImpl extends UnicastRemoteObject implements DebugModel {
-    private static final long serialVersionUID = 1L;
-
-    private final TemplateModel model;
-    private final int type;
-    
-    RmiDebugModelImpl(TemplateModel model, int extraTypes) throws RemoteException {
-        super();
-        this.model = model;
-        type = calculateType(model) + extraTypes;
-    }
-
-    private static DebugModel getDebugModel(TemplateModel tm) throws RemoteException {
-        return (DebugModel) RmiDebuggedEnvironmentImpl.getCachedWrapperFor(tm);
-    }
-    @Override
-    public String getAsString() throws TemplateModelException {
-        return ((TemplateScalarModel) model).getAsString();
-    }
-
-    @Override
-    public Number getAsNumber() throws TemplateModelException {
-        return ((TemplateNumberModel) model).getAsNumber();
-    }
-
-    @Override
-    public Date getAsDate() throws TemplateModelException {
-        return ((TemplateDateModel) model).getAsDate();
-    }
-
-    @Override
-    public int getDateType() {
-        return ((TemplateDateModel) model).getDateType();
-    }
-
-    @Override
-    public boolean getAsBoolean() throws TemplateModelException {
-        return ((TemplateBooleanModel) model).getAsBoolean();
-    }
-
-    @Override
-    public int size() throws TemplateModelException {
-        if (model instanceof TemplateSequenceModel) {
-            return ((TemplateSequenceModel) model).size();
-        }
-        return ((TemplateHashModelEx) model).size();
-    }
-
-    @Override
-    public DebugModel get(int index) throws TemplateModelException, RemoteException {
-        return getDebugModel(((TemplateSequenceModel) model).get(index));
-    }
-    
-    @Override
-    public DebugModel[] get(int fromIndex, int toIndex) throws TemplateModelException, RemoteException {
-        DebugModel[] dm = new DebugModel[toIndex - fromIndex];
-        TemplateSequenceModel s = (TemplateSequenceModel) model;
-        for (int i = fromIndex; i < toIndex; i++) {
-            dm[i - fromIndex] = getDebugModel(s.get(i));
-        }
-        return dm;
-    }
-
-    @Override
-    public DebugModel[] getCollection() throws TemplateModelException, RemoteException {
-        List list = new ArrayList();
-        TemplateModelIterator i = ((TemplateCollectionModel) model).iterator();
-        while (i.hasNext()) {
-            list.add(getDebugModel(i.next()));
-        }
-        return (DebugModel[]) list.toArray(new DebugModel[list.size()]);
-    }
-    
-    @Override
-    public DebugModel get(String key) throws TemplateModelException, RemoteException {
-        return getDebugModel(((TemplateHashModel) model).get(key));
-    }
-    
-    @Override
-    public DebugModel[] get(String[] keys) throws TemplateModelException, RemoteException {
-        DebugModel[] dm = new DebugModel[keys.length];
-        TemplateHashModel h = (TemplateHashModel) model;
-        for (int i = 0; i < keys.length; i++) {
-            dm[i] = getDebugModel(h.get(keys[i]));
-        }
-        return dm;
-    }
-
-    @Override
-    public String[] keys() throws TemplateModelException {
-        TemplateHashModelEx h = (TemplateHashModelEx) model;
-        List list = new ArrayList();
-        TemplateModelIterator i = h.keys().iterator();
-        while (i.hasNext()) {
-            list.add(((TemplateScalarModel) i.next()).getAsString());
-        }
-        return (String[]) list.toArray(new String[list.size()]);
-    }
-
-    @Override
-    public int getModelTypes() {
-        return type;
-    }
-    
-    private static int calculateType(TemplateModel model) {
-        int type = 0;
-        if (model instanceof TemplateScalarModel) type += TYPE_SCALAR;
-        if (model instanceof TemplateNumberModel) type += TYPE_NUMBER;
-        if (model instanceof TemplateDateModel) type += TYPE_DATE;
-        if (model instanceof TemplateBooleanModel) type += TYPE_BOOLEAN;
-        if (model instanceof TemplateSequenceModel) type += TYPE_SEQUENCE;
-        if (model instanceof TemplateCollectionModel) type += TYPE_COLLECTION;
-        if (model instanceof TemplateHashModelEx) type += TYPE_HASH_EX;
-        else if (model instanceof TemplateHashModel) type += TYPE_HASH;
-        if (model instanceof TemplateMethodModelEx) type += TYPE_METHOD_EX;
-        else if (model instanceof TemplateMethodModel) type += TYPE_METHOD;
-        if (model instanceof TemplateTransformModel) type += TYPE_TRANSFORM;
-        return type;
-    }
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggedEnvironmentImpl.java b/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggedEnvironmentImpl.java
deleted file mode 100644
index 3bbb3e31..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggedEnvironmentImpl.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug.impl;
-
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import freemarker.cache.CacheStorage;
-import freemarker.cache.SoftCacheStorage;
-import freemarker.core.Configurable;
-import freemarker.core.Environment;
-import freemarker.debug.DebugModel;
-import freemarker.debug.DebuggedEnvironment;
-import freemarker.template.Configuration;
-import freemarker.template.SimpleCollection;
-import freemarker.template.SimpleScalar;
-import freemarker.template.Template;
-import freemarker.template.TemplateCollectionModel;
-import freemarker.template.TemplateHashModelEx;
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateModelException;
-import freemarker.template.utility.UndeclaredThrowableException;
-
-/**
- */
-class RmiDebuggedEnvironmentImpl
-extends
-    RmiDebugModelImpl
-implements
-    DebuggedEnvironment {
-    private static final long serialVersionUID = 1L;
-
-    private static final CacheStorage storage = new SoftCacheStorage(new IdentityHashMap());
-    private static final Object idLock = new Object();
-    private static long nextId = 1;
-    private static Set remotes = new HashSet();
-
-    
-    private boolean stopped = false;
-    private final long id;
-    
-    private RmiDebuggedEnvironmentImpl(Environment env) throws RemoteException {
-        super(new DebugEnvironmentModel(env), DebugModel.TYPE_ENVIRONMENT);
-        synchronized (idLock) {
-            id = nextId++;
-        }
-    }
-
-    static synchronized Object getCachedWrapperFor(Object key)
-    throws RemoteException {
-        Object value = storage.get(key);
-        if (value == null) {
-            if (key instanceof TemplateModel) {
-                int extraTypes;
-                if (key instanceof DebugConfigurationModel) {
-                    extraTypes = DebugModel.TYPE_CONFIGURATION;
-                } else if (key instanceof DebugTemplateModel) {
-                    extraTypes = DebugModel.TYPE_TEMPLATE;
-                } else {
-                    extraTypes = 0;
-                }
-                value = new RmiDebugModelImpl((TemplateModel) key, extraTypes);
-            } else if (key instanceof Environment) {
-                value = new RmiDebuggedEnvironmentImpl((Environment) key); 
-            } else if (key instanceof Template) {
-                value = new DebugTemplateModel((Template) key);
-            } else if (key instanceof Configuration) {
-                value = new DebugConfigurationModel((Configuration) key);
-            }
-        }
-        if (value != null) {
-            storage.put(key, value);
-        }
-        if (value instanceof Remote) {
-            remotes.add(value);
-        }
-        return value;
-    }
-
-    // TODO See in SuppressFBWarnings
-    @Override
-    @SuppressFBWarnings(value="NN_NAKED_NOTIFY", justification="Will have to be re-desigend; postponed.")
-    public void resume() {
-        synchronized (this) {
-            notify();
-        }
-    }
-
-    @Override
-    public void stop() {
-        stopped = true;
-        resume();
-    }
-
-    @Override
-    public long getId() {
-        return id;
-    }
-    
-    boolean isStopped() {
-        return stopped;
-    }
-    
-    private abstract static class DebugMapModel implements TemplateHashModelEx {
-        @Override
-        public int size() {
-            return keySet().size();
-        }
-
-        @Override
-        public TemplateCollectionModel keys() {
-            return new SimpleCollection(keySet());
-        }
-
-        @Override
-        public TemplateCollectionModel values() throws TemplateModelException {
-            Collection keys = keySet();
-            List list = new ArrayList(keys.size());
-            
-            for (Iterator it = keys.iterator(); it.hasNext(); ) {
-                list.add(get((String) it.next()));
-            }
-            return new SimpleCollection(list);
-        }
-
-        @Override
-        public boolean isEmpty() {
-            return size() == 0;
-        }
-        
-        abstract Collection keySet();
-
-        static List composeList(Collection c1, Collection c2) {
-            List list = new ArrayList(c1);
-            list.addAll(c2);
-            Collections.sort(list);
-            return list;
-        }
-    }
-    
-    private static class DebugConfigurableModel extends DebugMapModel {
-        static final List KEYS = Arrays.asList(new String[]
-        {
-            Configurable.ARITHMETIC_ENGINE_KEY,
-            Configurable.BOOLEAN_FORMAT_KEY,
-            Configurable.CLASSIC_COMPATIBLE_KEY,
-            Configurable.LOCALE_KEY,
-            Configurable.NUMBER_FORMAT_KEY,
-            Configurable.OBJECT_WRAPPER_KEY,
-            Configurable.TEMPLATE_EXCEPTION_HANDLER_KEY
-        });
-
-        final Configurable configurable;
-        
-        DebugConfigurableModel(Configurable configurable) {
-            this.configurable = configurable;
-        }
-        
-        @Override
-        Collection keySet() {
-            return KEYS;
-        }
-        
-        @Override
-        public TemplateModel get(String key) throws TemplateModelException {
-            String s = configurable.getSetting(key);
-            return s == null ? null : new SimpleScalar(s);
-        }
-
-    }
-    
-    private static class DebugConfigurationModel extends DebugConfigurableModel {
-        private static final List KEYS = composeList(DebugConfigurableModel.KEYS, Collections.singleton("sharedVariables"));
-
-        private TemplateModel sharedVariables = new DebugMapModel()
-        {
-            @Override
-            Collection keySet() {
-                return ((Configuration) configurable).getSharedVariableNames();
-            }
-        
-            @Override
-            public TemplateModel get(String key) {
-                return ((Configuration) configurable).getSharedVariable(key);
-            }
-        };
-        
-        DebugConfigurationModel(Configuration config) {
-            super(config);
-        }
-        
-        @Override
-        Collection keySet() {
-            return KEYS;
-        }
-
-        @Override
-        public TemplateModel get(String key) throws TemplateModelException {
-            if ("sharedVariables".equals(key)) {
-                return sharedVariables; 
-            } else {
-                return super.get(key);
-            }
-        }
-    }
-    
-    private static class DebugTemplateModel extends DebugConfigurableModel {
-        private static final List KEYS = composeList(DebugConfigurableModel.KEYS, 
-            Arrays.asList(new String[] {
-                "configuration", 
-                "name",
-                }));
-    
-        private final SimpleScalar name;
-
-        DebugTemplateModel(Template template) {
-            super(template);
-            this.name = new SimpleScalar(template.getName());
-        }
-
-        @Override
-        Collection keySet() {
-            return KEYS;
-        }
-
-        @Override
-        public TemplateModel get(String key) throws TemplateModelException {
-            if ("configuration".equals(key)) {
-                try {
-                    return (TemplateModel) getCachedWrapperFor(((Template) configurable).getConfiguration());
-                } catch (RemoteException e) {
-                    throw new TemplateModelException(e);
-                }
-            }
-            if ("name".equals(key)) {
-                return name;
-            }
-            return super.get(key);
-        }
-    }
-
-    private static class DebugEnvironmentModel extends DebugConfigurableModel {
-        private static final List KEYS = composeList(DebugConfigurableModel.KEYS, 
-            Arrays.asList(new String[] {
-                "currentNamespace",
-                "dataModel",
-                "globalNamespace",
-                "knownVariables",
-                "mainNamespace",
-                "template",
-                 }));
-    
-        private TemplateModel knownVariables = new DebugMapModel()
-        {
-            @Override
-            Collection keySet() {
-                try {
-                    return ((Environment) configurable).getKnownVariableNames();
-                } catch (TemplateModelException e) {
-                    throw new UndeclaredThrowableException(e);
-                }
-            }
-        
-            @Override
-            public TemplateModel get(String key) throws TemplateModelException {
-                return ((Environment) configurable).getVariable(key);
-            }
-        };
-         
-        DebugEnvironmentModel(Environment env) {
-            super(env);
-        }
-
-        @Override
-        Collection keySet() {
-            return KEYS;
-        }
-
-        @Override
-        public TemplateModel get(String key) throws TemplateModelException {
-            if ("currentNamespace".equals(key)) {
-                return ((Environment) configurable).getCurrentNamespace();
-            }
-            if ("dataModel".equals(key)) {
-                return ((Environment) configurable).getDataModel();
-            }
-            if ("globalNamespace".equals(key)) {
-                return ((Environment) configurable).getGlobalNamespace();
-            }
-            if ("knownVariables".equals(key)) {
-                return knownVariables;
-            }
-            if ("mainNamespace".equals(key)) {
-                return ((Environment) configurable).getMainNamespace();
-            }
-            if ("template".equals(key)) {
-                try {
-                    return (TemplateModel) getCachedWrapperFor(((Environment) configurable).getTemplate());
-                } catch (RemoteException e) {
-                    throw new TemplateModelException(e);
-                }
-            }
-            return super.get(key);
-        }
-    }
-
-    public static void cleanup() {
-        for (Iterator i = remotes.iterator(); i.hasNext(); ) {
-            Object remoteObject = i.next();
-            try {
-                UnicastRemoteObject.unexportObject((Remote) remoteObject, true);
-            } catch (Exception e) {
-            }
-        }
-    }
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggerImpl.java b/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggerImpl.java
deleted file mode 100644
index db14ada2..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggerImpl.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug.impl;
-
-import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
-import java.util.Collection;
-import java.util.List;
-
-import freemarker.debug.Breakpoint;
-import freemarker.debug.Debugger;
-import freemarker.debug.DebuggerListener;
-
-/**
- */
-class RmiDebuggerImpl
-extends
-    UnicastRemoteObject
-implements
-    Debugger {
-    private static final long serialVersionUID = 1L;
-
-    private final RmiDebuggerService service;
-    
-    protected RmiDebuggerImpl(RmiDebuggerService service) throws RemoteException {
-        this.service = service;
-    }
-
-    @Override
-    public void addBreakpoint(Breakpoint breakpoint) {
-        service.addBreakpoint(breakpoint);
-    }
-
-    @Override
-    public Object addDebuggerListener(DebuggerListener listener) {
-        return service.addDebuggerListener(listener);
-    }
-
-    @Override
-    public List getBreakpoints() {
-        return service.getBreakpointsSpi();
-    }
-
-    @Override
-    public List getBreakpoints(String templateName) {
-        return service.getBreakpointsSpi(templateName);
-    }
-
-    @Override
-    public Collection getSuspendedEnvironments() {
-        return service.getSuspendedEnvironments();
-    }
-
-    @Override
-    public void removeBreakpoint(Breakpoint breakpoint) {
-        service.removeBreakpoint(breakpoint);
-    }
-
-    @Override
-    public void removeDebuggerListener(Object id) {
-        service.removeDebuggerListener(id);
-    }
-
-    @Override
-    public void removeBreakpoints() {
-        service.removeBreakpoints();
-    }
-
-    @Override
-    public void removeBreakpoints(String templateName) {
-        service.removeBreakpoints(templateName);
-    }
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggerListenerImpl.java b/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggerListenerImpl.java
deleted file mode 100644
index a99a2a37..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggerListenerImpl.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug.impl;
-
-import java.rmi.NoSuchObjectException;
-import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
-import java.rmi.server.Unreferenced;
-
-import freemarker.debug.DebuggerClient;
-import freemarker.debug.DebuggerListener;
-import freemarker.debug.EnvironmentSuspendedEvent;
-import freemarker.log.Logger;
-
-/**
- * Used by the {@link DebuggerClient} to create local 
- */
-public class RmiDebuggerListenerImpl
-extends
-    UnicastRemoteObject
-implements
-    DebuggerListener, Unreferenced {
-    private static final Logger LOG = Logger.getLogger(
-            "freemarker.debug.client");
-    
-    private static final long serialVersionUID = 1L;
-
-    private final DebuggerListener listener;
-
-    @Override
-    public void unreferenced() {
-        try {
-            UnicastRemoteObject.unexportObject(this, false);
-        } catch (NoSuchObjectException e) {
-            LOG.warn("Failed to unexport RMI debugger listener", e);
-        }
-    }
-    
-    public RmiDebuggerListenerImpl(DebuggerListener listener) 
-    throws RemoteException {
-        this.listener = listener;
-    }
-
-    @Override
-    public void environmentSuspended(EnvironmentSuspendedEvent e)
-    throws RemoteException {
-        listener.environmentSuspended(e);
-    }
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggerService.java b/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggerService.java
deleted file mode 100644
index 72ca88f0..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/impl/RmiDebuggerService.java
+++ /dev/null
@@ -1,395 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug.impl;
-
-import java.io.Serializable;
-import java.lang.ref.ReferenceQueue;
-import java.lang.ref.WeakReference;
-import java.rmi.RemoteException;
-import java.rmi.server.RemoteObject;
-import java.rmi.server.UnicastRemoteObject;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import freemarker.core.DebugBreak;
-import freemarker.core.Environment;
-import freemarker.core.TemplateElement;
-import freemarker.core._CoreAPI;
-import freemarker.debug.Breakpoint;
-import freemarker.debug.DebuggerListener;
-import freemarker.debug.EnvironmentSuspendedEvent;
-import freemarker.template.Template;
-import freemarker.template.utility.UndeclaredThrowableException;
-
-/**
- * @version $Id
- */
-class RmiDebuggerService
-extends
-    DebuggerService {
-    private final Map templateDebugInfos = new HashMap();
-    private final HashSet suspendedEnvironments = new HashSet();
-    private final Map listeners = new HashMap();
-    private final ReferenceQueue refQueue = new ReferenceQueue();
-     
-
-    private final RmiDebuggerImpl debugger;
-    private DebuggerServer server;
-
-    RmiDebuggerService() {
-        try {
-            debugger = new RmiDebuggerImpl(this);
-            server = new DebuggerServer((Serializable) RemoteObject.toStub(debugger));
-            server.start();
-        } catch (RemoteException e) {
-            e.printStackTrace();
-            throw new UndeclaredThrowableException(e);
-        }
-    }
-    
-    @Override
-    List getBreakpointsSpi(String templateName) {
-        synchronized (templateDebugInfos) {
-            TemplateDebugInfo tdi = findTemplateDebugInfo(templateName);
-            return tdi == null ? Collections.EMPTY_LIST : tdi.breakpoints;
-        }
-    }
-
-    List getBreakpointsSpi() {
-        List sumlist = new ArrayList();
-        synchronized (templateDebugInfos) {
-            for (Iterator iter = templateDebugInfos.values().iterator(); iter.hasNext(); ) {
-                sumlist.addAll(((TemplateDebugInfo) iter.next()).breakpoints);
-            }
-        }
-        Collections.sort(sumlist);
-        return sumlist;
-    }
-
-    // TODO See in SuppressFBWarnings
-    @Override
-    @SuppressFBWarnings(value={ "UW_UNCOND_WAIT", "WA_NOT_IN_LOOP" }, justification="Will have to be re-desigend; postponed.")
-    boolean suspendEnvironmentSpi(Environment env, String templateName, int line)
-    throws RemoteException {
-        RmiDebuggedEnvironmentImpl denv = 
-            (RmiDebuggedEnvironmentImpl)
-                RmiDebuggedEnvironmentImpl.getCachedWrapperFor(env);
-                
-        synchronized (suspendedEnvironments) {
-            suspendedEnvironments.add(denv);
-        }
-        try {
-            EnvironmentSuspendedEvent breakpointEvent = 
-                new EnvironmentSuspendedEvent(this, templateName, line, denv);
-    
-            synchronized (listeners) {
-                for (Iterator iter = listeners.values().iterator(); iter.hasNext(); ) {
-                    DebuggerListener listener = (DebuggerListener) iter.next();
-                    listener.environmentSuspended(breakpointEvent);
-                }
-            }
-            synchronized (denv) {
-                try {
-                    denv.wait();
-                } catch (InterruptedException e) {
-                    ;// Intentionally ignored
-                }
-            }
-            return denv.isStopped();
-        } finally {
-            synchronized (suspendedEnvironments) {
-                suspendedEnvironments.remove(denv);
-            }
-        }
-    }
-    
-    @Override
-    void registerTemplateSpi(Template template) {
-        String templateName = template.getName();
-        synchronized (templateDebugInfos) {
-            TemplateDebugInfo tdi = createTemplateDebugInfo(templateName);
-            tdi.templates.add(new TemplateReference(templateName, template, refQueue));
-            // Inject already defined breakpoints into the template
-            for (Iterator iter = tdi.breakpoints.iterator(); iter.hasNext(); ) {
-                Breakpoint breakpoint = (Breakpoint) iter.next();
-                insertDebugBreak(template, breakpoint);
-            }
-        }
-    }
-    
-    Collection getSuspendedEnvironments() {
-        return (Collection) suspendedEnvironments.clone();
-    }
-
-    Object addDebuggerListener(DebuggerListener listener) {
-        Object id; 
-        synchronized (listeners) {
-            id = Long.valueOf(System.currentTimeMillis());
-            listeners.put(id, listener);
-        }
-        return id;
-    }
-    
-    void removeDebuggerListener(Object id) {
-        synchronized (listeners) {
-            listeners.remove(id);
-        }
-    }
-
-    void addBreakpoint(Breakpoint breakpoint) {
-        String templateName = breakpoint.getTemplateName();
-        synchronized (templateDebugInfos) {
-            TemplateDebugInfo tdi = createTemplateDebugInfo(templateName);
-            List breakpoints = tdi.breakpoints;
-            int pos = Collections.binarySearch(breakpoints, breakpoint);
-            if (pos < 0) {
-                // Add to the list of breakpoints
-                breakpoints.add(-pos - 1, breakpoint);
-                // Inject the breakpoint into all templates with this name
-                for (Iterator iter = tdi.templates.iterator(); iter.hasNext(); ) {
-                    TemplateReference ref = (TemplateReference) iter.next();
-                    Template t = ref.getTemplate();
-                    if (t == null) {
-                        iter.remove();
-                    } else {
-                        insertDebugBreak(t, breakpoint);
-                    }
-                }
-            }
-        }
-    }
-
-    private static void insertDebugBreak(Template t, Breakpoint breakpoint) {
-        TemplateElement te = findTemplateElement(t.getRootTreeNode(), breakpoint.getLine());
-        if (te == null) {
-            return;
-        }
-        TemplateElement parent = _CoreAPI.getParentElement(te);
-        DebugBreak db = new DebugBreak(te);
-        // TODO: Ensure there always is a parent by making sure
-        // that the root element in the template is always a MixedContent
-        // Also make sure it doesn't conflict with anyone's code.
-        parent.setChildAt(parent.getIndex(te), db);
-    }
-
-    private static TemplateElement findTemplateElement(TemplateElement te, int line) {
-        if (te.getBeginLine() > line || te.getEndLine() < line) {
-            return null;
-        }
-        // Find the narrowest match
-        List childMatches = new ArrayList();
-        for (Enumeration children = te.children(); children.hasMoreElements(); ) {
-            TemplateElement child = (TemplateElement) children.nextElement();
-            TemplateElement childmatch = findTemplateElement(child, line);
-            if (childmatch != null) {
-                childMatches.add(childmatch);
-            }
-        }
-        //find a match that exactly matches the begin/end line
-        TemplateElement bestMatch = null;
-        for (int i = 0; i < childMatches.size(); i++) {
-            TemplateElement e = (TemplateElement) childMatches.get(i);
-
-            if ( bestMatch == null ) {
-                bestMatch = e;
-            }
-
-            if ( e.getBeginLine() == line && e.getEndLine() > line ) {
-                bestMatch = e;
-            }
-
-            if ( e.getBeginLine() == e.getEndLine() && e.getBeginLine() == line) {
-                bestMatch = e;
-                break;
-            }
-        }
-        if ( bestMatch != null) {
-           return bestMatch;
-        }
-        // If no child provides narrower match, return this
-        return te;
-    }
-    
-    private TemplateDebugInfo findTemplateDebugInfo(String templateName) {
-        processRefQueue();
-        return (TemplateDebugInfo) templateDebugInfos.get(templateName); 
-    }
-    
-    private TemplateDebugInfo createTemplateDebugInfo(String templateName) {
-        TemplateDebugInfo tdi = findTemplateDebugInfo(templateName);
-        if (tdi == null) {
-            tdi = new TemplateDebugInfo();
-            templateDebugInfos.put(templateName, tdi);
-        }
-        return tdi;
-    }
-    
-    void removeBreakpoint(Breakpoint breakpoint) {
-        String templateName = breakpoint.getTemplateName();
-        synchronized (templateDebugInfos) {
-            TemplateDebugInfo tdi = findTemplateDebugInfo(templateName);
-            if (tdi != null) {
-                List breakpoints = tdi.breakpoints;
-                int pos = Collections.binarySearch(breakpoints, breakpoint);
-                if (pos >= 0) { 
-                    breakpoints.remove(pos);
-                    for (Iterator iter = tdi.templates.iterator(); iter.hasNext(); ) {
-                        TemplateReference ref = (TemplateReference) iter.next();
-                        Template t = ref.getTemplate();
-                        if (t == null) {
-                            iter.remove();
-                        } else {
-                            removeDebugBreak(t, breakpoint);
-                        }
-                    }
-                }
-                if (tdi.isEmpty()) {
-                    templateDebugInfos.remove(templateName);
-                }
-            }
-        }
-    }
-
-    private void removeDebugBreak(Template t, Breakpoint breakpoint) {
-        TemplateElement te = findTemplateElement(t.getRootTreeNode(), breakpoint.getLine());
-        if (te == null) {
-            return;
-        }
-        DebugBreak db = null;
-        while (te != null) {
-            if (te instanceof DebugBreak) {
-                db = (DebugBreak) te;
-                break;
-            }
-            te = _CoreAPI.getParentElement(te);
-        }
-        if (db == null) {
-            return;
-        }
-        TemplateElement parent = _CoreAPI.getParentElement(db); 
-        parent.setChildAt(parent.getIndex(db), _CoreAPI.getChildElement(db, 0));
-    }
-    
-    void removeBreakpoints(String templateName) {
-        synchronized (templateDebugInfos) {
-            TemplateDebugInfo tdi = findTemplateDebugInfo(templateName);
-            if (tdi != null) {
-                removeBreakpoints(tdi);
-                if (tdi.isEmpty()) {
-                    templateDebugInfos.remove(templateName);
-                }
-            }
-        }
-    }
-
-    void removeBreakpoints() {
-        synchronized (templateDebugInfos) {
-            for (Iterator iter = templateDebugInfos.values().iterator(); iter.hasNext(); ) {
-                TemplateDebugInfo tdi = (TemplateDebugInfo) iter.next(); 
-                removeBreakpoints(tdi);
-                if (tdi.isEmpty()) {
-                    iter.remove();
-                }
-            }
-        }
-    }
-
-    private void removeBreakpoints(TemplateDebugInfo tdi) {
-        tdi.breakpoints.clear();
-        for (Iterator iter = tdi.templates.iterator(); iter.hasNext(); ) {
-            TemplateReference ref = (TemplateReference) iter.next();
-            Template t = ref.getTemplate();
-            if (t == null) {
-                iter.remove();
-            } else {
-                removeDebugBreaks(t.getRootTreeNode());
-            }
-        }
-    }
-    
-    private void removeDebugBreaks(TemplateElement te) {
-        int count = te.getChildCount();
-        for (int i = 0; i < count; ++i) {
-            TemplateElement child = _CoreAPI.getChildElement(te, i);
-            while (child instanceof DebugBreak) {
-                TemplateElement dbchild = _CoreAPI.getChildElement(child, 0); 
-                te.setChildAt(i, dbchild);
-                child = dbchild;
-            }
-            removeDebugBreaks(child);
-        }
-    }
-    
-    private static final class TemplateDebugInfo {
-        final List templates = new ArrayList();
-        final List breakpoints = new ArrayList();
-        
-        boolean isEmpty() {
-            return templates.isEmpty() && breakpoints.isEmpty();
-        }
-    }
-    
-    private static final class TemplateReference extends WeakReference {
-        final String templateName;
-         
-        TemplateReference(String templateName, Template template, ReferenceQueue queue) {
-            super(template, queue);
-            this.templateName = templateName;
-        }
-        
-        Template getTemplate() {
-            return (Template) get();
-        }
-    }
-    
-    private void processRefQueue() {
-        for (; ; ) {
-            TemplateReference ref = (TemplateReference) refQueue.poll();
-            if (ref == null) {
-                break;
-            }
-            TemplateDebugInfo tdi = findTemplateDebugInfo(ref.templateName);
-            if (tdi != null) {
-                tdi.templates.remove(ref);
-                if (tdi.isEmpty()) {
-                    templateDebugInfos.remove(ref.templateName);
-                }
-            }
-        }
-    }
-
-    @Override
-    void shutdownSpi() {
-        server.stop();
-        try {
-            UnicastRemoteObject.unexportObject(this.debugger, true);
-        } catch (Exception e) {
-        }
-
-        RmiDebuggedEnvironmentImpl.cleanup();
-    }
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/impl/SuppressFBWarnings.java b/freemarker-core/src/main/java/freemarker/debug/impl/SuppressFBWarnings.java
deleted file mode 100644
index 3059b0c7..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/impl/SuppressFBWarnings.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.debug.impl;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-@Retention(RetentionPolicy.CLASS)
-@interface SuppressFBWarnings {
-    String[] value() default {};
-    String justification() default "";
-}
diff --git a/freemarker-core/src/main/java/freemarker/debug/package-info.java b/freemarker-core/src/main/java/freemarker/debug/package-info.java
deleted file mode 100644
index b4ccfe7e..00000000
--- a/freemarker-core/src/main/java/freemarker/debug/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * Debugging API; experimental status, might change!
- * This is to support debugging in IDE-s. If you are working on a client for this, don't hesitate to contact us!
- */
-package freemarker.debug;
\ No newline at end of file
diff --git a/freemarker-core/src/main/java/freemarker/template/Template.java b/freemarker-core/src/main/java/freemarker/template/Template.java
index 7d71b137..984b08cc 100644
--- a/freemarker-core/src/main/java/freemarker/template/Template.java
+++ b/freemarker-core/src/main/java/freemarker/template/Template.java
@@ -19,42 +19,14 @@
 
 package freemarker.template;
 
-import java.io.BufferedReader;
-import java.io.FilterReader;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Vector;
-
 import freemarker.cache.TemplateCache;
 import freemarker.cache.TemplateLoader;
 import freemarker.cache.TemplateLookupStrategy;
-import freemarker.core.BugException;
-import freemarker.core.Configurable;
-import freemarker.core.Environment;
-import freemarker.core.FMParser;
-import freemarker.core.LibraryLoad;
-import freemarker.core.Macro;
-import freemarker.core.OutputFormat;
-import freemarker.core.ParseException;
-import freemarker.core.ParserConfiguration;
-import freemarker.core.TemplateConfiguration;
-import freemarker.core.TemplateElement;
-import freemarker.core.TextBlock;
-import freemarker.core.TokenMgrError;
-import freemarker.core._CoreAPI;
-import freemarker.debug.impl.DebuggerService;
+import freemarker.core.*;
+
+import java.io.*;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.*;
 
 /**
  * Stores an already parsed template, ready to be processed (rendered) for unlimited times, possibly from multiple
@@ -275,7 +247,6 @@ public class Template extends Configurable {
         // Throws any exception that JavaCC has silently treated as EOF:
         ltbReader.throwFailure();
         
-        DebuggerService.registerTemplate(this);
         namespaceURIToPrefixLookup = Collections.unmodifiableMap(namespaceURIToPrefixLookup);
         prefixToNamespaceURILookup = Collections.unmodifiableMap(prefixToNamespaceURILookup);
     }
@@ -303,7 +274,6 @@ public class Template extends Configurable {
     Template(String name, TemplateElement root, Configuration cfg) {
         this(name, null, cfg, (ParserConfiguration) null);
         this.rootElement = root;
-        DebuggerService.registerTemplate(this);
     }
     
     /**
@@ -336,7 +306,6 @@ public class Template extends Configurable {
             throw new BugException("Plain text template creation failed", e);
         }
         _CoreAPI.replaceText((TextBlock) template.rootElement, content);
-        DebuggerService.registerTemplate(template);
         return template;
     }