changeset 3294:d1015b6cf7f4

Fix: javap generates spurious errors due to bogus descriptor parsing logic
author mcimadamore
date Tue, 26 Jan 2016 13:59:03 +0000
parents 34140d95412b
children ade1263cab01
files src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantPool.java src/jdk.jdeps/share/classes/com/sun/tools/classfile/Descriptor.java
diffstat 2 files changed, 34 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantPool.java	Mon Jan 25 18:36:44 2016 +0000
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantPool.java	Tue Jan 26 13:59:03 2016 +0000
@@ -1248,7 +1248,11 @@
         }
 
         @Override
-        public String visitParameterizedType(CONSTANT_ParameterizedType_info info, ConstantPool pool) {
+        public String visitParameterizedType(CONSTANT_ParameterizedType_info info, ConstantPool constantPool) {
+            return visitParameterizedTypeInternal(info, constantPool, ",");
+        }
+
+        public String visitParameterizedTypeInternal(CONSTANT_ParameterizedType_info info, ConstantPool pool, String sep) {
             try {
                 String base = pool.getUTF8Value(info.clazz_idx);
                 String args = IntStream.of(info.params_idxs)
@@ -1258,7 +1262,7 @@
                                     } catch (Throwable ex) {
                                         throw new AssertionError(ex.getMessage());
                                     }})
-                        .collect(Collectors.joining(",", "<", ">"));
+                        .collect(Collectors.joining(sep, "<", ">"));
                 return base + args;
             } catch (Throwable ex) {
                 throw new AssertionError(ex.getMessage());
@@ -1298,7 +1302,7 @@
     private static final Visitor<String, ConstantPool> typeVisitor = new NameVisitor() {
         @Override
         public String visitParameterizedType(CONSTANT_ParameterizedType_info info, ConstantPool pool) {
-            return info.basicType + super.visitParameterizedType(info, pool) + ";";
+            return Character.valueOf((char)info.basicType) + super.visitParameterizedTypeInternal(info, pool, "") + ";";
         }
 
         @Override
--- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Descriptor.java	Mon Jan 25 18:36:44 2016 +0000
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Descriptor.java	Tue Jan 26 13:59:03 2016 +0000
@@ -130,6 +130,18 @@
                     sb.append(')');
                     continue;
 
+                case '>':
+                    sb.append('>');
+                    //expect a ';'
+                    if (desc.charAt(p++) != ';') {
+                        new InvalidDescriptor(desc, p - 1);
+                    }
+                    continue;
+
+                case '<':
+                    sb.append('<');
+                    continue;
+
                 case '[':
                     dims++;
                     continue;
@@ -161,11 +173,23 @@
                 case 'T':
                 case 'L':
                 case 'Q':
-                    int sep = desc.indexOf(';', p);
+                    boolean generics = false;
+                    int sep = desc.indexOf('<', p);
+                    if (sep == -1) {
+                        sep = desc.indexOf(';', p);
+                    } else {
+                        generics = true;
+                    }
                     if (sep == -1)
                         throw new InvalidDescriptor(desc, p - 1);
-                    type = desc.substring(p, sep).replace('/', '.');
-                    p = sep + 1;
+                    if (!generics) {
+                        type = desc.substring(p, sep).replace('/', '.');
+                        p = sep + 1;
+                    } else {
+                        sb.append(desc.substring(p, sep));
+                        p = sep;
+                        continue;
+                    }
                     break;
 
                 case 'S':