8003380: Compiler warnings in logging test code
Summary: Use generics, suppress warnings where appropriate, remove unused imports, etc.
Reviewed-by: lancea, chegar
--- a/jdk/test/java/util/logging/ClassLoaderLeakTest.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/ClassLoaderLeakTest.java Thu Nov 29 12:28:02 2012 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2012, 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
@@ -40,7 +40,6 @@
import java.net.URLClassLoader;
import java.util.concurrent.CountDownLatch;
import java.util.logging.Logger;
-import java.util.logging.Logger;
public class ClassLoaderLeakTest {
@@ -59,11 +58,11 @@
try {
ClassLoader cl =
Thread.currentThread().getContextClassLoader();
- Class appMain = cl.loadClass("AppTest");
+ Class<?> appMain = cl.loadClass("AppTest");
Method launch =
appMain.getDeclaredMethod("launch", doneSignal.getClass());
- Constructor c = appMain.getConstructor();
+ Constructor<?> c = appMain.getConstructor();
Object o = c.newInstance();
@@ -80,8 +79,7 @@
/* prepare test class loader */
URL pwd = null;
try {
-
- pwd = new File(System.getProperty("test.classes",".")).toURL();
+ pwd = new File(System.getProperty("test.classes",".")).toURI().toURL();
} catch (MalformedURLException e) {
throw new RuntimeException("Test failed.", e);
}
@@ -139,7 +137,7 @@
uniqClassName = uniq;
}
- public Class loadClass(String name) throws ClassNotFoundException {
+ public Class<?> loadClass(String name) throws ClassNotFoundException {
if (verbose) {
System.out.printf("%s: load class %s\n", uniqClassName, name);
}
--- a/jdk/test/java/util/logging/Listeners.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/Listeners.java Thu Nov 29 12:28:02 2012 +0000
@@ -88,6 +88,7 @@
}
}
+ @SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
LogManager logman = LogManager.getLogManager();
--- a/jdk/test/java/util/logging/ListenersWithSM.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/ListenersWithSM.java Thu Nov 29 12:28:02 2012 +0000
@@ -35,6 +35,7 @@
public class ListenersWithSM {
+ @SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
boolean granted = args[0].equals("grant");
--- a/jdk/test/java/util/logging/LoggerResourceBundleRace.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/LoggerResourceBundleRace.java Thu Nov 29 12:28:02 2012 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2012 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
@@ -30,11 +30,10 @@
* @run main LoggerResourceBundleRace
*/
+import java.util.ListResourceBundle;
+import java.util.MissingResourceException;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.ListResourceBundle;
import java.util.logging.Logger;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
public class LoggerResourceBundleRace extends RacingThreadsTest {
--- a/jdk/test/java/util/logging/LoggingDeadlock2.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/LoggingDeadlock2.java Thu Nov 29 12:28:02 2012 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2012 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
@@ -103,7 +103,7 @@
// This may or may not result in a first call to
// Runtime.addShutdownHook after shutdown has already
// commenced.
- LogManager log = LogManager.getLogManager();
+ LogManager.getLogManager();
if (dojoin) {
exiter.join();
@@ -148,7 +148,6 @@
public String out() { return out; }
public String err() { return err; }
public int exitValue() { return exitValue; }
- public Throwable throwable() { return throwable; }
public String toString() {
StringBuilder sb = new StringBuilder();
--- a/jdk/test/java/util/logging/LoggingDeadlock3.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/LoggingDeadlock3.java Thu Nov 29 12:28:02 2012 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2012 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
@@ -61,7 +61,7 @@
public static class GetLogger implements Runnable {
public void run() {
for (int cnt = 0; cnt < ITER_CNT * 8; cnt++) {
- Logger logger = Logger.getLogger("com.sun.Hello"+cnt/10);
+ Logger.getLogger("com.sun.Hello"+cnt/10);
if (cnt % 1000 == 0) out.print("1");
if (cnt % 10000 == 0) out.println();
}
--- a/jdk/test/java/util/logging/LoggingDeadlock4.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/LoggingDeadlock4.java Thu Nov 29 12:28:02 2012 +0000
@@ -30,7 +30,6 @@
* @run main/othervm/timeout=15 -Djava.awt.headless=true LoggingDeadlock4
*/
-import java.awt.Container;
import java.util.concurrent.CountDownLatch;
import java.util.logging.LogManager;
import java.util.logging.Logger;
@@ -68,7 +67,7 @@
} catch (InterruptedException e) {
}
- LogManager manager = LogManager.getLogManager();
+ LogManager.getLogManager();
}
};
lmThread.start();
@@ -86,7 +85,7 @@
} catch (InterruptedException e) {
}
- Logger foo = Logger.getLogger("foo logger");
+ Logger.getLogger("foo logger");
}
};
logThread.start();
--- a/jdk/test/java/util/logging/LoggingMXBeanTest.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/LoggingMXBeanTest.java Thu Nov 29 12:28:02 2012 +0000
@@ -208,7 +208,7 @@
String levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
l = Level.parse(levelName);
System.out.print(" Logger1: " );
- if ( l.equals( l.ALL ) ) {
+ if ( l.equals( Level.ALL ) ) {
System.out.println("Level Set to ALL: PASSED" );
log1 = true;
}
@@ -226,7 +226,7 @@
levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
l = Level.parse(levelName);
System.out.print(" Logger2: " );
- if ( l.equals( l.FINER ) ) {
+ if ( l.equals( Level.FINER ) ) {
System.out.println("Level Set to FINER: PASSED" );
log2 = true;
}
@@ -247,6 +247,6 @@
}
public static void main(String[] argv) throws Exception {
- LoggingMXBeanTest p = new LoggingMXBeanTest();
+ new LoggingMXBeanTest();
}
}
--- a/jdk/test/java/util/logging/LoggingMXBeanTest2.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/LoggingMXBeanTest2.java Thu Nov 29 12:28:02 2012 +0000
@@ -37,7 +37,6 @@
public class LoggingMXBeanTest2
{
-
static LoggingMXBean mbean = LogManager.getLoggingMXBean();
static String LOGGER_NAME_1 = "com.sun.management.Logger";
static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2";
@@ -57,14 +56,14 @@
*/
System.out.println("Test Logger Name retrieval (getLoggerNames)");
boolean log1 = false, log2 = false;
- List loggers = mbean.getLoggerNames();
+ List<String> loggers = mbean.getLoggerNames();
if (loggers == null || loggers.size() < 2) {
throw new RuntimeException(
"Could not Detect the presense of the new Loggers");
}
- for (ListIterator iter = loggers.listIterator(); iter.hasNext(); ) {
- String logger = (String) iter.next();
+ for (ListIterator<String> iter = loggers.listIterator(); iter.hasNext(); ) {
+ String logger = iter.next();
if (logger.equals(LOGGER_NAME_1)) {
log1 = true;
System.out.println(" : Found new Logger : " + logger);
@@ -187,6 +186,6 @@
}
public static void main(String[] argv) throws Exception {
- LoggingMXBeanTest2 p = new LoggingMXBeanTest2();
+ new LoggingMXBeanTest2();
}
}
--- a/jdk/test/java/util/logging/MemoryHandlerTest.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/MemoryHandlerTest.java Thu Nov 29 12:28:02 2012 +0000
@@ -48,7 +48,7 @@
File fname = new File(tstSrc, LM_PROP_FNAME);
String prop = fname.getCanonicalPath();
System.setProperty(CFG_FILE_PROP, prop);
- LogManager logMgr = LogManager.getLogManager();
+ LogManager.getLogManager();
// create a logger
logger = Logger.getLogger(MemoryHandlerTest.class.getName());
// don't have parent handlers get log messages
--- a/jdk/test/java/util/logging/ParentLoggersTest.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/ParentLoggersTest.java Thu Nov 29 12:28:02 2012 +0000
@@ -1,3 +1,26 @@
+/*
+ * Copyright (c) 2012, 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 6498300
@@ -86,12 +109,12 @@
Vector<String> expectedLoggerNames = new Vector<String>(getDefaultLoggerNames());
// Create the logger LOGGER_NAME_1
- Logger logger1 = Logger.getLogger(LOGGER_NAME_1);
+ Logger.getLogger(LOGGER_NAME_1);
expectedLoggerNames.addElement(PARENT_NAME_1);
expectedLoggerNames.addElement(LOGGER_NAME_1);
// Create the logger LOGGER_NAME_2
- Logger logger2 = Logger.getLogger(LOGGER_NAME_2);
+ Logger.getLogger(LOGGER_NAME_2);
expectedLoggerNames.addElement(PARENT_NAME_2);
expectedLoggerNames.addElement(LOGGER_NAME_2);
--- a/jdk/test/java/util/logging/SimpleFormatterFormat.java Thu Nov 29 09:47:31 2012 +0000
+++ b/jdk/test/java/util/logging/SimpleFormatterFormat.java Thu Nov 29 12:28:02 2012 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2012 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
@@ -92,8 +92,9 @@
System.out.println("Checking log records in file: " + log);
Pattern p = Pattern.compile("([\\.a-zA-Z:]+) (.*) \\[.*\\] source: (.*)");
- try (FileInputStream in = new FileInputStream(log)) {
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ try (FileInputStream in = new FileInputStream(log);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ ) {
String line;
int i = 0;
while (i < messages.length &&