mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 19:14:38 +02:00
6983646: javap should identify why a DefaultAttribute is being used
Reviewed-by: jjg
This commit is contained in:
parent
c5e36903f7
commit
a33129c6af
3 changed files with 26 additions and 3 deletions
|
@ -77,10 +77,12 @@ public abstract class Attribute {
|
||||||
|
|
||||||
public Attribute createAttribute(ClassReader cr, int name_index, byte[] data)
|
public Attribute createAttribute(ClassReader cr, int name_index, byte[] data)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (standardAttributes == null)
|
if (standardAttributes == null) {
|
||||||
init();
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
ConstantPool cp = cr.getConstantPool();
|
ConstantPool cp = cr.getConstantPool();
|
||||||
|
String reasonForDefaultAttr;
|
||||||
try {
|
try {
|
||||||
String name = cp.getUTF8Value(name_index);
|
String name = cp.getUTF8Value(name_index);
|
||||||
Class<? extends Attribute> attrClass = standardAttributes.get(name);
|
Class<? extends Attribute> attrClass = standardAttributes.get(name);
|
||||||
|
@ -90,14 +92,18 @@ public abstract class Attribute {
|
||||||
Constructor<? extends Attribute> constr = attrClass.getDeclaredConstructor(constrArgTypes);
|
Constructor<? extends Attribute> constr = attrClass.getDeclaredConstructor(constrArgTypes);
|
||||||
return constr.newInstance(new Object[] { cr, name_index, data.length });
|
return constr.newInstance(new Object[] { cr, name_index, data.length });
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
reasonForDefaultAttr = t.toString();
|
||||||
// fall through and use DefaultAttribute
|
// fall through and use DefaultAttribute
|
||||||
// t.printStackTrace();
|
// t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
reasonForDefaultAttr = "unknown attribute";
|
||||||
}
|
}
|
||||||
} catch (ConstantPoolException e) {
|
} catch (ConstantPoolException e) {
|
||||||
|
reasonForDefaultAttr = e.toString();
|
||||||
// fall through and use DefaultAttribute
|
// fall through and use DefaultAttribute
|
||||||
}
|
}
|
||||||
return new DefaultAttribute(cr, name_index, data);
|
return new DefaultAttribute(cr, name_index, data, reasonForDefaultAttr);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init() {
|
protected void init() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -33,13 +33,24 @@ package com.sun.tools.classfile;
|
||||||
*/
|
*/
|
||||||
public class DefaultAttribute extends Attribute {
|
public class DefaultAttribute extends Attribute {
|
||||||
DefaultAttribute(ClassReader cr, int name_index, byte[] data) {
|
DefaultAttribute(ClassReader cr, int name_index, byte[] data) {
|
||||||
|
this(cr, name_index, data, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
DefaultAttribute(ClassReader cr, int name_index, byte[] data, String reason) {
|
||||||
super(name_index, data.length);
|
super(name_index, data.length);
|
||||||
info = data;
|
info = data;
|
||||||
|
this.reason = reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultAttribute(ConstantPool constant_pool, int name_index, byte[] info) {
|
public DefaultAttribute(ConstantPool constant_pool, int name_index, byte[] info) {
|
||||||
|
this(constant_pool, name_index, info, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultAttribute(ConstantPool constant_pool, int name_index,
|
||||||
|
byte[] info, String reason) {
|
||||||
super(name_index, info.length);
|
super(name_index, info.length);
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
this.reason = reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <R, P> R accept(Visitor<R, P> visitor, P p) {
|
public <R, P> R accept(Visitor<R, P> visitor, P p) {
|
||||||
|
@ -47,4 +58,7 @@ public class DefaultAttribute extends Attribute {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final byte[] info;
|
public final byte[] info;
|
||||||
|
/** Why did we need to generate a DefaultAttribute
|
||||||
|
*/
|
||||||
|
public final String reason;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,9 @@ public class AttributeWriter extends BasicWriter
|
||||||
}
|
}
|
||||||
|
|
||||||
public Void visitDefault(DefaultAttribute attr, Void ignore) {
|
public Void visitDefault(DefaultAttribute attr, Void ignore) {
|
||||||
|
if (attr.reason != null) {
|
||||||
|
report(attr.reason);
|
||||||
|
}
|
||||||
byte[] data = attr.info;
|
byte[] data = attr.info;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue