enver 2003/12/18 09:22:58
Modified: src/java/org/apache/bcel/verifier/statics Pass1Verifier.java
Pass2Verifier.java StringRepresentation.java
Log:
Reflect the fact that BCEL throws ClassFormatException rather than
ClassFormatError in exceptional situations; so catch the Exc, and
no longer the Err in the verifier part [save JustIce from bit rot :) ].
Revision Changes Path
1.4 +2 -3 jakarta-bcel/src/java/org/apache/bcel/verifier/statics/Pass1Verifier.java
Index: Pass1Verifier.java
===================================================================
RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/verifier/statics/Pass1Verifier.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Pass1Verifier.java 23 May 2003 07:55:34 -0000 1.3
+++ Pass1Verifier.java 18 Dec 2003 17:22:58 -0000 1.4
@@ -182,8 +182,7 @@
catch(LoadingException e){
return new VerificationResult(VerificationResult.VERIFIED_REJECTED, e.getMessage());
}
- catch(ClassFormatError e){
- // BCEL sometimes is a little harsh describing exceptual situations.
+ catch(ClassFormatException e){
return new VerificationResult(VerificationResult.VERIFIED_REJECTED, e.getMessage());
}
catch(RuntimeException e){
1.4 +9 -13 jakarta-bcel/src/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
Index: Pass2Verifier.java
===================================================================
RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/verifier/statics/Pass2Verifier.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Pass2Verifier.java 23 May 2003 07:55:34 -0000 1.3
+++ Pass2Verifier.java 18 Dec 2003 17:22:58 -0000 1.4
@@ -525,8 +525,8 @@
try{
Type.getType(sig); /* Don't need the return value */
}
- catch (ClassFormatError cfe){ // sometimes BCEL is a little harsh describing exceptional situations.
- throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
+ catch (ClassFormatException cfe){
+ throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
}
String nameanddesc = (name+sig);
@@ -574,9 +574,8 @@
t = Type.getReturnType(sig);
ts = Type.getArgumentTypes(sig);
}
- catch (ClassFormatError cfe){
- // Well, BCEL sometimes is a little harsh describing exceptional situations.
- throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by Method '"+tostring(obj)+"'.");
+ catch (ClassFormatException cfe){
+ throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by Method '"+tostring(obj)+"'.");
}
// Check if referenced objects exist.
@@ -948,7 +947,7 @@
try{
t = Type.getType(localsig);
}
- catch (ClassFormatError cfe){ // sometimes BCEL is a little harsh describing exceptional situations.
+ catch (ClassFormatException cfe){
throw new ClassConstraintException("Illegal descriptor (==signature) '"+localsig+"' used by LocalVariable '"+tostring(localvariables[i])+"' referenced by '"+tostring(lvt)+"'.");
}
int localindex = localvariables[i].getIndex();
@@ -1159,8 +1158,7 @@
try{
Type.getType(sig); /* Don't need the return value */
}
- catch (ClassFormatError cfe){
- // Well, BCEL sometimes is a little harsh describing exceptional situations.
+ catch (ClassFormatException cfe){
throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
}
}
@@ -1191,8 +1189,7 @@
throw new ClassConstraintException("Instance initialization method must have VOID return type.");
}
}
- catch (ClassFormatError cfe){
- // Well, BCEL sometimes is a little harsh describing exceptional situations.
+ catch (ClassFormatException cfe){
throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
}
}
@@ -1223,8 +1220,7 @@
addMessage("Class or interface initialization method '"+STATIC_INITIALIZER_NAME+"' usually has VOID return type instead of '"+t+"'. Note this is really not a requirement of The Java Virtual Machine Specification, Second Edition.");
}
}
- catch (ClassFormatError cfe){
- // Well, BCEL sometimes is a little harsh describing exceptional situations.
+ catch (ClassFormatException cfe){
throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
}
1.6 +179 -150 jakarta-bcel/src/java/org/apache/bcel/verifier/statics/StringRepresentation.java
Index: StringRepresentation.java
===================================================================
RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/verifier/statics/StringRepresentation.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StringRepresentation.java 5 Aug 2002 17:31:32 -0000 1.5
+++ StringRepresentation.java 18 Dec 2003 17:22:58 -0000 1.6
@@ -68,156 +68,185 @@
* A (new StringRepresentation(Node n)).toString() never throws any exception.
* Note that this class also serves as a placeholder for more sophisticated message
* handling in future versions of JustIce.
- *
+ *
* @version $Id$
* @author <A HREF="http://www.inf.fu-berlin.de/~ehaase"/>Enver Haase</A>
*/
-public class StringRepresentation extends org.apache.bcel.classfile.EmptyVisitor implements Visitor{
- /** The string representation, created by a visitXXX() method, output by toString(). */
- private String tostring;
- /** The node we ask for its string representation. Not really needed; only for debug output. */
- private Node n;
- /**
- * Creates a new StringRepresentation object which is the representation of n.
- *
- * @see #toString()
- */
- public StringRepresentation(Node n){
- this.n = n;
- n.accept(this); // assign a string representation to field 'tostring' if we know n's class.
- }
- /**
- * Returns the String representation.
- */
- public String toString(){
- // The run-time check below is needed because we don't want to omit inheritance
- // of "EmptyVisitor" and provide a thousand empty methods.
- // However, in terms of performance this would be a better idea.
- // If some new "Node" is defined in BCEL (such as some concrete "Attribute"), we
- // want to know that this class has also to be adapted.
- if (tostring == null) throw new AssertionViolatedException("Please adapt '"+getClass()+"' to deal with objects of class '"+n.getClass()+"'.");
- return tostring;
- }
- /**
- * Returns the String representation of the Node object obj;
- * this is obj.toString() if it does not throw any RuntimeException,
- * or else it is a string derived only from obj's class name.
- */
- private String toString(Node obj){
- String ret;
- try{
- ret = obj.toString();
- }
- catch(RuntimeException e){
- String s = obj.getClass().getName();
- s = s.substring(s.lastIndexOf(".")+1);
- ret = "<<"+s+">>";
- }
- catch(ClassFormatError e){ /* BCEL can be harsh e.g. trying to convert the "signature" of a ReturnaddressType LocalVariable (shouldn't occur, but people do crazy things) */
- String s = obj.getClass().getName();
- s = s.substring(s.lastIndexOf(".")+1);
- ret = "<<"+s+">>";
- }
- return ret;
- }
- ////////////////////////////////
- // Visitor methods start here //
- ////////////////////////////////
- // We don't of course need to call some default implementation:
- // e.g. we could also simply output "Code" instead of a possibly
- // lengthy Code attribute's toString().
- public void visitCode(Code obj){
- //tostring = toString(obj);
- tostring = "<CODE>"; // We don't need real code outputs.
- }
- public void visitCodeException(CodeException obj){
- tostring = toString(obj);
- }
- public void visitConstantClass(ConstantClass obj){
- tostring = toString(obj);
- }
- public void visitConstantDouble(ConstantDouble obj){
- tostring = toString(obj);
- }
- public void visitConstantFieldref(ConstantFieldref obj){
- tostring = toString(obj);
- }
- public void visitConstantFloat(ConstantFloat obj){
- tostring = toString(obj);
- }
- public void visitConstantInteger(ConstantInteger obj){
- tostring = toString(obj);
- }
- public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj){
- tostring = toString(obj);
- }
- public void visitConstantLong(ConstantLong obj){
- tostring = toString(obj);
- }
- public void visitConstantMethodref(ConstantMethodref obj){
- tostring = toString(obj);
- }
- public void visitConstantNameAndType(ConstantNameAndType obj){
- tostring = toString(obj);
- }
- public void visitConstantPool(ConstantPool obj){
- tostring = toString(obj);
- }
- public void visitConstantString(ConstantString obj){
- tostring = toString(obj);
- }
- public void visitConstantUtf8(ConstantUtf8 obj){
- tostring = toString(obj);
- }
- public void visitConstantValue(ConstantValue obj){
- tostring = toString(obj);
- }
- public void visitDeprecated(Deprecated obj){
- tostring = toString(obj);
- }
- public void visitExceptionTable(ExceptionTable obj){
- tostring = toString(obj);
- }
- public void visitField(Field obj){
- tostring = toString(obj);
- }
- public void visitInnerClass(InnerClass obj){
- tostring = toString(obj);
- }
- public void visitInnerClasses(InnerClasses obj){
- tostring = toString(obj);
- }
- public void visitJavaClass(JavaClass obj){
- tostring = toString(obj);
- }
- public void visitLineNumber(LineNumber obj){
- tostring = toString(obj);
- }
- public void visitLineNumberTable(LineNumberTable obj){
- tostring = "<LineNumberTable: "+toString(obj)+">";
- }
- public void visitLocalVariable(LocalVariable obj){
- tostring = toString(obj);
- }
- public void visitLocalVariableTable(LocalVariableTable obj){
- tostring = "<LocalVariableTable: "+toString(obj)+">";
- }
- public void visitMethod(Method obj){
- tostring = toString(obj);
- }
- public void visitSignature(Signature obj){
- tostring = toString(obj);
- }
- public void visitSourceFile(SourceFile obj){
- tostring = toString(obj);
- }
- public void visitStackMap(StackMap obj){
- tostring = toString(obj);
- }
- public void visitSynthetic(Synthetic obj){
- tostring = toString(obj);
- }
- public void visitUnknown(Unknown obj){
- tostring = toString(obj);
- }
+public class StringRepresentation extends org.apache.bcel.classfile.EmptyVisitor implements Visitor {
+ /** The string representation, created by a visitXXX() method, output by toString(). */
+ private String tostring;
+ /** The node we ask for its string representation. Not really needed; only for debug output. */
+ private Node n;
+
+ /**
+ * Creates a new StringRepresentation object which is the representation of n.
+ *
+ * @see #toString()
+ */
+ public StringRepresentation(Node n) {
+ this.n = n;
+ n.accept(this); // assign a string representation to field 'tostring' if we know n's class.
+ }
+
+ /**
+ * Returns the String representation.
+ */
+ public String toString() {
+// The run-time check below is needed because we don't want to omit inheritance
+// of "EmptyVisitor" and provide a thousand empty methods.
+// However, in terms of performance this would be a better idea.
+// If some new "Node" is defined in BCEL (such as some concrete "Attribute"), we
+// want to know that this class has also to be adapted.
+ if (tostring == null) throw new AssertionViolatedException("Please adapt '" + getClass() + "' to deal with objects of class '" + n.getClass() + "'.");
+ return tostring;
+ }
+
+ /**
+ * Returns the String representation of the Node object obj;
+ * this is obj.toString() if it does not throw any RuntimeException,
+ * or else it is a string derived only from obj's class name.
+ */
+ private String toString(Node obj) {
+ String ret;
+ try {
+ ret = obj.toString();
+ }
+ catch (RuntimeException e) { // including ClassFormatException, trying to convert the "signature" of a ReturnaddressType LocalVariable (shouldn't occur, but people do crazy things)
+ String s = obj.getClass().getName();
+ s = s.substring(s.lastIndexOf(".") + 1);
+ ret = "<<" + s + ">>";
+ }
+ return ret;
+ }
+
+ ////////////////////////////////
+ // Visitor methods start here //
+ ////////////////////////////////
+ // We don't of course need to call some default implementation:
+ // e.g. we could also simply output "Code" instead of a possibly
+ // lengthy Code attribute's toString().
+ public void visitCode(Code obj) {
+ //tostring = toString(obj);
+ tostring = "<CODE>"; // We don't need real code outputs.
+ }
+
+ public void visitCodeException(CodeException obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantClass(ConstantClass obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantDouble(ConstantDouble obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantFieldref(ConstantFieldref obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantFloat(ConstantFloat obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantInteger(ConstantInteger obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantLong(ConstantLong obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantMethodref(ConstantMethodref obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantNameAndType(ConstantNameAndType obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantPool(ConstantPool obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantString(ConstantString obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantUtf8(ConstantUtf8 obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitConstantValue(ConstantValue obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitDeprecated(Deprecated obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitExceptionTable(ExceptionTable obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitField(Field obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitInnerClass(InnerClass obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitInnerClasses(InnerClasses obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitJavaClass(JavaClass obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitLineNumber(LineNumber obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitLineNumberTable(LineNumberTable obj) {
+ tostring = "<LineNumberTable: " + toString(obj) + ">";
+ }
+
+ public void visitLocalVariable(LocalVariable obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitLocalVariableTable(LocalVariableTable obj) {
+ tostring = "<LocalVariableTable: " + toString(obj) + ">";
+ }
+
+ public void visitMethod(Method obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitSignature(Signature obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitSourceFile(SourceFile obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitStackMap(StackMap obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitSynthetic(Synthetic obj) {
+ tostring = toString(obj);
+ }
+
+ public void visitUnknown(Unknown obj) {
+ tostring = toString(obj);
+ }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.