Bug 520335 - [9] ClassCastException in compiler when passed an endorsed
directory

Generify Main.java

Change-Id: I2b31e81b019cd720efddbf700994888081707ee5
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java
index fa0fc71..903b9a4 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java
@@ -406,12 +406,12 @@
 	}
 
 	@Override
-	protected void setPaths(ArrayList bootclasspaths,
+	protected void setPaths(ArrayList<String> bootclasspaths,
 			String sourcepathClasspathArg,
-			ArrayList sourcepathClasspaths,
-			ArrayList classpaths,
-			ArrayList extdirsClasspaths,
-			ArrayList endorsedDirClasspaths,
+			ArrayList<String> sourcepathClasspaths,
+			ArrayList<String> classpaths,
+			ArrayList<String> extdirsClasspaths,
+			ArrayList<String> endorsedDirClasspaths,
 			String customEncoding) {
 
 		ArrayList<FileSystem.Classpath> fileSystemClasspaths = new ArrayList<>();
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractBatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractBatchCompilerTest.java
index 6a3314b..b741ab0 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractBatchCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractBatchCompilerTest.java
@@ -24,6 +24,7 @@
 import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
 import org.eclipse.jdt.core.tests.util.Util;
 import org.eclipse.jdt.internal.compiler.batch.ClasspathLocation;
+import org.eclipse.jdt.internal.compiler.batch.FileSystem;
 import org.eclipse.jdt.internal.compiler.batch.Main;
 
 public abstract class AbstractBatchCompilerTest extends AbstractRegressionTest {
@@ -803,7 +804,7 @@
 		if (!outputDirectory.isDirectory()) {
 			outputDirectory.mkdirs();
 		}
-		ArrayList<ClasspathLocation> paths = new ArrayList<>(Main.DEFAULT_SIZE_CLASSPATH);
+		ArrayList<FileSystem.Classpath> paths = new ArrayList<>(Main.DEFAULT_SIZE_CLASSPATH);
 		try {
 			(new Main(new PrintWriter(System.out), new PrintWriter(System.err), true/*systemExit*/, null/*options*/, null/*progress*/)).
 				processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, classpathInput, null /* customEncoding */, true /* isSourceOnly */, false /* rejectDestinationPathOnJars*/);
@@ -822,7 +823,7 @@
 			assertEquals("unexpected classpaths entries number: ",
 					expectedClasspathEntries == null ? 0 : expectedClasspathEntries.length / 3, l);
 			for (int i = 0, j = 0; i < l ; i++) {
-				ClasspathLocation result = paths.get(i);
+				ClasspathLocation result = (ClasspathLocation) paths.get(i);
 				String expected = expectedClasspathEntries[j++];
 				String actual = result.toString();
 				if (! actual.equals("ClasspathDirectory " + expected + File.separator) &&
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java
index ea7baa5..1aeaa68 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java
@@ -25,6 +25,7 @@
 import java.util.zip.ZipFile;
 
 import org.eclipse.jdt.core.compiler.CharOperation;
+import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
 import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
 import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationDecorator;
@@ -54,13 +55,13 @@
 	this.closeZipFileAtEnd = closeZipFileAtEnd;
 }
 
-public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) {
+public List<Classpath> fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) {
 	// expected to be called once only - if multiple calls desired, consider
 	// using a cache
 	InputStream inputStream = null;
 	try {
 		initialize();
-		ArrayList result = new ArrayList();
+		ArrayList<Classpath> result = new ArrayList<>();
 		ZipEntry manifest = this.zipFile.getEntry("META-INF/MANIFEST.MF"); //$NON-NLS-1$
 		if (manifest != null) { // non-null implies regular file
 			inputStream = this.zipFile.getInputStream(manifest);
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java
index 64d3d89..fe7bf63 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java
index 9d24e70..e917dd0 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java
@@ -50,7 +50,7 @@
 		 * @return a list of the jar file names defined in the Class-Path
 		 *         section of the jar file manifest if any
 		 */
-		List fetchLinkedJars(ClasspathSectionProblemReporter problemReporter);
+		List<Classpath> fetchLinkedJars(ClasspathSectionProblemReporter problemReporter);
 		/**
 		 * This method resets the environment. The resulting state is equivalent to
 		 * a new name environment without creating a new object.
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
index 5e3f50a..d372aa2 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
@@ -56,6 +56,7 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.MissingResourceException;
 import java.util.Properties;
 import java.util.ResourceBundle;
@@ -94,7 +95,6 @@
 import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
 import org.eclipse.jdt.internal.compiler.util.Util;
 
-@SuppressWarnings({ "rawtypes", "unchecked" })
 public class Main implements ProblemSeverities, SuffixConstants {
 
 	public static class Logger {
@@ -102,7 +102,7 @@
 		private PrintWriter log;
 		private Main main;
 		private PrintWriter out;
-		private HashMap parameters;
+		private HashMap<String, Object> parameters;
 		int tagBits;
 		private static final String CLASS = "class"; //$NON-NLS-1$
 		private static final String CLASS_FILE = "classfile"; //$NON-NLS-1$
@@ -174,7 +174,7 @@
 		private static final String XML_DTD_DECLARATION = "<!DOCTYPE compiler PUBLIC \"-//Eclipse.org//DTD Eclipse JDT 3.2.005 Compiler//EN\" \"http://www.eclipse.org/jdt/core/compiler_32_005.dtd\">"; //$NON-NLS-1$
 		static {
 			try {
-				Class c = IProblem.class;
+				Class<?> c = IProblem.class;
 				Field[] fields = c.getFields();
 				for (int i = 0, max = fields.length; i < max; i++) {
 					Field field = fields[i];
@@ -198,7 +198,7 @@
 		public Logger(Main main, PrintWriter out, PrintWriter err) {
 			this.out = out;
 			this.err = err;
-			this.parameters = new HashMap();
+			this.parameters = new HashMap<>();
 			this.main = main;
 		}
 
@@ -631,7 +631,7 @@
 		}
 
 		public void loggingExtraProblems(Main currentMain) {
-			ArrayList problems = currentMain.extraProblems;
+			ArrayList<CategorizedProblem> problems = currentMain.extraProblems;
 			final int count = problems.size();
 			int localProblemCount = 0;
 			if (count != 0) {
@@ -639,7 +639,7 @@
 				int warnings = 0;
 				int infos = 0;
 				for (int i = 0; i < count; i++) {
-					CategorizedProblem problem = (CategorizedProblem) problems.get(i);
+					CategorizedProblem problem = problems.get(i);
 					if (problem != null) {
 						currentMain.globalProblemsCount++;
 						logExtraProblem(problem, localProblemCount, currentMain.globalProblemsCount);
@@ -660,7 +660,7 @@
 					if ((errors + warnings + infos) != 0) {
 						startLoggingExtraProblems(count);
 						for (int i = 0; i < count; i++) {
-							CategorizedProblem problem = (CategorizedProblem) problems.get(i);
+							CategorizedProblem problem = problems.get(i);
 							if (problem!= null) {
 								if (problem.getID() != IProblem.Task) {
 									logXmlExtraProblem(problem, localProblemCount, currentMain.globalProblemsCount);
@@ -1206,7 +1206,7 @@
 			}
 		}
 
-		private void printTag(String name, HashMap params, boolean insertNewLine, boolean closeTag) {
+		private void printTag(String name, HashMap<String, Object> params, boolean insertNewLine, boolean closeTag) {
 			if (this.log != null) {
 				((GenericXMLWriter) this.log).printTag(name, this.parameters, true, insertNewLine, closeTag);
 			}
@@ -1313,9 +1313,9 @@
 	 * Resource bundle factory to share bundles for the same locale
 	 */
 	public static class ResourceBundleFactory {
-		private static HashMap Cache = new HashMap();
+		private static HashMap<Locale, ResourceBundle> Cache = new HashMap<>();
 		public static synchronized ResourceBundle getBundle(Locale locale) {
-			ResourceBundle bundle = (ResourceBundle) Cache.get(locale);
+			ResourceBundle bundle = Cache.get(locale);
 			if (bundle == null) {
 				bundle = ResourceBundle.getBundle(Main.bundleName, locale);
 				Cache.put(locale, bundle);
@@ -1386,7 +1386,7 @@
 	public int currentRepetition, maxRepetition;
 	public boolean showProgress = false;
 	public long startTime;
-	public ArrayList pendingErrors;
+	public ArrayList<String> pendingErrors;
 	public boolean systemExitWhenFinished = true;
 
 	public static final int TIMING_DISABLED = 0;
@@ -1400,7 +1400,7 @@
 
 	private PrintWriter err;
 
-	protected ArrayList extraProblems;
+	protected ArrayList<CategorizedProblem> extraProblems;
 	public final static String bundleName = "org.eclipse.jdt.internal.compiler.batch.messages"; //$NON-NLS-1$
 	// two uses: recognize 'none' in options; code the singleton none
 	// for the '-d none' option (wherever it may be found)
@@ -1517,7 +1517,7 @@
  * @deprecated - use {@link #Main(PrintWriter, PrintWriter, boolean, Map, CompilationProgress)} instead
  *                       e.g. Main(outWriter, errWriter, systemExitWhenFinished, customDefaultOptions, null)
  */
-public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished, Map customDefaultOptions) {
+public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished, Map<String, String> customDefaultOptions) {
 	this(outWriter, errWriter, systemExitWhenFinished, customDefaultOptions, null /* progress */);
 }
 
@@ -1528,12 +1528,12 @@
 
 public void addExtraProblems(CategorizedProblem problem) {
 	if (this.extraProblems == null) {
-		this.extraProblems = new ArrayList();
+		this.extraProblems = new ArrayList<>();
 	}
 	this.extraProblems.add(problem);
 }
 protected void addNewEntry(ArrayList<FileSystem.Classpath> paths, String currentClasspathName,
-		ArrayList currentRuleSpecs, String customEncoding,
+		ArrayList<String> currentRuleSpecs, String customEncoding,
 		String destPath, boolean isSourceOnly,
 		boolean rejectDestinationPathOnJars) {
 
@@ -1542,10 +1542,10 @@
 	if (rulesSpecsSize != 0) {
 		AccessRule[] accessRules = new AccessRule[currentRuleSpecs.size()];
 		boolean rulesOK = true;
-		Iterator i = currentRuleSpecs.iterator();
+		Iterator<String> i = currentRuleSpecs.iterator();
 		int j = 0;
 		while (i.hasNext()) {
-			String ruleSpec = (String) i.next();
+			String ruleSpec = i.next();
 			char key = ruleSpec.charAt(0);
 			String pattern = ruleSpec.substring(1);
 			if (pattern.length() > 0) {
@@ -1610,7 +1610,7 @@
 }
 void addPendingErrors(String message) {
 	if (this.pendingErrors == null) {
-		this.pendingErrors = new ArrayList();
+		this.pendingErrors = new ArrayList<>();
 	}
 	this.pendingErrors.add(message);
 }
@@ -1757,7 +1757,7 @@
 			System.exit(-1);
 		}
 		return false;
-	} catch (RuntimeException e) { // internal compiler failure
+	} catch (Exception e) { // internal compiler failure
 		this.logger.logException(e);
 		if (this.systemExitWhenFinished) {
 			this.logger.flush();
@@ -1807,12 +1807,12 @@
 	final int INSIDE_ANNOTATIONPATH_start = 22;
 
 	final int DEFAULT = 0;
-	ArrayList bootclasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
+	ArrayList<String> bootclasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
 	String sourcepathClasspathArg = null;
-	ArrayList sourcepathClasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
-	ArrayList classpaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
-	ArrayList extdirsClasspaths = null;
-	ArrayList endorsedDirClasspaths = null;
+	ArrayList<String> sourcepathClasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
+	ArrayList<String> classpaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
+	ArrayList<String> extdirsClasspaths = null;
+	ArrayList<String> endorsedDirClasspaths = null;
 	this.annotationPaths = null;
 	this.annotationsFromClasspath = false;
 
@@ -1835,7 +1835,7 @@
 	String currentSourceDirectory = null;
 	String currentArg = Util.EMPTY_STRING;
 	
-	Set specifiedEncodings = null;
+	Set<String> specifiedEncodings = null;
 
 	// expand the command line if necessary
 	boolean needExpansion = false;
@@ -2658,7 +2658,7 @@
 						}
 					}
 				} else {
-					specifiedEncodings = new HashSet();
+					specifiedEncodings = new HashSet<>();
 				}
 				try { // ensure encoding is supported
 					new InputStreamReader(new ByteArrayInputStream(new byte[0]), currentArg);
@@ -2695,7 +2695,7 @@
 							"-extdir")); //$NON-NLS-1$
 				}
 				StringTokenizer tokenizer = new StringTokenizer(currentArg,	File.pathSeparator, false);
-				extdirsClasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
+				extdirsClasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
 				while (tokenizer.hasMoreTokens())
 					extdirsClasspaths.add(tokenizer.nextToken());
 				mode = DEFAULT;
@@ -2706,7 +2706,7 @@
 						this.bind("configure.unexpectedDestinationPathEntry", //$NON-NLS-1$
 							"-endorseddirs")); //$NON-NLS-1$
 				}				tokenizer = new StringTokenizer(currentArg,	File.pathSeparator, false);
-				endorsedDirClasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
+				endorsedDirClasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
 				while (tokenizer.hasMoreTokens())
 					endorsedDirClasspaths.add(tokenizer.nextToken());
 				mode = DEFAULT;
@@ -2944,8 +2944,8 @@
 				getAllEncodings(specifiedEncodings)));
 	}
 	if (this.pendingErrors != null) {
-		for (Iterator iterator = this.pendingErrors.iterator(); iterator.hasNext(); ) {
-			String message = (String) iterator.next();
+		for (Iterator<String> iterator = this.pendingErrors.iterator(); iterator.hasNext(); ) {
+			String message = iterator.next();
 			this.logger.logPendingError(message);
 		}
 		this.pendingErrors = null;
@@ -2976,7 +2976,7 @@
 	return result;
 }
 
-private static String getAllEncodings(Set encodings) {
+private static String getAllEncodings(Set<String> encodings) {
 	int size = encodings.size();
 	String[] allEncodings = new String[size];
 	encodings.toArray(allEncodings);
@@ -2990,7 +2990,7 @@
 	}
 	return String.valueOf(buffer);
 }
-
+@SuppressWarnings("rawtypes")
 private void initializeWarnings(String propertiesFile) {
 	File file = new File(propertiesFile);
 	if (!file.exists()) {
@@ -3014,7 +3014,7 @@
 			}
 		}
 	}
-	for (Iterator iterator = properties.entrySet().iterator(); iterator.hasNext(); ) {
+	for(Iterator iterator = properties.entrySet().iterator(); iterator.hasNext(); ) {
 		Map.Entry entry = (Map.Entry) iterator.next();
 		final String key = entry.getKey().toString();
 		if (key.startsWith("org.eclipse.jdt.core.compiler.")) { //$NON-NLS-1$
@@ -3067,15 +3067,10 @@
 			checkedValue = CompilerOptions.INFO;
 			break;
 	}
-	Object[] entries = this.options.entrySet().toArray();
-	for (int i = 0, max = entries.length; i < max; i++) {
-		Map.Entry entry = (Map.Entry) entries[i];
-		if (!(entry.getKey() instanceof String))
-			continue;
-		if (!(entry.getValue() instanceof String))
-			continue;
-		if (((String) entry.getValue()).equals(checkedValue)) {
-			this.options.put((String) entry.getKey(), CompilerOptions.IGNORE);
+	Set<Entry<String, String>> entrySet = this.options.entrySet();
+	for (Entry<String, String> entry : entrySet) {
+		if (entry.getValue().equals(checkedValue)) {
+			this.options.put(entry.getKey(), CompilerOptions.IGNORE);
 		}
 	}
 	if (severity == ProblemSeverities.Warning) {
@@ -3184,55 +3179,43 @@
 /*
  * External API
  */
-protected ArrayList handleBootclasspath(ArrayList bootclasspaths, String customEncoding) {
+protected ArrayList<Classpath> handleBootclasspath(ArrayList<String> bootclasspaths, String customEncoding) {
  	final int bootclasspathsSize;
+ 	ArrayList<Classpath> result = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
 	if ((bootclasspaths != null)
-		&& ((bootclasspathsSize = bootclasspaths.size()) != 0))
-	{
-		String[] paths = new String[bootclasspathsSize];
-		bootclasspaths.toArray(paths);
-		bootclasspaths.clear();
-		for (int i = 0; i < bootclasspathsSize; i++) {
-			processPathEntries(DEFAULT_SIZE_CLASSPATH, bootclasspaths,
-				paths[i], customEncoding, false, true);
+		&& ((bootclasspathsSize = bootclasspaths.size()) != 0)) {
+		result = new ArrayList<>(bootclasspathsSize);
+		for (String path : bootclasspaths) {
+			processPathEntries(DEFAULT_SIZE_CLASSPATH, result, path, customEncoding, false, true);
 		}
 	} else {
-		bootclasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
 		try {
-			Util.collectRunningVMBootclasspath(bootclasspaths);
+			Util.collectRunningVMBootclasspath(result);
 		} catch(IllegalStateException e) {
 			this.logger.logWrongJDK();
 			this.proceed = false;
 			return null;
 		}
 	}
-	return bootclasspaths;
+	return result;
 }
-
 /*
  * External API
  */
-protected ArrayList handleClasspath(ArrayList classpaths, String customEncoding) {
-	final int classpathsSize;
-	if ((classpaths != null)
-		&& ((classpathsSize = classpaths.size()) != 0))
-	{
-		String[] paths = new String[classpathsSize];
-		classpaths.toArray(paths);
-		classpaths.clear();
-		for (int i = 0; i < classpathsSize; i++) {
-			processPathEntries(DEFAULT_SIZE_CLASSPATH, classpaths, paths[i],
-					customEncoding, false, true);
+protected ArrayList<FileSystem.Classpath> handleClasspath(ArrayList<String> classpaths, String customEncoding) {
+	ArrayList<FileSystem.Classpath> initial = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
+	if (classpaths != null && classpaths.size() > 0) {
+		for (String path : classpaths) {
+			processPathEntries(DEFAULT_SIZE_CLASSPATH, initial, path, customEncoding, false, true);
 		}
 	} else {
 		// no user classpath specified.
-		classpaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
 		String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
 		if ((classProp == null) || (classProp.length() == 0)) {
 			addPendingErrors(this.bind("configure.noClasspath")); //$NON-NLS-1$
 			final Classpath classpath = FileSystem.getClasspath(System.getProperty("user.dir"), customEncoding, null, this.options);//$NON-NLS-1$
 			if (classpath != null) {
-				classpaths.add(classpath);
+				initial.add(classpath);
 			}
 		} else {
 			StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
@@ -3242,15 +3225,15 @@
 				FileSystem.Classpath currentClasspath = FileSystem
 						.getClasspath(token, customEncoding, null, this.options);
 				if (currentClasspath != null) {
-					classpaths.add(currentClasspath);
+					initial.add(currentClasspath);
 				} else if (token.length() != 0) {
 					addPendingErrors(this.bind("configure.incorrectClasspath", token));//$NON-NLS-1$
 				}
 			}
 		}
 	}
-	ArrayList result = new ArrayList();
-	HashMap knownNames = new HashMap();
+	ArrayList<Classpath> result = new ArrayList<>();
+	HashMap<String, Classpath> knownNames = new HashMap<>();
 	FileSystem.ClasspathSectionProblemReporter problemReporter =
 		new FileSystem.ClasspathSectionProblemReporter() {
 			public void invalidClasspathSection(String jarFilePath) {
@@ -3260,15 +3243,15 @@
 				addPendingErrors(bind("configure.multipleClasspathSections", jarFilePath)); //$NON-NLS-1$
 			}
 		};
-	while (! classpaths.isEmpty()) {
-		Classpath current = (Classpath) classpaths.remove(0);
+	while (! initial.isEmpty()) {
+		Classpath current = initial.remove(0);
 		String currentPath = current.getPath();
 		if (knownNames.get(currentPath) == null) {
 			knownNames.put(currentPath, current);
 			result.add(current);
-			List linkedJars = current.fetchLinkedJars(problemReporter);
+			List<Classpath> linkedJars = current.fetchLinkedJars(problemReporter);
 			if (linkedJars != null) {
-				classpaths.addAll(0, linkedJars);
+				initial.addAll(0, linkedJars);
 			}
 		}
 	}
@@ -3286,7 +3269,7 @@
 	 * - else default extensions directory for the platform. (/lib/endorsed)
 	 */
 	if (endorsedDirClasspaths == null) {
-		endorsedDirClasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
+		endorsedDirClasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
 		String endorsedDirsStr = System.getProperty("java.endorsed.dirs"); //$NON-NLS-1$
 		if (endorsedDirsStr == null) {
 			if (javaHome != null) {
@@ -3350,7 +3333,7 @@
 	 * - else default extensions directory for the platform.
 	 */
 	if (extdirsClasspaths == null) {
-		extdirsClasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH);
+		extdirsClasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
 		String extdirsStr = System.getProperty("java.ext.dirs"); //$NON-NLS-1$
 		if (extdirsStr == null) {
 			extdirsClasspaths.add(javaHome.getAbsolutePath() + "/lib/ext"); //$NON-NLS-1$
@@ -4125,7 +4108,7 @@
  * @deprecated - use {@link #initialize(PrintWriter, PrintWriter, boolean, Map, CompilationProgress)} instead
  *                       e.g. initialize(outWriter, errWriter, systemExit, customDefaultOptions, null)
  */
-protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit, Map customDefaultOptions) {
+protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit, Map<String, String> customDefaultOptions) {
 	this.initialize(outWriter, errWriter, systemExit, customDefaultOptions, null /* progress */);
 }
 protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit, Map<String, String> customDefaultOptions, CompilationProgress compilationProgress) {
@@ -4154,7 +4137,7 @@
 protected void initializeAnnotationProcessorManager() {
 	String className = "org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager"; //$NON-NLS-1$
 	try {
-		Class c = Class.forName(className);
+		Class<?> c = Class.forName(className);
 		AbstractAnnotationProcessorManager annotationManager = (AbstractAnnotationProcessorManager) c.newInstance();
 		annotationManager.configure(this, this.expandedCommandLine);
 		annotationManager.setErr(this.err);
@@ -4351,15 +4334,15 @@
 /*
  * External API
  */
-public void processPathEntries(final int defaultSize, final ArrayList paths,
+public void processPathEntries(final int defaultSize, final ArrayList<FileSystem.Classpath> paths,
 			final String currentPath, String customEncoding, boolean isSourceOnly,
 			boolean rejectDestinationPathOnJars) {
 	String currentClasspathName = null;
 	String currentDestinationPath = null;
-	ArrayList currentRuleSpecs = new ArrayList(defaultSize);
+	ArrayList<String> currentRuleSpecs = new ArrayList<>(defaultSize);
 	StringTokenizer tokenizer = new StringTokenizer(currentPath,
 			File.pathSeparator + "[]", true); //$NON-NLS-1$
-	ArrayList tokens = new ArrayList();
+	ArrayList<String> tokens = new ArrayList<>();
 	while (tokenizer.hasMoreTokens()) {
 		tokens.add(tokenizer.nextToken());
 	}
@@ -4393,7 +4376,7 @@
 	String token = null;
 	int cursor = 0, tokensNb = tokens.size(), bracket = -1;
 	while (cursor < tokensNb && state != error) {
-		token = (String) tokens.get(cursor++);
+		token = tokens.get(cursor++);
 		if (token.equals(File.pathSeparator)) {
 			switch (state) {
 			case start:
@@ -4498,7 +4481,7 @@
 				break;
 			case bracketClosed:
 				for (int i = bracket; i < cursor ; i++) {
-					currentClasspathName += (String) tokens.get(i);
+					currentClasspathName += tokens.get(i);
 				}
 				state = readyToClose;
 				break;
@@ -4533,7 +4516,7 @@
 	}
 }
 
-private int processPaths(String[] args, int index, String currentArg, ArrayList paths) {
+private int processPaths(String[] args, int index, String currentArg, ArrayList<String> paths) {
 	int localIndex = index;
 	int count = 0;
 	for (int i = 0, max = currentArg.length(); i < max; i++) {
@@ -4684,21 +4667,22 @@
 /*
  * External API
  */
-protected void setPaths(ArrayList bootclasspaths,
+protected void setPaths(ArrayList<String> bootclasspaths,
 		String sourcepathClasspathArg,
-		ArrayList sourcepathClasspaths,
-		ArrayList classpaths,
-		ArrayList extdirsClasspaths,
-		ArrayList endorsedDirClasspaths,
+		ArrayList<String> sourcepathClasspaths,
+		ArrayList<String> classpaths,
+		ArrayList<String> extdirsClasspaths,
+		ArrayList<String> endorsedDirClasspaths,
 		String customEncoding) {
 
 	// process bootclasspath, classpath and sourcepaths
- 	bootclasspaths = handleBootclasspath(bootclasspaths, customEncoding);
+ 	ArrayList<Classpath> allPaths = handleBootclasspath(bootclasspaths, customEncoding);
 
-	classpaths = handleClasspath(classpaths, customEncoding);
+	List<FileSystem.Classpath> cp = handleClasspath(classpaths, customEncoding);
 
+	ArrayList<FileSystem.Classpath> sourcepaths = new ArrayList<>();
 	if (sourcepathClasspathArg != null) {
-		processPathEntries(DEFAULT_SIZE_CLASSPATH, sourcepathClasspaths,
+		processPathEntries(DEFAULT_SIZE_CLASSPATH, sourcepaths,
 			sourcepathClasspathArg, customEncoding, true, false);
 	}
 
@@ -4708,9 +4692,9 @@
 	 * - else java.ext.dirs if defined;
 	 * - else default extensions directory for the platform.
 	 */
-	extdirsClasspaths = handleExtdirs(extdirsClasspaths);
+	List<FileSystem.Classpath> extdirs = handleExtdirs(extdirsClasspaths);
 
-	endorsedDirClasspaths = handleEndorseddirs(endorsedDirClasspaths);
+	List<FileSystem.Classpath> endorsed = handleEndorseddirs(endorsedDirClasspaths);
 
 	/*
 	 * Concatenate classpath entries
@@ -4720,20 +4704,19 @@
 	 * entries are searched for both sources and binaries except
 	 * the sourcepath entries which are searched for sources only.
 	 */
-	bootclasspaths.addAll(0, endorsedDirClasspaths);
-	bootclasspaths.addAll(extdirsClasspaths);
-	bootclasspaths.addAll(sourcepathClasspaths);
-	bootclasspaths.addAll(classpaths);
-	classpaths = bootclasspaths;
-	classpaths = FileSystem.ClasspathNormalizer.normalize(classpaths);
-	this.checkedClasspaths = new FileSystem.Classpath[classpaths.size()];
-	classpaths.toArray(this.checkedClasspaths);
+	allPaths.addAll(0, endorsed);
+	allPaths.addAll(extdirs);
+	allPaths.addAll(sourcepaths);
+	allPaths.addAll(cp);
+	allPaths = FileSystem.ClasspathNormalizer.normalize(allPaths);
+	this.checkedClasspaths = new FileSystem.Classpath[allPaths.size()];
+	allPaths.toArray(this.checkedClasspaths);
 	this.logger.logClasspath(this.checkedClasspaths);
 
 	if (this.annotationPaths != null && CompilerOptions.ENABLED.equals(this.options.get(CompilerOptions.OPTION_AnnotationBasedNullAnalysis))) {
-		for (FileSystem.Classpath cp : this.checkedClasspaths) {
-			if (cp instanceof ClasspathJar)
-				((ClasspathJar) cp).annotationPaths = this.annotationPaths;
+		for (FileSystem.Classpath c : this.checkedClasspaths) {
+			if (c instanceof ClasspathJar)
+				((ClasspathJar) c).annotationPaths = this.annotationPaths;
 		}
 	}
 }
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java
index 56a86ef..c9c502f 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -35,6 +35,7 @@
 import org.eclipse.jdt.internal.compiler.ClassFile;
 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
 import org.eclipse.jdt.internal.compiler.batch.FileSystem;
+import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
 import org.eclipse.jdt.internal.compiler.batch.Main;
 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
 import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
@@ -45,7 +46,6 @@
 import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
 import org.eclipse.jdt.internal.compiler.lookup.WildcardBinding;
 
-@SuppressWarnings({"rawtypes", "unchecked"})
 public class Util implements SuffixConstants {
 
 	/**
@@ -1007,6 +1007,7 @@
 			output.close();
 		}
 	}
+	@SuppressWarnings({ "rawtypes", "unchecked" })
 	public static void recordNestedType(ClassFile classFile, TypeBinding typeBinding) {
 		if (classFile.visitedTypes == null) {
 			classFile.visitedTypes = new HashSet(3);
@@ -1093,7 +1094,7 @@
 		return null;
 	}
 
-	public static void collectRunningVMBootclasspath(List bootclasspaths) {
+	public static void collectRunningVMBootclasspath(List<Classpath> bootclasspaths) {
 		for (String filePath : collectFilesNames()) {
 			FileSystem.Classpath currentClasspath = FileSystem.getClasspath(filePath, null, null, null);
 			if (currentClasspath != null) {
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java
index 70a6e25..7ce431c 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java
@@ -35,6 +35,7 @@
 import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall;
 import org.eclipse.jdt.internal.compiler.batch.Main;
+import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
 import org.eclipse.jdt.internal.compiler.env.IBinaryType;
 import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner;
 import org.eclipse.jdt.internal.compiler.parser.RecoveryScannerData;
@@ -235,9 +236,9 @@
 		initializeDefaults();
 	}
 
-	private List getClasspath() throws IllegalStateException {
+	private List<Classpath> getClasspath() throws IllegalStateException {
 		Main main = new Main(new PrintWriter(System.out), new PrintWriter(System.err), false/*systemExit*/, null/*options*/, null/*progress*/);
-		ArrayList allClasspaths = new ArrayList();
+		ArrayList<Classpath> allClasspaths = new ArrayList<Classpath>();
 		try {
 			if ((this.bits & CompilationUnitResolver.INCLUDE_RUNNING_VM_BOOTCLASSPATH) != 0) {
 				org.eclipse.jdt.internal.compiler.util.Util.collectRunningVMBootclasspath(allClasspaths);