7152007: Fix warnings in sun/rmi/rmic
Summary: Minor code changes to remove warnings in sun/rmi/rmic
Reviewed-by: chegar, smarks
--- a/jdk/src/share/classes/sun/rmi/rmic/BatchEnvironment.java Wed Mar 14 08:43:28 2012 +0100
+++ b/jdk/src/share/classes/sun/rmi/rmic/BatchEnvironment.java Fri Mar 16 11:52:48 2012 -0700
@@ -160,7 +160,7 @@
}
/** list of generated source files created in this environment */
- private Vector generatedFiles = new Vector();
+ private Vector<File> generatedFiles = new Vector<>();
/**
* Remember a generated source file generated so that it
@@ -177,9 +177,9 @@
*/
public void deleteGeneratedFiles() {
synchronized(generatedFiles) {
- Enumeration enumeration = generatedFiles.elements();
+ Enumeration<File> enumeration = generatedFiles.elements();
while (enumeration.hasMoreElements()) {
- File file = (File) enumeration.nextElement();
+ File file = enumeration.nextElement();
file.delete();
}
generatedFiles.removeAllElements();
--- a/jdk/src/share/classes/sun/rmi/rmic/Main.java Wed Mar 14 08:43:28 2012 +0100
+++ b/jdk/src/share/classes/sun/rmi/rmic/Main.java Fri Mar 16 11:52:48 2012 -0700
@@ -73,14 +73,15 @@
File destDir;
int flags;
long tm;
- Vector classes;
+ Vector<String> classes;
boolean nowrite;
boolean nocompile;
boolean keepGenerated;
boolean status;
String[] generatorArgs;
- Vector generators;
- Class environmentClass = BatchEnvironment.class;
+ Vector<Generator> generators;
+ Class<? extends BatchEnvironment> environmentClass =
+ BatchEnvironment.class;
boolean iiopGeneration = false;
/**
@@ -183,7 +184,7 @@
destDir = null;
flags = F_WARNINGS;
tm = System.currentTimeMillis();
- classes = new Vector();
+ classes = new Vector<>();
nowrite = false;
nocompile = false;
keepGenerated = false;
@@ -191,7 +192,7 @@
if (generatorArgs == null) {
return false;
}
- generators = new Vector();
+ generators = new Vector<>();
// Pre-process command line for @file arguments
try {
@@ -411,7 +412,7 @@
// Get the environment required by this generator...
- Class envClass = BatchEnvironment.class;
+ Class<?> envClass = BatchEnvironment.class;
String env = getString("generator.env." + arg);
if (env != null) {
try {
@@ -423,7 +424,7 @@
// Yes, so switch to the new one...
- environmentClass = envClass;
+ environmentClass = envClass.asSubclass(BatchEnvironment.class);
} else {
@@ -495,8 +496,9 @@
try {
Class[] ctorArgTypes = {OutputStream.class,ClassPath.class,Main.class};
Object[] ctorArgs = {out,classPath,this};
- Constructor constructor = environmentClass.getConstructor(ctorArgTypes);
- result = (BatchEnvironment) constructor.newInstance(ctorArgs);
+ Constructor<? extends BatchEnvironment> constructor =
+ environmentClass.getConstructor(ctorArgTypes);
+ result = constructor.newInstance(ctorArgs);
result.reset();
}
catch (Exception e) {
@@ -530,7 +532,7 @@
*/
for (int i = classes.size()-1; i >= 0; i-- ) {
Identifier implClassName =
- Identifier.lookup((String)classes.elementAt(i));
+ Identifier.lookup(classes.elementAt(i));
/*
* Fix bugid 4049354: support using '.' as an inner class
@@ -558,7 +560,7 @@
try {
ClassDefinition def = decl.getClassDefinition(env);
for (int j = 0; j < generators.size(); j++) {
- Generator gen = (Generator)generators.elementAt(j);
+ Generator gen = generators.elementAt(j);
gen.generate(env, def, destDir);
}
} catch (ClassNotFound ex) {
@@ -673,7 +675,7 @@
do {
done = true;
- for (Enumeration e = env.getClasses() ; e.hasMoreElements() ; ) {
+ for (Enumeration<?> e = env.getClasses() ; e.hasMoreElements() ; ) {
ClassDeclaration c = (ClassDeclaration)e.nextElement();
done = compileClass(c,buf,env);
}
@@ -682,7 +684,9 @@
/*
* Compile a single class.
+ * Fallthrough is intentional
*/
+ @SuppressWarnings("fallthrough")
public boolean compileClass (ClassDeclaration c,
ByteArrayOutputStream buf,
BatchEnvironment env)
@@ -879,6 +883,6 @@
args[1] = (arg1 != null ? arg1.toString() : "null");
args[2] = (arg2 != null ? arg2.toString() : "null");
- return java.text.MessageFormat.format(format, args);
+ return java.text.MessageFormat.format(format, (Object[]) args);
}
}
--- a/jdk/src/share/classes/sun/rmi/rmic/RMIGenerator.java Wed Mar 14 08:43:28 2012 +0100
+++ b/jdk/src/share/classes/sun/rmi/rmic/RMIGenerator.java Fri Mar 16 11:52:48 2012 -0700
@@ -61,7 +61,7 @@
*/
public class RMIGenerator implements RMIConstants, Generator {
- private static final Hashtable versionOptions = new Hashtable();
+ private static final Hashtable<String, Integer> versionOptions = new Hashtable<>();
static {
versionOptions.put("-v1.1", new Integer(STUB_VERSION_1_1));
versionOptions.put("-vcompat", new Integer(STUB_VERSION_FAT));
@@ -96,7 +96,7 @@
return false;
}
explicitVersion = arg;
- version = ((Integer) versionOptions.get(arg)).intValue();
+ version = versionOptions.get(arg);
argv[i] = null;
}
}
@@ -519,7 +519,7 @@
* follows a previous catch of it or of one of its superclasses.
* The following method invocation takes care of these details.
*/
- Vector catchList = computeUniqueCatchList(exceptions);
+ Vector<ClassDefinition> catchList = computeUniqueCatchList(exceptions);
/*
* If we need to catch any particular exceptions (i.e. this method
@@ -615,10 +615,10 @@
* UnexpectedException, and end the try block.
*/
if (catchList.size() > 0) {
- for (Enumeration enumeration = catchList.elements();
+ for (Enumeration<ClassDefinition> enumeration = catchList.elements();
enumeration.hasMoreElements();)
{
- ClassDefinition def = (ClassDefinition) enumeration.nextElement();
+ ClassDefinition def = enumeration.nextElement();
p.pOlnI("} catch (" + def.getName() + " e) {");
p.pln("throw e;");
}
@@ -650,8 +650,8 @@
* of its superclasses is in the throws clause of the method, indicating
* that no exceptions need to be caught.
*/
- private Vector computeUniqueCatchList(ClassDeclaration[] exceptions) {
- Vector uniqueList = new Vector(); // unique exceptions to catch
+ private Vector<ClassDefinition> computeUniqueCatchList(ClassDeclaration[] exceptions) {
+ Vector<ClassDefinition> uniqueList = new Vector<>(); // unique exceptions to catch
uniqueList.addElement(defRuntimeException);
uniqueList.addElement(defRemoteException);
@@ -682,8 +682,7 @@
* exceptions that need to be caught:
*/
for (int j = 0; j < uniqueList.size();) {
- ClassDefinition def =
- (ClassDefinition) uniqueList.elementAt(j);
+ ClassDefinition def = uniqueList.elementAt(j);
if (def.superClassOf(env, decl)) {
/*
* If a superclass of this exception is already on
--- a/jdk/src/share/classes/sun/rmi/rmic/newrmic/Main.java Wed Mar 14 08:43:28 2012 +0100
+++ b/jdk/src/share/classes/sun/rmi/rmic/newrmic/Main.java Fri Mar 16 11:52:48 2012 -0700
@@ -455,7 +455,7 @@
BatchEnvironment env;
try {
Constructor<? extends BatchEnvironment> cons =
- batch.envClass.getConstructor(new Class[] { RootDoc.class });
+ batch.envClass.getConstructor(new Class<?>[] { RootDoc.class });
env = cons.newInstance(rootDoc);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
--- a/jdk/src/share/classes/sun/rmi/rmic/newrmic/Resources.java Wed Mar 14 08:43:28 2012 +0100
+++ b/jdk/src/share/classes/sun/rmi/rmic/newrmic/Resources.java Fri Mar 16 11:52:48 2012 -0700
@@ -69,7 +69,7 @@
format = "missing resource key: key = \"" + key + "\", " +
"arguments = \"{0}\", \"{1}\", \"{2}\"";
}
- return MessageFormat.format(format, args);
+ return MessageFormat.format(format, (Object[]) args);
}
/**