svn commit: r190050 - /jakarta/bcel/trunk/src/java/org/apache/bcel/generic/FieldOrMethod.java

[email protected]
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
Author: dbrosius
Date: Fri Jun 10 17:47:39 2005
New Revision: 190050

URL: http://svn.apache.org/viewcvs?rev=190050&view=rev
Log:
For FieldOrMethod.getClassName changed to support java5.0 for old clients. thanks Dave Hovemeyer

   *  @deprecated If the instruction references an array class,
   *    this method will return "java.lang.Object".
   *    For code generated by Java 1.5, this answer is
   *    sometimes wrong (e.g., if the "clone()" method is
   *    called on an array).  A better idea is to use
   *    the getReferenceType() method, which correctly distinguishes
   *    between class types and array types.

Modified:
    jakarta/bcel/trunk/src/java/org/apache/bcel/generic/FieldOrMethod.java

Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/generic/FieldOrMethod.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/generic/FieldOrMethod.java?rev=190050&r1=190049&r2=190050&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/generic/FieldOrMethod.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/generic/FieldOrMethod.java Fri Jun 10 17:47:39 2005
@@ -62,11 +62,23 @@
   }
 
   /** @return name of the referenced class/interface
+   *  @deprecated If the instruction references an array class,
+   *    this method will return "java.lang.Object".
+   *    For code generated by Java 1.5, this answer is
+   *    sometimes wrong (e.g., if the "clone()" method is
+   *    called on an array).  A better idea is to use
+   *    the getReferenceType() method, which correctly distinguishes
+   *    between class types and array types.
    */
   public String getClassName(ConstantPoolGen cpg) {
     ConstantPool cp  = cpg.getConstantPool();
     ConstantCP   cmr = (ConstantCP)cp.getConstant(index);
-    return cp.getConstantString(cmr.getClassIndex(), org.apache.bcel.Constants.CONSTANT_Class).replace('/', '.');
+    String className = cp.getConstantString(cmr.getClassIndex(), org.apache.bcel.Constants.CONSTANT_Class);
+    if (className.startsWith("[")) {
+      // Turn array classes into java.lang.Object.
+       return "java.lang.Object";
+    }
+    return className.replace('/', '.');
   }
 
   /** @return type of the referenced class/interface
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.