[PATCH] 8036827: Incorrect printing of the generic method declaration

B. Blaser bsrbnd at gmail.com
Sat Jan 28 18:26:10 UTC 2017


Jonathan,

2017-01-27 23:05 GMT+01:00 B. Blaser <bsrbnd at gmail.com>:
> Thanks for your answer.
> It seems reasonable to print it and compliant with the comments you
> provided in JDK 7031005.
>
> I think there's probably a slight inconsistency similar to JDK
> 7031005, but for classes.
> With -verbose, we have:
>
> 1) Info from super_class:
>
> $ more JDK_8036827.java
> class JDK_8036827 {}
>
> $ javap -v JDK_8036827.class
>   Compiled from "JDK_8036827.java"
> class JDK_8036827
>
> 2) Info from class signature:
>
> $ more JDK_8036827.java
> class JDK_8036827<T> {}
>
> $ javap -v JDK_8036827.class
>   Compiled from "JDK_8036827.java"
> class JDK_8036827<T extends java.lang.Object> extends java.lang.Object
>
> What's the correct expectation?
>
> Should "extends java.lang.Object" be present in the first example as
> this information is present in the class file?

If so, I suggest the following fix along with the associate test
updated to check the -verbose behavior.

Bernard

diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java
b/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2017, 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
@@ -205,7 +205,7 @@
             // use info from class file header
             if (classFile.isClass() && classFile.super_class != 0 ) {
                 String sn = getJavaSuperclassName(cf);
-                if (!sn.equals("java.lang.Object")) {
+                if (options.verbose || !sn.equals("java.lang.Object")) {
                     print(" extends ");
                     print(sn);
                 }
diff --git a/test/tools/javap/TestSuperclass.java
b/test/tools/javap/TestSuperclass.java
--- a/test/tools/javap/TestSuperclass.java
+++ b/test/tools/javap/TestSuperclass.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -53,12 +53,14 @@
     }

     enum GenericKind {
-        NO(""),
-        YES("<T>");
-        GenericKind(String typarams) {
+        NO("", ""),
+        YES("<T>", "<T extends java.lang.Object>");
+        GenericKind(String typarams, String verbose) {
             this.typarams = typarams;
+            this.verbose = verbose;
         }
         final String typarams;
+        final String verbose;
     }

     enum SuperKind {
@@ -73,6 +75,9 @@
         String decl(ClassKind ck) {
             return (name == null) ? "" : ck.keyword + " " + name + " { }";
         }
+        String verbose(ClassKind ck) {
+            return ck == ClassKind.CLASS && name == null ? "extends
java.lang.Object" : extend();
+        }
         final String name;
     }

@@ -117,28 +122,41 @@
             throw new Error("compilation failed");

         File testClass = new File(testDir, "Test.class");
-        String out = javap(testClass);
+
+        System.err.print("normal: ");
+        String out = javap(testClass.getPath());

         // Extract class sig from first line of Java source
         String expect = js.source.replaceAll("(?s)^(.* Test[^{]+?)
*\\{.*", "$1");

         // Extract class sig from line from javap output
         String found = out.replaceAll("(?s).*\n(.* Test[^{]+?) *\\{.*", "$1");
+        System.err.println(found);

         checkEqual("class signature", expect, found);

+        System.err.print("verbose: ");
+        out = javap("-v", testClass.getPath());
+
+        String verbose = ck.keyword + " Test" + gk.verbose +
+                (sk.verbose(ck).isEmpty() ? "" : " " + sk.verbose(ck));
+
+        if (out.contains(verbose))
+            System.err.println(verbose);
+        else
+            checkEqual("class signature", verbose, out);
+
+        System.err.println();
+
         return errors;
     }

-    String javap(File file) {
+    String javap(String... args) {
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
-        String[] args = { file.getPath() };
         int rc = com.sun.tools.javap.Main.run(args, pw);
         pw.close();
         String out = sw.toString();
-        if (!out.isEmpty())
-            System.err.println(out);
         if (rc != 0)
             throw new Error("javap failed: rc=" + rc);
         return out;


> 2017-01-26 22:24 GMT+01:00 Jonathan Gibbons <jonathan.gibbons at oracle.com>:
>> Bernard,
>>
>> I don't think this should be changed, and I will close out the JBS issue.
>>
>> Without the -verbose flag, the "extends java.lang.Object" is not printed.
>>
>> $ ./build/linux-x86_64-normal-server-release/images/jdk/bin/javap
>> play/src/JDK_8036827.class
>> Compiled from "JDK_8036827.java"
>> class JDK_8036827 {
>>   JDK_8036827();
>>   public <T> T m1(T);
>> }
>>
>> When the -verbose flag is used, it does not seem unreasonable to print out
>> information which is explicitly present in the class file.
>>
>> -- Jon


More information about the compiler-dev mailing list