提交 63976323 编写于 作者: J jgish

8003380: Compiler warnings in logging test code

Summary: Use generics, suppress warnings where appropriate, remove unused imports, etc.
Reviewed-by: lancea, chegar
上级 c804bc6b
/*
* 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.URL;
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 @@ public class ClassLoaderLeakTest {
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 @@ public class ClassLoaderLeakTest {
/* 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 @@ public class ClassLoaderLeakTest {
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);
}
......
......@@ -88,6 +88,7 @@ public class Listeners {
}
}
@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
LogManager logman = LogManager.getLogManager();
......
......@@ -35,6 +35,7 @@ import java.beans.PropertyChangeEvent;
public class ListenersWithSM {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
boolean granted = args[0].equals("grant");
......
/*
* 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.concurrent.atomic.AtomicInteger;
import java.util.ListResourceBundle;
import java.util.logging.Logger;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
public class LoggerResourceBundleRace extends RacingThreadsTest {
......
/*
* 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 @@ public class LoggingDeadlock2 {
// 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 class LoggingDeadlock2 {
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();
......
/*
* 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 class LoggingDeadlock3 {
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();
}
......
......@@ -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 @@ public class LoggingDeadlock4 {
} catch (InterruptedException e) {
}
LogManager manager = LogManager.getLogManager();
LogManager.getLogManager();
}
};
lmThread.start();
......@@ -86,7 +85,7 @@ public class LoggingDeadlock4 {
} catch (InterruptedException e) {
}
Logger foo = Logger.getLogger("foo logger");
Logger.getLogger("foo logger");
}
};
logThread.start();
......
......@@ -208,7 +208,7 @@ public class LoggingMXBeanTest
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 @@ public class LoggingMXBeanTest
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 class LoggingMXBeanTest
}
public static void main(String[] argv) throws Exception {
LoggingMXBeanTest p = new LoggingMXBeanTest();
new LoggingMXBeanTest();
}
}
......@@ -37,7 +37,6 @@ import java.util.ListIterator;
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 @@ public class LoggingMXBeanTest2
*/
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 class LoggingMXBeanTest2
}
public static void main(String[] argv) throws Exception {
LoggingMXBeanTest2 p = new LoggingMXBeanTest2();
new LoggingMXBeanTest2();
}
}
......@@ -48,7 +48,7 @@ public class MemoryHandlerTest {
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
......
/*
* 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 @@ public class ParentLoggersTest {
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);
......
/*
* 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 @@ public class SimpleFormatterFormat {
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 &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册