From 63976323301e4a3f904b2777798444cc20e6928e Mon Sep 17 00:00:00 2001 From: jgish Date: Thu, 29 Nov 2012 12:28:02 +0000 Subject: [PATCH] 8003380: Compiler warnings in logging test code Summary: Use generics, suppress warnings where appropriate, remove unused imports, etc. Reviewed-by: lancea, chegar --- .../util/logging/ClassLoaderLeakTest.java | 12 ++++----- test/java/util/logging/Listeners.java | 1 + test/java/util/logging/ListenersWithSM.java | 1 + .../logging/LoggerResourceBundleRace.java | 7 +++-- test/java/util/logging/LoggingDeadlock2.java | 5 ++-- test/java/util/logging/LoggingDeadlock3.java | 4 +-- test/java/util/logging/LoggingDeadlock4.java | 5 ++-- test/java/util/logging/LoggingMXBeanTest.java | 6 ++--- .../java/util/logging/LoggingMXBeanTest2.java | 9 +++---- test/java/util/logging/MemoryHandlerTest.java | 2 +- test/java/util/logging/ParentLoggersTest.java | 27 +++++++++++++++++-- .../util/logging/SimpleFormatterFormat.java | 7 ++--- 12 files changed, 53 insertions(+), 33 deletions(-) diff --git a/test/java/util/logging/ClassLoaderLeakTest.java b/test/java/util/logging/ClassLoaderLeakTest.java index a1c56fa6a..f2957dba7 100644 --- a/test/java/util/logging/ClassLoaderLeakTest.java +++ b/test/java/util/logging/ClassLoaderLeakTest.java @@ -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.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); } diff --git a/test/java/util/logging/Listeners.java b/test/java/util/logging/Listeners.java index 265fdced5..86383ef06 100644 --- a/test/java/util/logging/Listeners.java +++ b/test/java/util/logging/Listeners.java @@ -88,6 +88,7 @@ public class Listeners { } } + @SuppressWarnings("deprecation") public static void main(String[] args) throws Exception { LogManager logman = LogManager.getLogManager(); diff --git a/test/java/util/logging/ListenersWithSM.java b/test/java/util/logging/ListenersWithSM.java index 41af3299b..49eba235d 100644 --- a/test/java/util/logging/ListenersWithSM.java +++ b/test/java/util/logging/ListenersWithSM.java @@ -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"); diff --git a/test/java/util/logging/LoggerResourceBundleRace.java b/test/java/util/logging/LoggerResourceBundleRace.java index c7976d7cc..e159a2dde 100644 --- a/test/java/util/logging/LoggerResourceBundleRace.java +++ b/test/java/util/logging/LoggerResourceBundleRace.java @@ -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.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 { diff --git a/test/java/util/logging/LoggingDeadlock2.java b/test/java/util/logging/LoggingDeadlock2.java index 611ec2ae8..8c83ae90c 100644 --- a/test/java/util/logging/LoggingDeadlock2.java +++ b/test/java/util/logging/LoggingDeadlock2.java @@ -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 @@ 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(); diff --git a/test/java/util/logging/LoggingDeadlock3.java b/test/java/util/logging/LoggingDeadlock3.java index 1b94d0316..73162d58b 100644 --- a/test/java/util/logging/LoggingDeadlock3.java +++ b/test/java/util/logging/LoggingDeadlock3.java @@ -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 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(); } diff --git a/test/java/util/logging/LoggingDeadlock4.java b/test/java/util/logging/LoggingDeadlock4.java index f52d74b12..65846979f 100644 --- a/test/java/util/logging/LoggingDeadlock4.java +++ b/test/java/util/logging/LoggingDeadlock4.java @@ -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(); diff --git a/test/java/util/logging/LoggingMXBeanTest.java b/test/java/util/logging/LoggingMXBeanTest.java index a01e57c13..a023aeeb0 100644 --- a/test/java/util/logging/LoggingMXBeanTest.java +++ b/test/java/util/logging/LoggingMXBeanTest.java @@ -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(); } } diff --git a/test/java/util/logging/LoggingMXBeanTest2.java b/test/java/util/logging/LoggingMXBeanTest2.java index 005ed72e0..3791e80b2 100644 --- a/test/java/util/logging/LoggingMXBeanTest2.java +++ b/test/java/util/logging/LoggingMXBeanTest2.java @@ -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 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 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(); } } diff --git a/test/java/util/logging/MemoryHandlerTest.java b/test/java/util/logging/MemoryHandlerTest.java index 026e57185..ee80ef786 100644 --- a/test/java/util/logging/MemoryHandlerTest.java +++ b/test/java/util/logging/MemoryHandlerTest.java @@ -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 diff --git a/test/java/util/logging/ParentLoggersTest.java b/test/java/util/logging/ParentLoggersTest.java index 3dc4bfcc2..72d5ddadc 100644 --- a/test/java/util/logging/ParentLoggersTest.java +++ b/test/java/util/logging/ParentLoggersTest.java @@ -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 @@ public class ParentLoggersTest { Vector expectedLoggerNames = new Vector(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); diff --git a/test/java/util/logging/SimpleFormatterFormat.java b/test/java/util/logging/SimpleFormatterFormat.java index fc786a0f0..4fafba3b7 100644 --- a/test/java/util/logging/SimpleFormatterFormat.java +++ b/test/java/util/logging/SimpleFormatterFormat.java @@ -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 @@ 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 && -- GitLab