Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8019397

javap does not show SourceDebugExtension properly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 8
    • tools
    • b98
    • Not verified

    Description

      Taken from a compiler-dev message by dmytro_sheyko at hotmail.com

      Hello,

      I was trying to get SourceDebugExtension for compiled jsp class using javap (1.7.0_25, 1.8.0-ea-b91) and it printed something like:

        SourceFile: "x_jsp.java"
        SourceDebugExtension: null
        minor version: 0
        major version: 50

      where expected output is following:

        SourceFile: "x_jsp.java"
        SourceDebugExtension:
          SMAP
          x_jsp.java
          JSP
          *S JSP
          *F
          + 0 x.jsp
          x.jsp
          *L
          1,3:62
          4:65,4
          6,4:70
          9,4:74
          *E
        minor version: 0
        major version: 50

      Getting SourceDebugExtension using JDI works well (i.e. class file is correct).

      And I would like to propose a patch to fix this issue. Please review.

      diff -r b3458329d060 src/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java
      --- a/src/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java Mon Jun 24 14:27:32 2013 -0700
      +++ b/src/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java Tue Jun 25 20:22:06 2013 +0300
      @@ -25,9 +25,8 @@
       
       package com.sun.tools.classfile;
       
      -import java.io.ByteArrayInputStream;
      -import java.io.DataInputStream;
       import java.io.IOException;
      +import java.nio.charset.Charset;
       
       /**
        * See JVMS, section 4.8.15.
      @@ -38,6 +37,8 @@
        * deletion without notice.</b>
        */
       public class SourceDebugExtension_attribute extends Attribute {
      + private static final Charset UTF8 = Charset.forName("UTF-8");
      +
           SourceDebugExtension_attribute(ClassReader cr, int name_index, int length) throws IOException {
               super(name_index, length);
               debug_extension = new byte[attribute_length];
      @@ -55,12 +56,7 @@
           }
       
           public String getValue() {
      - DataInputStream d = new DataInputStream(new ByteArrayInputStream(debug_extension));
      - try {
      - return d.readUTF();
      - } catch (IOException e) {
      - return null;
      - }
      + return new String(debug_extension, UTF8);
           }
       
           public <R, D> R accept(Visitor<R, D> visitor, D data) {
      diff -r b3458329d060 src/share/classes/com/sun/tools/javap/AttributeWriter.java
      --- a/src/share/classes/com/sun/tools/javap/AttributeWriter.java Mon Jun 24 14:27:32 2013 -0700
      +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java Tue Jun 25 20:22:06 2013 +0300
      @@ -511,7 +511,10 @@
           }
       
           public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, Void ignore) {
      - println("SourceDebugExtension: " + attr.getValue());
      + println("SourceDebugExtension:");
      + indent(+1);
      + print(attr.getValue());
      + indent(-1);
               return null;
           }

      Attachments

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              vromero Vicente Arturo Romero Zaldivar
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: