Index: /trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 4724)
+++ /trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 4725)
@@ -819,11 +819,18 @@
      * <code>Way wnew = new Way(existingWay)</code>
      *
+     * @param allowWithoutDataset If true, method will return empty list if primitive is not part of the dataset. If false,
+     * exception will be thrown in this case
+     *
      * @return a collection of all primitives that reference this primitive.
      */
 
-    public final List<OsmPrimitive> getReferrers() {
+    public final List<OsmPrimitive> getReferrers(boolean allowWithoutDataset) {
         // Method copied from OsmPrimitive in josm-ng
         // Returns only referrers that are members of the same dataset (primitive can have some fake references, for example
         // when way is cloned
+
+        if (dataSet == null && allowWithoutDataset)
+            return Collections.emptyList();
+
         checkDataset();
         Object referrers = this.referrers;
@@ -846,4 +853,8 @@
     }
 
+    public final List<OsmPrimitive> getReferrers() {
+        return getReferrers(false);
+    }
+
     /**
      * <p>Visits {@code visitor} for all referrers.</p>
@@ -966,5 +977,5 @@
         if (!isNew() &&  id != other.id)
             return false;
-//        if (isIncomplete() && ! other.isIncomplete() || !isIncomplete()  && other.isIncomplete())
+        //        if (isIncomplete() && ! other.isIncomplete() || !isIncomplete()  && other.isIncomplete())
         if (isIncomplete() ^ other.isIncomplete()) // exclusive or operator for performance (see #7159)
             return false;
Index: /trunk/src/org/openstreetmap/josm/tools/template_engine/ContextSwitchTemplate.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/tools/template_engine/ContextSwitchTemplate.java	(revision 4724)
+++ /trunk/src/org/openstreetmap/josm/tools/template_engine/ContextSwitchTemplate.java	(revision 4725)
@@ -68,5 +68,5 @@
             List<OsmPrimitive> result = new ArrayList<OsmPrimitive>();
             for (OsmPrimitive child: children) {
-                for (OsmPrimitive parent: child.getReferrers()) {
+                for (OsmPrimitive parent: child.getReferrers(true)) {
                     if (condition == null || condition.match(parent)) {
                         result.add(parent);
