Tue, 02 Jul 2013 10:21:41 +0100
8019397: javap does not show SourceDebugExtension properly
Reviewed-by: jjg
Contributed-by: dmytro_sheyko@hotmail.com
1.1 --- a/src/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java Mon Jul 01 11:58:45 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java Tue Jul 02 10:21:41 2013 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2007, 2013, 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 @@ -28,6 +28,7 @@ 1.11 import java.io.ByteArrayInputStream; 1.12 import java.io.DataInputStream; 1.13 import java.io.IOException; 1.14 +import java.nio.charset.Charset; 1.15 1.16 /** 1.17 * See JVMS, section 4.8.15. 1.18 @@ -38,6 +39,8 @@ 1.19 * deletion without notice.</b> 1.20 */ 1.21 public class SourceDebugExtension_attribute extends Attribute { 1.22 + private static final Charset UTF8 = Charset.forName("UTF-8"); 1.23 + 1.24 SourceDebugExtension_attribute(ClassReader cr, int name_index, int length) throws IOException { 1.25 super(name_index, length); 1.26 debug_extension = new byte[attribute_length]; 1.27 @@ -55,12 +58,7 @@ 1.28 } 1.29 1.30 public String getValue() { 1.31 - DataInputStream d = new DataInputStream(new ByteArrayInputStream(debug_extension)); 1.32 - try { 1.33 - return d.readUTF(); 1.34 - } catch (IOException e) { 1.35 - return null; 1.36 - } 1.37 + return new String(debug_extension, UTF8); 1.38 } 1.39 1.40 public <R, D> R accept(Visitor<R, D> visitor, D data) {
2.1 --- a/src/share/classes/com/sun/tools/javap/AttributeWriter.java Mon Jul 01 11:58:45 2013 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java Tue Jul 02 10:21:41 2013 +0100 2.3 @@ -513,7 +513,12 @@ 2.4 } 2.5 2.6 public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, Void ignore) { 2.7 - println("SourceDebugExtension: " + attr.getValue()); 2.8 + println("SourceDebugExtension:"); 2.9 + indent(+1); 2.10 + for (String s: attr.getValue().split("[\r\n]+")) { 2.11 + println(s); 2.12 + } 2.13 + indent(-1); 2.14 return null; 2.15 } 2.16