Revert "Fix to not mark a valid preloaded subtask as INVALID"

This reverts commit ba8f1423d2e7cc502a8af95bf87d365755d47c0f.

Reason for revert: Better approach at Ieff1da7a47b63514fb8d0437340e096e03ad54bd

Change-Id: I0b67bb426dd6422a6459601096aa66f2bd4253a0
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java b/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java
index 56cdd88..f5f0bd4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java
@@ -27,7 +27,6 @@
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
-import java.util.stream.Collectors;
 
 /** Task Configuration file living in git */
 public class TaskConfig extends AbstractVersionedMetaData {
@@ -64,7 +63,7 @@
     public String preloadTask;
     public Map<String, String> properties;
     public String readyHint;
-    public List<TaskKey> subTasks;
+    public List<String> subTasks;
     public List<String> subTasksExternals;
     public List<String> subTasksFactories;
     public List<String> subTasksFiles;
@@ -86,10 +85,7 @@
       preloadTask = getString(s, KEY_PRELOAD_TASK, null);
       properties = getProperties(s, KEY_PROPERTIES_PREFIX);
       readyHint = getString(s, KEY_READY_HINT, null);
-      subTasks =
-          getStringList(s, KEY_SUBTASK).stream()
-              .map(subtask -> TaskKey.create(s.file(), subtask))
-              .collect(Collectors.toList());
+      subTasks = getStringList(s, KEY_SUBTASK);
       subTasksExternals = getStringList(s, KEY_SUBTASKS_EXTERNAL);
       subTasksFactories = getStringList(s, KEY_SUBTASKS_FACTORY);
       subTasksFiles = getStringList(s, KEY_SUBTASKS_FILE);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/TaskKey.java b/src/main/java/com/googlesource/gerrit/plugins/task/TaskKey.java
index 6b8f486..bd0b683 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/TaskKey.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/TaskKey.java
@@ -52,10 +52,6 @@
     return subSection().file().branch();
   }
 
-  public FileKey file() {
-    return subSection().file();
-  }
-
   public abstract SubSectionKey subSection();
 
   public abstract String task();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java b/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java
index d5ab48e..44fcadc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java
@@ -365,11 +365,10 @@
       }
 
       protected void addSubTasks() throws IOException, StorageException {
-        for (TaskKey taskKey : task.subTasks) {
+        for (String expression : task.subTasks) {
           try {
             Optional<Task> def =
-                preloader.getOptionalTask(
-                    taskExpressionFactory.create(taskKey.file(), taskKey.task()));
+                preloader.getOptionalTask(taskExpressionFactory.create(task.file(), expression));
             if (def.isPresent()) {
               addPreloaded(def.get());
             }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/properties/AbstractExpander.java b/src/main/java/com/googlesource/gerrit/plugins/task/properties/AbstractExpander.java
index 1c9ef43..c970cec 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/properties/AbstractExpander.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/properties/AbstractExpander.java
@@ -14,9 +14,7 @@
 
 package com.googlesource.gerrit.plugins.task.properties;
 
-import com.googlesource.gerrit.plugins.task.TaskKey;
 import java.lang.reflect.Field;
-import java.lang.reflect.ParameterizedType;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -103,24 +101,11 @@
           field.set(cow.getForWrite(), expanded);
         }
       } else if (o instanceof List) {
-        ParameterizedType parameterizedType = (ParameterizedType) field.getGenericType();
-        Class<?> classType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
-        if (classType == String.class) {
-          @SuppressWarnings("unchecked")
-          List<String> forceCheck = List.class.cast(o);
-          List<String> expanded = expand(forceCheck);
-          if (expanded != o) {
-            field.set(cow.getForWrite(), expanded);
-          }
-        } else if (classType == TaskKey.class) {
-          @SuppressWarnings("unchecked")
-          List<TaskKey> forceCheck = List.class.cast(o);
-          List<TaskKey> expanded = expandTaskKey(forceCheck);
-          if (expanded != o) {
-            field.set(cow.getForWrite(), expanded);
-          }
-        } else {
-          throw new RuntimeException(String.format("Unknown list type: %s", classType));
+        @SuppressWarnings("unchecked")
+        List<String> forceCheck = List.class.cast(o);
+        List<String> expanded = expand(forceCheck);
+        if (expanded != o) {
+          field.set(cow.getForWrite(), expanded);
         }
       }
     } catch (IllegalAccessException e) {
@@ -133,29 +118,6 @@
    * Returns expanded unmodifiable List if property found. Returns same object if no expansions
    * occurred.
    */
-  public List<TaskKey> expandTaskKey(List<TaskKey> list) {
-    if (list != null) {
-      boolean hasProperty = false;
-      List<TaskKey> expandedList = new ArrayList<>(list.size());
-      for (TaskKey value : list) {
-        String expanded = expandText(value.task());
-        boolean hasExpanded = (value.task() != expanded);
-        hasProperty = hasProperty || hasExpanded;
-        if (hasExpanded) {
-          expandedList.add(TaskKey.create(value.file(), expanded));
-        } else {
-          expandedList.add(value);
-        }
-      }
-      return hasProperty ? Collections.unmodifiableList(expandedList) : list;
-    }
-    return null;
-  }
-
-  /**
-   * Returns expanded unmodifiable List if property found. Returns same object if no expansions
-   * occurred.
-   */
   public List<String> expand(List<String> list) {
     if (list != null) {
       boolean hasProperty = false;
diff --git a/src/main/resources/Documentation/test/task_states.md b/src/main/resources/Documentation/test/task_states.md
index e3f1834..199306f 100644
--- a/src/main/resources/Documentation/test/task_states.md
+++ b/src/main/resources/Documentation/test/task_states.md
@@ -2451,144 +2451,6 @@
    ]
 }
 
-[root "Root Preload from all-projects sub-dir"]
-  preload-task = //dir/common.config^Sample relative task in sub dir
-
-{
-   "applicable" : true,
-   "hasPass" : true,
-   "name" : "Root Preload from all-projects sub-dir",
-   "status" : "PASS"
-}
-
-[root "Root Preload from all-projects sub-dir which has subtask in same file"]
-  preload-task = //dir/common.config^Sample relative task in sub dir with subtask from same file
-
-{
-   "applicable" : true,
-   "hasPass" : true,
-   "name" : "Root Preload from all-projects sub-dir which has subtask in same file",
-   "status" : "PASS",
-   "subTasks" : [
-      {
-         "applicable" : true,
-         "hasPass" : true,
-         "name" : "Sample relative task in sub dir",
-         "status" : "PASS"
-      }
-   ]
-}
-
-[root "Root Preload from all-projects sub-dir which has subtask in different file"]
-  preload-task = //dir/common.config^Sample relative task in sub dir with subtask from different file
-
-{
-   "applicable" : true,
-   "hasPass" : true,
-   "name" : "Root Preload from all-projects sub-dir which has subtask in different file",
-   "status" : "PASS",
-   "subTasks" : [
-      {
-         "applicable" : true,
-         "hasPass" : true,
-         "name" : "Passing task",
-         "status" : "PASS"
-      }
-   ]
-}
-
-[root "Root Preload from user ref"]
-  preload-task = @testuser/dir/relative.config^Relative Task
-
-{
-   "applicable" : true,
-   "hasPass" : true,
-   "name" : "Root Preload from user ref",
-   "status" : "PASS"
-}
-
-[root "Root Preload from user ref which has subtask in same file"]
-  preload-task = @testuser/dir/relative.config^Relative Task with subtask
-
-{
-   "applicable" : true,
-   "hasPass" : true,
-   "name" : "Root Preload from user ref which has subtask in same file",
-   "status" : "PASS",
-   "subTasks" : [
-      {
-         "applicable" : true,
-         "hasPass" : true,
-         "name" : "Passing task",
-         "status" : "PASS"
-      }
-   ]
-}
-
-[root "Root Preload from user ref which has subtask in different file"]
-  preload-task = @testuser/dir/relative.config^Import All-Projects root task
-
-{
-   "applicable" : true,
-   "hasPass" : false,
-   "name" : "Root Preload from user ref which has subtask in different file",
-   "status" : "PASS",
-   "subTasks" : [
-      {
-         "applicable" : true,
-         "hasPass" : true,
-         "name" : "Subtask PASS",
-         "status" : "PASS"
-      }
-   ]
-}
-
-[root "Root Preload from group ref"]
-  preload-task = %{non_secret_group_name_without_space}^task in group root config file 1
-
-{
-   "applicable" : true,
-   "hasPass" : true,
-   "name" : "Root Preload from group ref",
-   "status" : "PASS"
-}
-
-[root "Root Preload from group ref which has subtask in same file"]
-  preload-task = %{non_secret_group_name_without_space}^task in group root with subtask
-
-{
-   "applicable" : true,
-   "hasPass" : true,
-   "name" : "Root Preload from group ref which has subtask in same file",
-   "status" : "PASS",
-   "subTasks" : [
-      {
-         "applicable" : true,
-         "hasPass" : true,
-         "name" : "Passing task",
-         "status" : "PASS"
-      }
-   ]
-}
-
-[root "Root Preload from group ref which has subtask in different file"]
-  preload-task = %{non_secret_group_name_without_space}^task in group root with subtask from all-projects
-
-{
-   "applicable" : true,
-   "hasPass" : true,
-   "name" : "Root Preload from group ref which has subtask in different file",
-   "status" : "PASS",
-   "subTasks" : [
-      {
-         "applicable" : true,
-         "hasPass" : true,
-         "name" : "Subtask PASS",
-         "status" : "PASS"
-      }
-   ]
-}
-
 [root "Root Preload from all-projects sub-dir which has preload-task in same file"]
   preload-task = //dir/common.config^Sample task in sub dir with preload-task from same file
 
@@ -2596,15 +2458,7 @@
    "applicable" : true,
    "hasPass" : true,
    "name" : "Root Preload from all-projects sub-dir which has preload-task in same file",
-   "status" : "PASS",
-   "subTasks" : [
-      {
-         "applicable" : true,
-         "hasPass" : true,
-         "name" : "Sample relative task in sub dir",
-         "status" : "PASS"
-      }
-   ]
+   "status" : "PASS"
 }
 
 [root "Root Preload from all-projects sub-dir which has preload-task in different file"]
@@ -3211,10 +3065,6 @@
 ```
 [task "Root Import task from subdir using relative syntax"]
     subtask = dir/common.config^Sample relative task in sub dir
-
-[task "Passing task"]
-    applicable = is:open
-    pass = True
 ```
 
 file: `All-Projects:refs/meta/config:task/dir/common.config`
@@ -3223,22 +3073,12 @@
     applicable = is:open
     pass = is:open
 
-[task "Sample relative task in sub dir with subtask from same file"]
-    applicable = is:open
-    pass = is:open
-    subtask = Sample relative task in sub dir
-
-[task "Sample relative task in sub dir with subtask from different file"]
-    applicable = is:open
-    pass = is:open
-    subtask = //relative.config^Passing task
-
 [task "Root Import task from root task.config"]
     applicable = is:open
     subtask = ^Subtask PASS
 
 [task "Sample task in sub dir with preload-task from same file"]
-    preload-task = Sample relative task in sub dir with subtask from same file
+    preload-task = Sample relative task in sub dir
 
 [task "Sample task in sub dir with preload-task from different file"]
     preload-task = %{non_secret_group_name_without_space}/foo/bar.config^Absolute Task 1
@@ -3454,15 +3294,6 @@
   applicable = is:open
   pass = is:open
 
-[task "Relative Task with subtask"]
-  applicable = is:open
-  pass = is:open
-  subtask = Passing task
-
-[task "Passing task"]
-  applicable = is:open
-  pass = True
-
 [task "Import All-Projects root task"]
   applicable = is:open
   subtask = //^Subtask PASS
@@ -3514,20 +3345,6 @@
   applicable = is:open
   pass = is:open
 
-[task "task in group root with subtask"]
-  applicable = is:open
-  pass = is:open
-  subtask = Passing task
-
-[task "Passing task"]
-  applicable = is:open
-  pass = True
-
-[task "task in group root with subtask from all-projects"]
-  applicable = is:open
-  pass = is:open
-  subtask = //^Subtask PASS
-
 [task "task in group root config file 2"]
   applicable = is:open
   pass = is:open