6983646: javap should identify why a DefaultAttribute is being used

Sat, 29 Jun 2013 20:12:24 +0100

author
vromero
date
Sat, 29 Jun 2013 20:12:24 +0100
changeset 1874
891c5ecb8306
parent 1873
66147d50d8d6
child 1875
f559ef7568ce

6983646: javap should identify why a DefaultAttribute is being used
Reviewed-by: jjg

src/share/classes/com/sun/tools/classfile/Attribute.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/classfile/DefaultAttribute.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javap/AttributeWriter.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/classfile/Attribute.java	Fri Jun 28 19:47:54 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/classfile/Attribute.java	Sat Jun 29 20:12:24 2013 +0100
     1.3 @@ -77,10 +77,12 @@
     1.4  
     1.5          public Attribute createAttribute(ClassReader cr, int name_index, byte[] data)
     1.6                  throws IOException {
     1.7 -            if (standardAttributes == null)
     1.8 +            if (standardAttributes == null) {
     1.9                  init();
    1.10 +            }
    1.11  
    1.12              ConstantPool cp = cr.getConstantPool();
    1.13 +            String reasonForDefaultAttr;
    1.14              try {
    1.15                  String name = cp.getUTF8Value(name_index);
    1.16                  Class<? extends Attribute> attrClass = standardAttributes.get(name);
    1.17 @@ -90,14 +92,18 @@
    1.18                          Constructor<? extends Attribute> constr = attrClass.getDeclaredConstructor(constrArgTypes);
    1.19                          return constr.newInstance(new Object[] { cr, name_index, data.length });
    1.20                      } catch (Throwable t) {
    1.21 +                        reasonForDefaultAttr = t.toString();
    1.22                          // fall through and use DefaultAttribute
    1.23                          // t.printStackTrace();
    1.24                      }
    1.25 +                } else {
    1.26 +                    reasonForDefaultAttr = "unknown attribute";
    1.27                  }
    1.28              } catch (ConstantPoolException e) {
    1.29 +                reasonForDefaultAttr = e.toString();
    1.30                  // fall through and use DefaultAttribute
    1.31              }
    1.32 -            return new DefaultAttribute(cr, name_index, data);
    1.33 +            return new DefaultAttribute(cr, name_index, data, reasonForDefaultAttr);
    1.34          }
    1.35  
    1.36          protected void init() {
     2.1 --- a/src/share/classes/com/sun/tools/classfile/DefaultAttribute.java	Fri Jun 28 19:47:54 2013 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/classfile/DefaultAttribute.java	Sat Jun 29 20:12:24 2013 +0100
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -33,13 +33,24 @@
    2.11   */
    2.12  public class DefaultAttribute extends Attribute {
    2.13      DefaultAttribute(ClassReader cr, int name_index, byte[] data) {
    2.14 +        this(cr, name_index, data, null);
    2.15 +    }
    2.16 +
    2.17 +    DefaultAttribute(ClassReader cr, int name_index, byte[] data, String reason) {
    2.18          super(name_index, data.length);
    2.19          info = data;
    2.20 +        this.reason = reason;
    2.21      }
    2.22  
    2.23      public DefaultAttribute(ConstantPool constant_pool, int name_index, byte[] info) {
    2.24 +        this(constant_pool, name_index, info, null);
    2.25 +    }
    2.26 +
    2.27 +    public DefaultAttribute(ConstantPool constant_pool, int name_index,
    2.28 +            byte[] info, String reason) {
    2.29          super(name_index, info.length);
    2.30          this.info = info;
    2.31 +        this.reason = reason;
    2.32      }
    2.33  
    2.34      public <R, P> R accept(Visitor<R, P> visitor, P p) {
    2.35 @@ -47,4 +58,7 @@
    2.36      }
    2.37  
    2.38      public final byte[] info;
    2.39 +    /** Why did we need to generate a DefaultAttribute
    2.40 +     */
    2.41 +    public final String reason;
    2.42  }
     3.1 --- a/src/share/classes/com/sun/tools/javap/AttributeWriter.java	Fri Jun 28 19:47:54 2013 -0700
     3.2 +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java	Sat Jun 29 20:12:24 2013 +0100
     3.3 @@ -114,6 +114,9 @@
     3.4      }
     3.5  
     3.6      public Void visitDefault(DefaultAttribute attr, Void ignore) {
     3.7 +        if (attr.reason != null) {
     3.8 +            report(attr.reason);
     3.9 +        }
    3.10          byte[] data = attr.info;
    3.11          int i = 0;
    3.12          int j = 0;

mercurial