gt:         for (String onearg : args) {
context: /*
   * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
   *
   * This code is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   * version 2 for more details (a copy is included in the LICENSE file that
   * accompanied this code).
   *
   * You should have received a copy of the GNU General Public License version
   * 2 along with this work; if not, write to the Free Software Foundation,
   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   *
   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
  /*
   * @test
   * @bug 4981566 5028634 5094412 6304984 7025786 7025789 8001112 8028545 8000961 8030610
   * @summary Check interpretation of -target and -source options
   * @run main Versions
   */
  
  import java.io.*;
  import java.nio.*;
  import java.nio.channels.*;
  
  import javax.tools.JavaCompiler;
  import javax.tools.ToolProvider;
  import javax.tools.JavaFileObject;
  import javax.tools.StandardJavaFileManager;
  import java.util.List;
  import java.util.ArrayList;
  import java.util.Arrays;
  
  
  public class Versions {
  
      protected JavaCompiler javacompiler;
      protected int failedCases;
  
      public Versions() throws IOException {
          javacompiler = ToolProvider.getSystemJavaCompiler();
          genSourceFiles();
          failedCases = 0;
      }
  
      public static void main(String... args) throws IOException {
          Versions versions = new Versions();
          versions.run();
      }
  
      void run() {
  
          String jdk9cv = "52.0";  // class version.change when ./dev pushed to 53
  
          String TC = "";
          System.out.println("Version.java: Starting");
  
          check("52.0");
          check("52.0", "-source 1.6");
          check("52.0", "-source 1.7");
          check("52.0", "-source 1.8");
          check(jdk9cv, "-source 1.9");
  
          check_source_target("50.0", "6", "6");
          check_source_target("51.0", "6", "7");
          check_source_target("51.0", "7", "7");
          check_source_target("52.0", "6", "8");
          check_source_target("52.0", "7", "8");
          check_source_target("52.0", "8", "8");
          check_source_target(jdk9cv, "6", "9");
          check_source_target(jdk9cv, "7", "9");
          check_source_target(jdk9cv, "8", "9");
          check_source_target(jdk9cv, "9", "9");
  
          checksrc16("-source 1.6");
          checksrc16("-source 6");
          checksrc16("-source 1.6", "-target 1.6");
          checksrc16("-source 6", "-target 6");
          checksrc17("-source 1.7");
          checksrc17("-source 7");
          checksrc17("-source 1.7", "-target 1.7");
          checksrc17("-source 7", "-target 7");
          checksrc18("-source 1.8");
          checksrc18("-source 8");
          checksrc18("-source 1.8", "-target 1.8");
          checksrc18("-source 8", "-target 8");
          checksrc19();
          checksrc19("-source 1.9");
          checksrc19("-source 9");
          checksrc19("-source 1.9", "-target 1.9");
          checksrc19("-source 9", "-target 9");
          checksrc19("-target 1.9");
          checksrc19("-target 9");
  
          fail("-source 7", "-target 1.6", "Base.java");
          fail("-source 8", "-target 1.6", "Base.java");
          fail("-source 8", "-target 1.7", "Base.java");
          fail("-source 9", "-target 1.7", "Base.java");
          fail("-source 9", "-target 1.8", "Base.java");
  
          fail("-source 1.5", "-target 1.5", "Base.java");
          fail("-source 1.4", "-target 1.4", "Base.java");
          fail("-source 1.3", "-target 1.3", "Base.java");
          fail("-source 1.2", "-target 1.2", "Base.java");
  
          if (failedCases > 0) {
              System.err.println("failedCases = " + String.valueOf(failedCases));
              throw new Error("Test failed");
          }
  
      }
  
      protected void printargs(String fname,String... args) {
          System.out.printf("test: %s", fname);
          for (String onearg : args) {
              System.out.printf(" %s", onearg);
          }
          System.out.printf("\n", fname);
      }
  
      protected void check_source_target(String... args) {
          printargs("check_source_target", args);
          check_target(args[0], args[1], args[2]);
          check_target(args[0], "1." + args[1], args[2]);
      }
  
      protected void check_target(String... args) {
          check(args[0], "-source " + args[1], "-target " + args[2]);
          check(args[0], "-source " + args[1], "-target 1." + args[2]);
      }
  
      protected void check(String major, String... args) {
          printargs("check", args);
          List<String> jcargs = new ArrayList<String>();
          jcargs.add("-Xlint:-options");
  
          // add in args conforming to List requrements of JavaCompiler
          for (String onearg : args) {
              String[] fields = onearg.split(" ");
              for (String onefield : fields) {
                  jcargs.add(onefield);
              }
          }
  
          boolean creturn = compile("Base.java", jcargs);
          if (!creturn) {
              // compilation errors note and return.. assume no class file
              System.err.println("check: Compilation Failed");
              System.err.println("\t classVersion:\t" + major);
              System.err.println("\t arguments:\t" + jcargs);
              failedCases++;
  
          } else if (!checkClassFileVersion("Base.class", major)) {
              failedCases++;
          }
      }
  
      protected void checksrc16(String... args) {
          printargs("checksrc16", args);
          int asize = args.length;
          String[] newargs = new String[asize + 1];
          System.arraycopy(args, 0, newargs, 0, asize);
          newargs[asize] = "Base.java";
          pass(newargs);
          newargs[asize] = "New17.java";
          fail(newargs);
      }
  
      protected void checksrc17(String... args) {
          printargs("checksrc17", args);
          int asize = args.length;
          String[] newargs = new String[asize+1];
          System.arraycopy(args, 0, newargs,0 , asize);
          newargs[asize] = "New17.java";
          pass(newargs);
          newargs[asize] = "New18.java";
          fail(newargs);
      }
  
      protected void checksrc18(String... args) {
          printargs("checksrc18", args);
          int asize = args.length;
          String[] newargs = new String[asize+1];
          System.arraycopy(args, 0, newargs,0 , asize);
          newargs[asize] = "New17.java";
          pass(newargs);
          newargs[asize] = "New18.java";
          pass(newargs);
      }
  
      protected void checksrc19(String... args) {
          printargs("checksrc19", args);
          checksrc18(args);
      }
  
      protected void pass(String... args) {
          printargs("pass", args);
  
          List<String> jcargs = new ArrayList<String>();
          jcargs.add("-Xlint:-options");
  
          // add in args conforming to List requrements of JavaCompiler
          for (String onearg : args) {
              String[] fields = onearg.split(" ");
              for (String onefield : fields) {
                  jcargs.add(onefield);
              }
          }
  
          // empty list is error
          if (jcargs.isEmpty()) {
              System.err.println("error: test error in pass() - No arguments");
              System.err.println("\t arguments:\t" + jcargs);
              failedCases++;
              return;
          }
  
          // the last argument is the filename *.java
          String filename = jcargs.get(jcargs.size() - 1);
          jcargs.remove(jcargs.size() - 1);
  
          boolean creturn = compile(filename, jcargs);
          // expect a compilation failure, failure if otherwise
          if (!creturn) {
              System.err.println("pass: Compilation erroneously failed");
              System.err.println("\t arguments:\t" + jcargs);
              System.err.println("\t file     :\t" + filename);
              failedCases++;
  
          }
  
      }
  
      protected void fail(String... args) {
          printargs("fail", args);
  
          List<String> jcargs = new ArrayList<String>();
          jcargs.add("-Xlint:-options");
  
          // add in args conforming to List requrements of JavaCompiler
  