提交 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -40,7 +40,6 @@ import java.net.URL; ...@@ -40,7 +40,6 @@ import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.Logger;
public class ClassLoaderLeakTest { public class ClassLoaderLeakTest {
...@@ -59,11 +58,11 @@ public class ClassLoaderLeakTest { ...@@ -59,11 +58,11 @@ public class ClassLoaderLeakTest {
try { try {
ClassLoader cl = ClassLoader cl =
Thread.currentThread().getContextClassLoader(); Thread.currentThread().getContextClassLoader();
Class appMain = cl.loadClass("AppTest"); Class<?> appMain = cl.loadClass("AppTest");
Method launch = Method launch =
appMain.getDeclaredMethod("launch", doneSignal.getClass()); appMain.getDeclaredMethod("launch", doneSignal.getClass());
Constructor c = appMain.getConstructor(); Constructor<?> c = appMain.getConstructor();
Object o = c.newInstance(); Object o = c.newInstance();
...@@ -80,8 +79,7 @@ public class ClassLoaderLeakTest { ...@@ -80,8 +79,7 @@ public class ClassLoaderLeakTest {
/* prepare test class loader */ /* prepare test class loader */
URL pwd = null; URL pwd = null;
try { try {
pwd = new File(System.getProperty("test.classes",".")).toURI().toURL();
pwd = new File(System.getProperty("test.classes",".")).toURL();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
throw new RuntimeException("Test failed.", e); throw new RuntimeException("Test failed.", e);
} }
...@@ -139,7 +137,7 @@ public class ClassLoaderLeakTest { ...@@ -139,7 +137,7 @@ public class ClassLoaderLeakTest {
uniqClassName = uniq; uniqClassName = uniq;
} }
public Class loadClass(String name) throws ClassNotFoundException { public Class<?> loadClass(String name) throws ClassNotFoundException {
if (verbose) { if (verbose) {
System.out.printf("%s: load class %s\n", uniqClassName, name); System.out.printf("%s: load class %s\n", uniqClassName, name);
} }
......
...@@ -88,6 +88,7 @@ public class Listeners { ...@@ -88,6 +88,7 @@ public class Listeners {
} }
} }
@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
LogManager logman = LogManager.getLogManager(); LogManager logman = LogManager.getLogManager();
......
...@@ -35,6 +35,7 @@ import java.beans.PropertyChangeEvent; ...@@ -35,6 +35,7 @@ import java.beans.PropertyChangeEvent;
public class ListenersWithSM { public class ListenersWithSM {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
boolean granted = args[0].equals("grant"); 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,11 +30,10 @@ ...@@ -30,11 +30,10 @@
* @run main LoggerResourceBundleRace * @run main LoggerResourceBundleRace
*/ */
import java.util.concurrent.atomic.AtomicInteger;
import java.util.ListResourceBundle; import java.util.ListResourceBundle;
import java.util.logging.Logger;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
public class LoggerResourceBundleRace extends RacingThreadsTest { 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -103,7 +103,7 @@ public class LoggingDeadlock2 { ...@@ -103,7 +103,7 @@ public class LoggingDeadlock2 {
// This may or may not result in a first call to // This may or may not result in a first call to
// Runtime.addShutdownHook after shutdown has already // Runtime.addShutdownHook after shutdown has already
// commenced. // commenced.
LogManager log = LogManager.getLogManager(); LogManager.getLogManager();
if (dojoin) { if (dojoin) {
exiter.join(); exiter.join();
...@@ -148,7 +148,6 @@ public class LoggingDeadlock2 { ...@@ -148,7 +148,6 @@ public class LoggingDeadlock2 {
public String out() { return out; } public String out() { return out; }
public String err() { return err; } public String err() { return err; }
public int exitValue() { return exitValue; } public int exitValue() { return exitValue; }
public Throwable throwable() { return throwable; }
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -61,7 +61,7 @@ public class LoggingDeadlock3 { ...@@ -61,7 +61,7 @@ public class LoggingDeadlock3 {
public static class GetLogger implements Runnable { public static class GetLogger implements Runnable {
public void run() { public void run() {
for (int cnt = 0; cnt < ITER_CNT * 8; cnt++) { 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 % 1000 == 0) out.print("1");
if (cnt % 10000 == 0) out.println(); if (cnt % 10000 == 0) out.println();
} }
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
* @run main/othervm/timeout=15 -Djava.awt.headless=true LoggingDeadlock4 * @run main/othervm/timeout=15 -Djava.awt.headless=true LoggingDeadlock4
*/ */
import java.awt.Container;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.logging.LogManager; import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -68,7 +67,7 @@ public class LoggingDeadlock4 { ...@@ -68,7 +67,7 @@ public class LoggingDeadlock4 {
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
LogManager manager = LogManager.getLogManager(); LogManager.getLogManager();
} }
}; };
lmThread.start(); lmThread.start();
...@@ -86,7 +85,7 @@ public class LoggingDeadlock4 { ...@@ -86,7 +85,7 @@ public class LoggingDeadlock4 {
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
Logger foo = Logger.getLogger("foo logger"); Logger.getLogger("foo logger");
} }
}; };
logThread.start(); logThread.start();
......
...@@ -208,7 +208,7 @@ public class LoggingMXBeanTest ...@@ -208,7 +208,7 @@ public class LoggingMXBeanTest
String levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature ); String levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
l = Level.parse(levelName); l = Level.parse(levelName);
System.out.print(" Logger1: " ); System.out.print(" Logger1: " );
if ( l.equals( l.ALL ) ) { if ( l.equals( Level.ALL ) ) {
System.out.println("Level Set to ALL: PASSED" ); System.out.println("Level Set to ALL: PASSED" );
log1 = true; log1 = true;
} }
...@@ -226,7 +226,7 @@ public class LoggingMXBeanTest ...@@ -226,7 +226,7 @@ public class LoggingMXBeanTest
levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature ); levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
l = Level.parse(levelName); l = Level.parse(levelName);
System.out.print(" Logger2: " ); System.out.print(" Logger2: " );
if ( l.equals( l.FINER ) ) { if ( l.equals( Level.FINER ) ) {
System.out.println("Level Set to FINER: PASSED" ); System.out.println("Level Set to FINER: PASSED" );
log2 = true; log2 = true;
} }
...@@ -247,6 +247,6 @@ public class LoggingMXBeanTest ...@@ -247,6 +247,6 @@ public class LoggingMXBeanTest
} }
public static void main(String[] argv) throws Exception { public static void main(String[] argv) throws Exception {
LoggingMXBeanTest p = new LoggingMXBeanTest(); new LoggingMXBeanTest();
} }
} }
...@@ -37,7 +37,6 @@ import java.util.ListIterator; ...@@ -37,7 +37,6 @@ import java.util.ListIterator;
public class LoggingMXBeanTest2 public class LoggingMXBeanTest2
{ {
static LoggingMXBean mbean = LogManager.getLoggingMXBean(); static LoggingMXBean mbean = LogManager.getLoggingMXBean();
static String LOGGER_NAME_1 = "com.sun.management.Logger"; static String LOGGER_NAME_1 = "com.sun.management.Logger";
static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2"; static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2";
...@@ -57,14 +56,14 @@ public class LoggingMXBeanTest2 ...@@ -57,14 +56,14 @@ public class LoggingMXBeanTest2
*/ */
System.out.println("Test Logger Name retrieval (getLoggerNames)"); System.out.println("Test Logger Name retrieval (getLoggerNames)");
boolean log1 = false, log2 = false; boolean log1 = false, log2 = false;
List loggers = mbean.getLoggerNames(); List<String> loggers = mbean.getLoggerNames();
if (loggers == null || loggers.size() < 2) { if (loggers == null || loggers.size() < 2) {
throw new RuntimeException( throw new RuntimeException(
"Could not Detect the presense of the new Loggers"); "Could not Detect the presense of the new Loggers");
} }
for (ListIterator iter = loggers.listIterator(); iter.hasNext(); ) { for (ListIterator<String> iter = loggers.listIterator(); iter.hasNext(); ) {
String logger = (String) iter.next(); String logger = iter.next();
if (logger.equals(LOGGER_NAME_1)) { if (logger.equals(LOGGER_NAME_1)) {
log1 = true; log1 = true;
System.out.println(" : Found new Logger : " + logger); System.out.println(" : Found new Logger : " + logger);
...@@ -187,6 +186,6 @@ public class LoggingMXBeanTest2 ...@@ -187,6 +186,6 @@ public class LoggingMXBeanTest2
} }
public static void main(String[] argv) throws Exception { public static void main(String[] argv) throws Exception {
LoggingMXBeanTest2 p = new LoggingMXBeanTest2(); new LoggingMXBeanTest2();
} }
} }
...@@ -48,7 +48,7 @@ public class MemoryHandlerTest { ...@@ -48,7 +48,7 @@ public class MemoryHandlerTest {
File fname = new File(tstSrc, LM_PROP_FNAME); File fname = new File(tstSrc, LM_PROP_FNAME);
String prop = fname.getCanonicalPath(); String prop = fname.getCanonicalPath();
System.setProperty(CFG_FILE_PROP, prop); System.setProperty(CFG_FILE_PROP, prop);
LogManager logMgr = LogManager.getLogManager(); LogManager.getLogManager();
// create a logger // create a logger
logger = Logger.getLogger(MemoryHandlerTest.class.getName()); logger = Logger.getLogger(MemoryHandlerTest.class.getName());
// don't have parent handlers get log messages // 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 * @test
* @bug 6498300 * @bug 6498300
...@@ -86,12 +109,12 @@ public class ParentLoggersTest { ...@@ -86,12 +109,12 @@ public class ParentLoggersTest {
Vector<String> expectedLoggerNames = new Vector<String>(getDefaultLoggerNames()); Vector<String> expectedLoggerNames = new Vector<String>(getDefaultLoggerNames());
// Create the logger LOGGER_NAME_1 // 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(PARENT_NAME_1);
expectedLoggerNames.addElement(LOGGER_NAME_1); expectedLoggerNames.addElement(LOGGER_NAME_1);
// Create the logger LOGGER_NAME_2 // 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(PARENT_NAME_2);
expectedLoggerNames.addElement(LOGGER_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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -92,8 +92,9 @@ public class SimpleFormatterFormat { ...@@ -92,8 +92,9 @@ public class SimpleFormatterFormat {
System.out.println("Checking log records in file: " + log); System.out.println("Checking log records in file: " + log);
Pattern p = Pattern.compile("([\\.a-zA-Z:]+) (.*) \\[.*\\] source: (.*)"); Pattern p = Pattern.compile("([\\.a-zA-Z:]+) (.*) \\[.*\\] source: (.*)");
try (FileInputStream in = new FileInputStream(log)) { try (FileInputStream in = new FileInputStream(log);
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); BufferedReader reader = new BufferedReader(new InputStreamReader(in));
) {
String line; String line;
int i = 0; int i = 0;
while (i < messages.length && while (i < messages.length &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册