Fri, 07 Sep 2012 11:12:16 -0700
7186925: JavapTask passes null to java.io.Writer
Reviewed-by: jjh
src/share/classes/com/sun/tools/javap/JavapTask.java | file | annotate | diff | comparison | revisions | |
test/tools/javap/T7186925.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javap/JavapTask.java Wed Sep 05 12:00:30 2012 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javap/JavapTask.java Fri Sep 07 11:12:16 2012 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -374,8 +374,8 @@ 1.11 task_locale = locale; 1.12 } 1.13 1.14 - public void setLog(PrintWriter log) { 1.15 - this.log = log; 1.16 + public void setLog(Writer log) { 1.17 + this.log = getPrintWriterForWriter(log); 1.18 } 1.19 1.20 public void setLog(OutputStream s) { 1.21 @@ -383,7 +383,7 @@ 1.22 } 1.23 1.24 private static PrintWriter getPrintWriterForStream(OutputStream s) { 1.25 - return new PrintWriter(s, true); 1.26 + return new PrintWriter(s == null ? System.err : s, true); 1.27 } 1.28 1.29 private static PrintWriter getPrintWriterForWriter(Writer w) {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javap/T7186925.java Fri Sep 07 11:12:16 2012 -0700 2.3 @@ -0,0 +1,78 @@ 2.4 +/* 2.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 7186925 2.30 + * @summary JavapTask passes null to java.io.Writer 2.31 + */ 2.32 + 2.33 +import java.io.*; 2.34 +import java.util.*; 2.35 +import javax.tools.*; 2.36 +import com.sun.tools.javap.*; 2.37 + 2.38 +public class T7186925 2.39 +{ 2.40 + public static void main(String... args) { 2.41 + new T7186925().run(); 2.42 + } 2.43 + 2.44 + void run() { 2.45 + verify("java.lang.Object"); 2.46 + if (errors > 0) 2.47 + throw new Error(errors + " found."); 2.48 + } 2.49 + 2.50 + void verify(String className) { 2.51 + try { 2.52 + JavaFileManager fileManager = JavapFileManager.create(null, null); 2.53 + JavaFileObject fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS); 2.54 + if (fo == null) { 2.55 + error("Can't find " + className); 2.56 + } else { 2.57 + JavapTask t = new JavapTask(null, fileManager, null); 2.58 + t.handleOptions(new String[] { "-sysinfo", className }); 2.59 + JavapTask.ClassFileInfo cfInfo = t.read(fo); 2.60 + expectEqual(cfInfo.cf.byteLength(), cfInfo.size); 2.61 + } 2.62 + } catch (NullPointerException ee) { 2.63 + ee.printStackTrace(); 2.64 + error("Exception: " + ee); 2.65 + } catch (Exception ee) { 2.66 + System.err.println("Caught exception: " + ee); 2.67 + } 2.68 + } 2.69 + 2.70 + void expectEqual(int found, int expected) { 2.71 + if (found != expected) 2.72 + error("bad value found: " + found + " expected: " + expected); 2.73 + } 2.74 + 2.75 + void error(String msg) { 2.76 + System.err.println(msg); 2.77 + errors++; 2.78 + } 2.79 + 2.80 + int errors; 2.81 +}