< prev index next >

src/com/sun/javatest/TestSuite.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg

@@ -214,15 +214,12 @@
                 throw new NotTestSuiteFault(i18n, "ts.notTestSuiteFile", canonRoot);
         }
 
         File f = new File(canonRootDir, TESTSUITE_JTT);
         if (isReadableFile(f)) {
-            try {
-                Properties p = new Properties();
-                InputStream in = new BufferedInputStream(new FileInputStream(f));
-                p.load(in);
-                in.close();
+            try (InputStream in = new BufferedInputStream(new FileInputStream(f))) {
+                Map<String, String> p = com.sun.javatest.util.Properties.load(in);
                 return open(canonRoot, p);
             }
             catch (IOException e) {
                 throw new Fault(i18n, "ts.cantReadTestSuiteFile", e.toString());
             }

@@ -231,11 +228,11 @@
             // check for old style test suite
             File ts_html = new File(canonRootDir, TESTSUITE_HTML);
             File parentDir = canonRootDir.getParentFile();
             File parent_jtt = (parentDir == null ? null : new File(parentDir, TESTSUITE_JTT));
             if (isReadableFile(ts_html) && (parent_jtt == null || !parent_jtt.exists()))
-                return open(canonRoot, new HashMap());
+                return open(canonRoot, new HashMap<String, String>());
             else
                 throw new NotTestSuiteFault(i18n, "ts.notTestSuiteFile", canonRoot);
         }
     }
 

@@ -244,11 +241,11 @@
      * @param root A file identifying the root of the test suite.
      * @param tsInfo Test Suite properties read from the test suite properties file.
      * @return A TestSuite object for the test suite in question.
      * @throws TestSuite.Fault if any problems occur while opening the test suite
      */
-    private static TestSuite open(File root, Map tsInfo) throws Fault {
+    private static TestSuite open(File root, Map<String, String> tsInfo) throws Fault {
         synchronized (dirMap) {
             TestSuite ts;
 
             // if this test suite has already been opened, return that
             WeakReference<TestSuite> ref = dirMap.get(root);

@@ -266,12 +263,12 @@
             dirMap.put(root, new WeakReference<>(ts));
             return ts;
         }
     }
 
-    private static TestSuite open0(File root, Map tsInfo) throws Fault {
-        String[] classPath = StringArray.split((String) (tsInfo.get("classpath")));
+    private static TestSuite open0(File root, Map<String, String> tsInfo) throws Fault {
+        String[] classPath = StringArray.split(tsInfo.get("classpath"));
 
         ClassLoader cl;
         if (classPath.length == 0)
             cl = null;
         else {

@@ -295,21 +292,21 @@
                 throw new Fault(i18n, "ts.badClassPath",
                                 new Object[] {root, e.getMessage()});
             }
         }
 
-        String[] tsClassAndArgs = StringArray.split((String) (tsInfo.get("testsuite")));
+        String[] tsClassAndArgs = StringArray.split(tsInfo.get("testsuite"));
 
         TestSuite testSuite;
         if (tsClassAndArgs.length == 0)
             testSuite = new TestSuite(root, tsInfo, cl);
         else {
             String className = tsClassAndArgs[0];
 
             try {
-                Class c = loadClass(className, cl);
-                Class[] tsArgTypes = {File.class, Map.class, ClassLoader.class};
+                Class<?> c = loadClass(className, cl);
+                Class<?>[] tsArgTypes = {File.class, Map.class, ClassLoader.class};
                 Object[] tsArgs = {root, tsInfo, cl};
                 testSuite = (TestSuite)(newInstance(c, tsArgTypes, tsArgs));
             }
             catch (ClassCastException e) {
                 throw new Fault(i18n, "ts.notASubtype",

@@ -363,16 +360,16 @@
      * in the root directory of the test suite.
      * @param cl A class loader to be used to load additional classes as required,
      * typically using a class path defined in the test suite properties file.
      * @throws TestSuite.Fault if a problem occurs while creating this test suite.
      */
-    public TestSuite(File root, Map tsInfo, ClassLoader cl) throws Fault {
+    public TestSuite(File root, Map<String, String> tsInfo, ClassLoader cl) throws Fault {
         this.root = root;
         this.tsInfo = tsInfo;
         this.loader = cl;
 
-        String kw = (tsInfo == null ? null : (String) (tsInfo.get("keywords")));
+        String kw = (tsInfo == null ? null : tsInfo.get("keywords"));
         keywords = (kw == null ? null : StringArray.split(kw));
     }
 
 
     /**

@@ -438,11 +435,11 @@
      * <li>Otherwise, the result is the root directory of the test suite.
      * </ol>
      * @return the directory that contains the tests
      */
     public File getTestsDir() {
-        String t = (String) (tsInfo == null ? null : tsInfo.get("tests"));
+        String t = (tsInfo == null ? null : tsInfo.get("tests"));
         if (t == null || t.length() == 0) {
             File rootDir = getRootDir();
             File testsDir = new File(rootDir, "tests");
             if (testsDir.isDirectory()) {
                 // if the tests directory exists, and there is no overriding

@@ -549,11 +546,11 @@
      */
     protected TestFinder createTestFinder() throws Fault {
         File testsDir = getTestsDir();
 
         // no BTF file; look for a finder=class args... entry
-        String[] finderCmd = StringArray.split((String) (tsInfo.get("finder")));
+        String[] finderCmd = StringArray.split((tsInfo.get("finder")));
         String finderClassName;
         String[] finderArgs = new String[0];
 
         if (finderCmd == null || finderCmd.length == 0) {
             //finderCmd = new String[] {HTMLTestFinder.class.getName()};

@@ -571,11 +568,11 @@
                 // finderArgs should remain empty array
             }
         }
 
         // first, try looking for testsuite.jtd
-        String jtd = (String) (tsInfo.get("testsuite.jtd"));
+        String jtd = tsInfo.get("testsuite.jtd");
         File jtdFile = (jtd == null ? new File(testsDir, "testsuite.jtd") : new File(root, jtd));
         if (jtdFile.exists()) {
             try {
                 // found a file for BinaryTestFinder
                 // only pass the finder class if it was not defaulted to HTMLTestFinder

@@ -589,11 +586,11 @@
                 // ignore, try to continue with normal finder
             }
         }
 
         try {
-            Class c = loadClass(finderClassName);
+            Class<?> c = loadClass(finderClassName);
             TestFinder tf = (TestFinder) (newInstance(c));
             // called old deprecated entry till we know no-one cares
             //tf.init(finderArgs, testsRoot, null, null, tsInfo/*pass in env?*/);
             // this likely kills ExpandTestFinder, finally
             tf.init(finderArgs, testsDir, null, null, null/*pass in env?*/);

@@ -629,11 +626,11 @@
             String finderArgs[], File testsDir, File jtdFile) throws Fault, TestFinder.Fault {
         try {
             TestFinder tf = null;
 
             if (finderClassName != null) {
-                Class c = loadClass(finderClassName);
+                Class<?> c = loadClass(finderClassName);
                 tf = (TestFinder) (newInstance(c));
             }
 
             if (tf instanceof BinaryTestFinder) {
                 tf.init(finderArgs, testsDir, null, null, null);

@@ -695,11 +692,11 @@
                                WorkDirectory workDir,
                                BackupPolicy backupPolicy) throws Fault {
         if (scriptClass == null) {
             String[] script = envLookup(scriptEnv, "script");
             if (script.length == 0)
-                script = StringArray.split((String) tsInfo.get("script"));
+                script = StringArray.split(tsInfo.get("script"));
             if (script.length > 0) {
                 scriptClass = loadClass(script[0]);
                 if (!Script.class.isAssignableFrom(scriptClass)) {
                     throw new Fault(i18n, "ts.notASubtype",
                                     new Object[] {script[0], "script", Script.class.getName()});

@@ -709,12 +706,12 @@
             }
             else {
                 // for backwards compatibility,
                 // see if KeywordScript is a reasonable default
                 boolean keywordScriptOK = false;
-                for (Iterator i = scriptEnv.keys().iterator(); i.hasNext() && !keywordScriptOK; ) {
-                    String key = (String)(i.next());
+                for (Iterator<String> i = scriptEnv.keys().iterator(); i.hasNext() && !keywordScriptOK; ) {
+                    String key = i.next();
                     keywordScriptOK = key.startsWith("script.");
                 }
                 if (keywordScriptOK) {
                     scriptClass = KeywordScript.class;
                     scriptArgs = new String[] { };

@@ -756,11 +753,11 @@
      * @throws TestSuite.Fault if a problem occurs while creating the interview
      */
     public InterviewParameters createInterview()
         throws Fault
     {
-        String[] classNameAndArgs = StringArray.split((String) (tsInfo.get("interview")));
+        String[] classNameAndArgs = StringArray.split((tsInfo.get("interview")));
         if (classNameAndArgs == null || classNameAndArgs.length == 0) {
             try {
                 return new LegacyParameters(this);
             }
             catch (InterviewParameters.Fault e) {

@@ -773,11 +770,11 @@
         String className = classNameAndArgs[0];
         String[] args = new String[classNameAndArgs.length - 1];
         System.arraycopy(classNameAndArgs, 1, args, 0, args.length);
 
         try {
-            Class c = loadClass(className);
+            Class<?> c = loadClass(className);
             InterviewParameters p = (InterviewParameters) (newInstance(c));
             p.init(args);
             p.setTestSuite(this);
             return p;
         }

@@ -840,11 +837,11 @@
      * in the .jtt file.
      * @return a unique ID identifying the test suite, or null if not specified.
      * @see #getName
      */
     public String getID() {
-        return (tsInfo == null ? null : (String) (tsInfo.get("id")));
+        return (tsInfo == null ? null : tsInfo.get("id"));
     }
 
     /**
      * Get a string identifying this test suite, or null if not available.
      * The default is taken from the "name" entry in the .jtt file.

@@ -852,11 +849,11 @@
      * if appropriate.
      * @return a string identifying the test suite, or null if not specified.
      * @see #getID
      */
     public String getName() {
-        return (tsInfo == null ? null : (String) (tsInfo.get("name")));
+        return (tsInfo == null ? null : tsInfo.get("name"));
     }
 
     /**
      * Get the estimated number of tests in the test suite.
      * The default is to use the value of the "testCount" property from the

@@ -865,11 +862,11 @@
      * @return The estimated number of tests, or -1 if this number is not available.
      */
     public int getEstimatedTestCount() {
         try {
             if (tsInfo != null) {
-                String s = (String) (tsInfo.get("testCount"));
+                String s = tsInfo.get("testCount");
                 if (s != null)
                     return Integer.parseInt(s);
             }
         }
         catch (NumberFormatException e) {

@@ -884,11 +881,11 @@
      * testsuite.jtt file. If the value is a relative filename, it will be made absolute
      * by evaluating it relative to the test suite root directory.
      * @return the name of the default exclude list, or null if none specified.
      */
     public File getInitialExcludeList() {
-        String s = (tsInfo == null ? null : (String) (tsInfo.get("initial.jtx")));
+        String s = (tsInfo == null ? null : tsInfo.get("initial.jtx"));
         if (s == null)
             return null;
 
         File f = new File(s.replace('/', File.separatorChar));
         if (!f.isAbsolute())

@@ -915,11 +912,11 @@
      * identifying the latest exclude list for this test suite.
      * @return the name of the latest exclude list, or null if none specified.
      */
     public URL getLatestExcludeList() {
         try {
-            String s = (tsInfo == null ? null : (String) (tsInfo.get("latest.jtx")));
+            String s = (tsInfo == null ? null : tsInfo.get("latest.jtx"));
             return (s == null ? null : new URL(s));
         }
         catch (MalformedURLException e) {
             // ignore
             return null;

@@ -953,11 +950,11 @@
      * such documents.
      */
     public String[] getAdditionalDocNames() {
         return (tsInfo == null
                 ? null
-                : StringArray.split((String) (tsInfo.get("additionalDocs"))));
+                : StringArray.split((tsInfo.get("additionalDocs"))));
     }
 
     /**
      * Get the set of valid keywords for this test suite.
      * By default, the keywords will be looked up under the name "keywords"

@@ -1008,11 +1005,11 @@
      * Get A URL identifying a logo for this test suite, or null if none available.
      * @return a URL for a logo for the testsuite, or null if not available
      */
     public URL getLogo() {
         try {
-            String s = (tsInfo == null ? null : (String) (tsInfo.get("logo")));
+            String s = (tsInfo == null ? null : tsInfo.get("logo"));
             return (s == null ? null : new URL(getRootDir().toURL(), s));
         }
         catch (MalformedURLException e) {
             // ignore
             return null;

@@ -1035,11 +1032,11 @@
      * @param c the class to be instantiated
      * @return an instance of the specified class
      * @throws TestSuite.Fault if any errors arise while trying to instantiate
      * the class.
      */
-    protected static Object newInstance(Class c) throws Fault {
+    protected static Object newInstance(Class<?> c) throws Fault {
         try {
             return c.newInstance();
         }
         catch (InstantiationException e) {
             throw new Fault(i18n, "ts.cantInstantiate",

@@ -1061,11 +1058,11 @@
      * @param args the arguments to be passed to the constructor
      * @return an instance of the specified class
      * @throws TestSuite.Fault if any errors arise while trying to instantiate
      * the class.
      */
-    protected static Object newInstance(Class<?> c, Class[] argTypes, Object[] args)
+    protected static Object newInstance(Class<?> c, Class<?>[] argTypes, Object[] args)
         throws Fault
     {
         try {
             return c.getConstructor(argTypes).newInstance(args);
         }

@@ -1085,11 +1082,11 @@
                 throw new Fault(i18n, "ts.cantInit", new Object[] { c.getName(), te });
         }
         catch (NoSuchMethodException e) {
             // don't recurse past the use of a single arg constructor
             if (argTypes.length > 1 && Boolean.getBoolean(FIND_LEGACY_CONSTRUCTOR)) {
-                return newInstance(c, new Class[] {File.class}, new Object[] {args[0]});
+                return newInstance(c, new Class<?>[] {File.class}, new Object[] {args[0]});
             }
 
             throw new Fault(i18n, "ts.cantFindConstructor",
                             new Object[] { c.getName(), e });
         }

@@ -1099,11 +1096,11 @@
      * Load a class using the class loader provided when this test suite was created.
      * @param className the name of the class to be loaded
      * @return the class that was loaded
      * @throws TestSuite.Fault if there was a problem loading the specified class
      */
-    public Class loadClass(String className) throws Fault {
+    public Class<?> loadClass(String className) throws Fault {
         return loadClass(className, loader);
     }
 
     /**
      * Load a class using a specified loader, translating any errors that may arise

@@ -1111,11 +1108,11 @@
      * @param className the name of the class to be loaded
      * @param cl the class loader to use to load the specified class
      * @return the class that was loaded
      * @throws TestSuite.Fault if there was a problem loading the specified class
      */
-    protected static Class loadClass(String className, ClassLoader cl) throws Fault {
+    protected static Class<?> loadClass(String className, ClassLoader cl) throws Fault {
         try {
             if (cl == null)
                 return Class.forName(className);
             else
                 return cl.loadClass(className);

@@ -1167,11 +1164,11 @@
          * the extra check is performed: check if the newly introduced method
          * is abstract or not.
          */
         boolean isLegacy = false;
         try {
-            Method m = sr.getClass().getMethod("getServiceDescriptorFileName", new Class[0]);
+            Method m = sr.getClass().getMethod("getServiceDescriptorFileName", new Class<?>[0]);
             if (Modifier.isAbstract(m.getModifiers())) {
                 isLegacy = true;
             }
         } catch (NoSuchMethodException e) {
              isLegacy = true;

@@ -1191,15 +1188,15 @@
     public ServiceReader getServiceReader() {
         if (serviceReader != null) {
             return serviceReader;
         }
 
-        String servInfo = (String)tsInfo.get("serviceReader");
+        String servInfo = tsInfo.get("serviceReader");
         if (servInfo != null) {
             String[] args = servInfo.split(" ");
             try {
-                Class c = loadClass(args[0]);
+                Class<?> c = loadClass(args[0]);
                 serviceReader = (ServiceReader) (newInstance(c));
                 if (args.length > 1) {
                     // problem with java1.5, which has no Arrays.copyOfRange();
                     String[] copy = new String[args.length - 1];
                     for (int i = 1; i < args.length; i++) {

@@ -1225,11 +1222,11 @@
 
     /**
      * Get a map containing the test suite data in the .jtt file.
      * @return a map containing the test suite data in the .jtt file
      */
-    protected Map getTestSuiteInfo() {
+    protected Map<String, String> getTestSuiteInfo() {
         return tsInfo;
     }
 
     /**
      * Get an entry from the data in the .jtt file.

@@ -1238,11 +1235,11 @@
      */
     public String getTestSuiteInfo(String name) {
         if (tsInfo == null)
             return null;
         else
-            return (String) (tsInfo.get(name));
+            return (tsInfo.get(name));
     }
 
     /**
      * Get the requested behavior for dealing with conflicts between
      * which tests are in the test suite vs those in the work directory.

@@ -1481,16 +1478,16 @@
     private static final String TESTSUITE_HTML = "testsuite.html";
     private static final String TESTSUITE_JTT  = "testsuite.jtt";
     private static final String FIND_LEGACY_CONSTRUCTOR = "com.sun.javatest.ts.findLegacyCtor";
 
     private File root;
-    private Map tsInfo;
+    private Map<String, String> tsInfo;
     private ClassLoader loader;
     private TestFinder finder;
 
     // the following are used by the default impl of createScript
-    private Class scriptClass;
+    private Class<?> scriptClass;
     private String[] scriptArgs;
 
     private String[] keywords;
 
     private ServiceReader serviceReader;
< prev index next >