Wed, 18 Jun 2008 16:53:08 -0700
6715767: javap on java.lang.ClassLoader crashes
Reviewed-by: ksrini
1.1 --- a/src/share/classes/com/sun/tools/classfile/ConstantPool.java Mon Jun 16 22:23:33 2008 -0700 1.2 +++ b/src/share/classes/com/sun/tools/classfile/ConstantPool.java Wed Jun 18 16:53:08 2008 -0700 1.3 @@ -153,7 +153,7 @@ 1.4 break; 1.5 1.6 case CONSTANT_String: 1.7 - pool[i] = new CONSTANT_String_info(cr); 1.8 + pool[i] = new CONSTANT_String_info(this, cr); 1.9 break; 1.10 1.11 case CONSTANT_Utf8: 1.12 @@ -509,7 +509,8 @@ 1.13 } 1.14 1.15 public static class CONSTANT_String_info extends CPInfo { 1.16 - CONSTANT_String_info(ClassReader cr) throws IOException { 1.17 + CONSTANT_String_info(ConstantPool cp, ClassReader cr) throws IOException { 1.18 + super(cp); 1.19 string_index = cr.readUnsignedShort(); 1.20 } 1.21
2.1 --- a/src/share/classes/com/sun/tools/javap/AttributeWriter.java Mon Jun 16 22:23:33 2008 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java Wed Jun 18 16:53:08 2008 -0700 2.3 @@ -259,7 +259,7 @@ 2.4 return null; 2.5 } 2.6 2.7 - String getJavaException(Exceptions_attribute attr, int index) { 2.8 + private String getJavaException(Exceptions_attribute attr, int index) { 2.9 try { 2.10 return getJavaName(attr.getException(index, constant_pool)); 2.11 } catch (ConstantPoolException e) {
3.1 --- a/src/share/classes/com/sun/tools/javap/ClassWriter.java Mon Jun 16 22:23:33 2008 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javap/ClassWriter.java Wed Jun 18 16:53:08 2008 -0700 3.3 @@ -291,7 +291,7 @@ 3.4 for (int i = 0; i < exceptions.number_of_exceptions; i++) { 3.5 if (i > 0) 3.6 print(", "); 3.7 - print(attrWriter.getJavaException(exceptions, i)); 3.8 + print(getJavaException(exceptions, i)); 3.9 } 3.10 } 3.11 } else { 3.12 @@ -441,6 +441,14 @@ 3.13 } 3.14 } 3.15 3.16 + String getJavaException(Exceptions_attribute attr, int index) { 3.17 + try { 3.18 + return getJavaName(attr.getException(index, constant_pool)); 3.19 + } catch (ConstantPoolException e) { 3.20 + return report(e); 3.21 + } 3.22 + } 3.23 + 3.24 String getValue(Descriptor d) { 3.25 try { 3.26 return d.getValue(constant_pool);
4.1 --- a/src/share/classes/com/sun/tools/javap/JavapTask.java Mon Jun 16 22:23:33 2008 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javap/JavapTask.java Wed Jun 18 16:53:08 2008 -0700 4.3 @@ -475,6 +475,7 @@ 4.4 t.printStackTrace(pw); 4.5 pw.close(); 4.6 diagnosticListener.report(createDiagnostic("err.crash", t.toString(), sw.toString())); 4.7 + ok = false; 4.8 } 4.9 } 4.10
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javap/T6715767.java Wed Jun 18 16:53:08 2008 -0700 5.3 @@ -0,0 +1,50 @@ 5.4 +/* 5.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 5.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 5.24 + * have any questions. 5.25 + */ 5.26 + 5.27 +/* 5.28 + * @test 5.29 + * @bug 6715767 5.30 + * @summary javap on java.lang.ClassLoader crashes 5.31 + */ 5.32 + 5.33 +import java.io.*; 5.34 + 5.35 +public class T6715767 { 5.36 + public static void main(String... args) throws Exception { 5.37 + new T6715767().run(); 5.38 + } 5.39 + 5.40 + void run() throws Exception { 5.41 + StringWriter sw = new StringWriter(); 5.42 + PrintWriter pw = new PrintWriter(sw); 5.43 + String[] args = { "java.lang.ClassLoader" }; 5.44 + int rc = com.sun.tools.javap.Main.run(args, pw); 5.45 + if (rc != 0 || 5.46 + sw.toString().indexOf("at com.sun.tools.javap.JavapTask.run") != -1) { 5.47 + System.err.println("rc: " + rc); 5.48 + System.err.println("log:\n" + sw); 5.49 + throw new Exception("unexpected result"); 5.50 + } 5.51 + } 5.52 +} 5.53 +