You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/09/11 12:34:46 UTC

svn commit: r1702419 - in /commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6: classfile/ generic/ util/ verifier/

Author: sebb
Date: Fri Sep 11 10:34:45 2015
New Revision: 1702419

URL: http://svn.apache.org/r1702419
Log:
Gradually working towards restoring binary compatibility
Restore deprecated methods for now

Modified:
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/ConstantUtf8.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/FieldOrMethod.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/LocalVariableTable.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/StackMapEntry.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/FieldOrMethod.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/ObjectType.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/ReferenceType.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/ClassPath.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/GraphicalVerifier.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/VerifierFactoryListModel.java

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/ConstantUtf8.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/ConstantUtf8.java?rev=1702419&r1=1702418&r2=1702419&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/ConstantUtf8.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/ConstantUtf8.java Fri Sep 11 10:34:45 2015
@@ -192,6 +192,16 @@ public final class ConstantUtf8 extends
 
 
     /**
+     * @param bytes the raw bytes of this Utf-8
+     * @deprecated
+     */
+    @java.lang.Deprecated
+    public final void setBytes( String bytes ) {
+        throw new UnsupportedOperationException();
+    }
+
+
+    /**
      * @return String representation
      */
     @Override

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/FieldOrMethod.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/FieldOrMethod.java?rev=1702419&r1=1702418&r2=1702419&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/FieldOrMethod.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/FieldOrMethod.java Fri Sep 11 10:34:45 2015
@@ -18,6 +18,7 @@
 package org.apache.commons.bcel6.classfile;
 
 import java.io.DataInput;
+import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 
@@ -48,6 +49,12 @@ public abstract class FieldOrMethod exte
     @java.lang.Deprecated
     protected Attribute[] attributes; // Collection of attributes
 
+    /**
+     * @deprecated (since 6.0) will be removed (not needed)
+     */
+    @java.lang.Deprecated
+    protected int attributes_count; // No. of attributes
+
     // @since 6.0
     private AnnotationEntry[] annotationEntries; // annotations defined on the field or method 
 
@@ -79,6 +86,18 @@ public abstract class FieldOrMethod exte
      * @param file Input stream
      * @throws IOException
      * @throws ClassFormatException
+     * @deprecated Use {@link #FieldOrMethod(java.io.DataInput, ConstantPool)} instead.
+     */
+    protected FieldOrMethod(DataInputStream file, ConstantPool constant_pool) throws IOException,
+            ClassFormatException {
+        this((DataInput) file, constant_pool);
+    }
+
+    /**
+     * Construct object from file stream.
+     * @param file Input stream
+     * @throws IOException
+     * @throws ClassFormatException
      */
     protected FieldOrMethod(DataInput file, ConstantPool constant_pool) throws IOException, ClassFormatException {
         this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null,
@@ -88,6 +107,7 @@ public abstract class FieldOrMethod exte
         for (int i = 0; i < attributes_count; i++) {
             attributes[i] = Attribute.readAttribute(file, constant_pool);
         }
+        this.attributes_count = attributes_count; // init deprecated field
     }
 
 
@@ -138,6 +158,7 @@ public abstract class FieldOrMethod exte
      */
     public final void setAttributes( Attribute[] attributes ) {
         this.attributes = attributes;
+        this.attributes_count = attributes.length; // init deprecated field
     }
 
 
@@ -223,6 +244,7 @@ public abstract class FieldOrMethod exte
 
         c.constant_pool    = constant_pool;
         c.attributes       = new Attribute[attributes.length];
+        c.attributes_count = attributes_count; // init deprecated field
 
         for (int i = 0; i < attributes.length; i++) {
             c.attributes[i] = attributes[i].copy(constant_pool);

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/LocalVariableTable.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/LocalVariableTable.java?rev=1702419&r1=1702418&r2=1702419&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/LocalVariableTable.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/LocalVariableTable.java Fri Sep 11 10:34:45 2015
@@ -117,6 +117,26 @@ public class LocalVariableTable extends
     /** 
      * 
      * @param index the variable slot
+     * 
+     * @return the first LocalVariable that matches the slot or null if not found
+     * 
+     * @deprecated since 5.2 because multiple variables can share the
+     *             same slot, use getLocalVariable(int index, int pc) instead.
+     */
+    @java.lang.Deprecated
+    public final LocalVariable getLocalVariable( int index ) {
+        for (LocalVariable variable : local_variable_table) {
+            if (variable.getIndex() == index) {
+                return variable;
+            }
+        }
+        return null;
+    }
+
+
+    /** 
+     * 
+     * @param index the variable slot
      * @param pc the current pc that this variable is alive
      * 
      * @return the LocalVariable that matches or null if not found

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/StackMapEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/StackMapEntry.java?rev=1702419&r1=1702418&r2=1702419&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/StackMapEntry.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/StackMapEntry.java Fri Sep 11 10:34:45 2015
@@ -334,6 +334,11 @@ public final class StackMapEntry impleme
     }
 
 
+    @java.lang.Deprecated
+    public void setNumberOfLocals( int n ) { // TODO unused
+    }
+
+
     public int getNumberOfLocals() {
         return types_of_locals.length;
     }
@@ -349,6 +354,11 @@ public final class StackMapEntry impleme
     }
 
 
+    @java.lang.Deprecated
+    public void setNumberOfStackItems( int n ) { // TODO unused
+    }
+
+
     public int getNumberOfStackItems() {
         return types_of_stack_items.length;
     }

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/FieldOrMethod.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/FieldOrMethod.java?rev=1702419&r1=1702418&r2=1702419&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/FieldOrMethod.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/FieldOrMethod.java Fri Sep 11 10:34:45 2015
@@ -91,6 +91,17 @@ public abstract class FieldOrMethod exte
     }
 
 
+    /** @return type of the referenced class/interface
+     * @deprecated If the instruction references an array class,
+     *    the ObjectType returned will be invalid.  Use
+     *    getReferenceType() instead.
+     */
+    @Deprecated
+    public ObjectType getClassType( ConstantPoolGen cpg ) {
+        return ObjectType.getInstance(getClassName(cpg));
+    }
+
+
     /**
      * Return the reference type representing the class, interface,
      * or array class referenced by the instruction.

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java?rev=1702419&r1=1702418&r2=1702419&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java Fri Sep 11 10:34:45 2015
@@ -549,6 +549,27 @@ public abstract class Instruction implem
     public abstract void accept( Visitor v );
 
 
+    /** Get Comparator object used in the equals() method to determine
+     * equality of instructions.
+     *
+     * @return currently used comparator for equals()
+     * @deprecated use the built in comparator, or wrap this class in another object that implements these methods
+     */
+    @Deprecated
+    public static InstructionComparator getComparator() {
+        return cmp;
+    }
+
+
+    /** Set comparator to be used for equals().
+      * @deprecated use the built in comparator, or wrap this class in another object that implements these methods
+     */
+    @Deprecated
+    public static void setComparator( InstructionComparator c ) {
+        cmp = c;
+    }
+
+
     /** Check for equality, delegated to comparator
      * @return true if that is an Instruction and has the same opcode
      */

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/ObjectType.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/ObjectType.java?rev=1702419&r1=1702418&r2=1702419&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/ObjectType.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/ObjectType.java Fri Sep 11 10:34:45 2015
@@ -72,6 +72,42 @@ public class ObjectType extends Referenc
 
 
     /**
+     * If "this" doesn't reference a class, it references an interface
+     * or a non-existant entity.
+     * @deprecated (since 6.0) this method returns an inaccurate result
+     *   if the class or interface referenced cannot
+     *   be found: use referencesClassExact() instead
+     */
+    @Deprecated
+    public boolean referencesClass() {
+        try {
+            JavaClass jc = Repository.lookupClass(class_name);
+            return jc.isClass();
+        } catch (ClassNotFoundException e) {
+            return false;
+        }
+    }
+
+
+    /**
+     * If "this" doesn't reference an interface, it references a class
+     * or a non-existant entity.
+     * @deprecated (since 6.0) this method returns an inaccurate result
+     *   if the class or interface referenced cannot
+     *   be found: use referencesInterfaceExact() instead
+     */
+    @Deprecated
+    public boolean referencesInterface() {
+        try {
+            JavaClass jc = Repository.lookupClass(class_name);
+            return !jc.isClass();
+        } catch (ClassNotFoundException e) {
+            return false;
+        }
+    }
+
+
+    /**
      * Return true if this type references a class,
      * false if it references an interface.
      * @return true if the type references a class, false if

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/ReferenceType.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/ReferenceType.java?rev=1702419&r1=1702418&r2=1702419&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/ReferenceType.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/ReferenceType.java Fri Sep 11 10:34:45 2015
@@ -256,4 +256,75 @@ public abstract class ReferenceType exte
         return null;
     }
 
+    /**
+     * This commutative operation returns the first common superclass (narrowest ReferenceType
+     * referencing a class, not an interface).
+     * If one of the types is a superclass of the other, the former is returned.
+     * If "this" is Type.NULL, then t is returned.
+     * If t is Type.NULL, then "this" is returned.
+     * If "this" equals t ['this.equals(t)'] "this" is returned.
+     * If "this" or t is an ArrayType, then Type.OBJECT is returned.
+     * If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned.
+     * If not all of the two classes' superclasses cannot be found, "null" is returned.
+     * See the JVM specification edition 2, "�4.9.2 The Bytecode Verifier".
+     *
+     * @deprecated use getFirstCommonSuperclass(ReferenceType t) which has
+     *             slightly changed semantics.
+     * @throws ClassNotFoundException on failure to find superclasses of this
+     *  type, or the type passed as a parameter
+     */
+    @Deprecated
+    public ReferenceType firstCommonSuperclass( ReferenceType t ) throws ClassNotFoundException {
+        if (this.equals(Type.NULL)) {
+            return t;
+        }
+        if (t.equals(Type.NULL)) {
+            return this;
+        }
+        if (this.equals(t)) {
+            return this;
+            /*
+             * TODO: Above sounds a little arbitrary. On the other hand, there is
+             * no object referenced by Type.NULL so we can also say all the objects
+             * referenced by Type.NULL were derived from java.lang.Object.
+             * However, the Java Language's "instanceof" operator proves us wrong:
+             * "null" is not referring to an instance of java.lang.Object :)
+             */
+        }
+        if ((this instanceof ArrayType) || (t instanceof ArrayType)) {
+            return Type.OBJECT;
+            // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType?
+        }
+        if (((this instanceof ObjectType) && ((ObjectType) this).referencesInterface())
+                || ((t instanceof ObjectType) && ((ObjectType) t).referencesInterface())) {
+            return Type.OBJECT;
+            // TODO: The above line is correct comparing to the vmspec2. But one could
+            // make class file verification a bit stronger here by using the notion of
+            // superinterfaces or even castability or assignment compatibility.
+        }
+        // this and t are ObjectTypes, see above.
+        ObjectType thiz = (ObjectType) this;
+        ObjectType other = (ObjectType) t;
+        JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName());
+        JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName());
+        if ((thiz_sups == null) || (other_sups == null)) {
+            return null;
+        }
+        // Waaahh...
+        JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1];
+        JavaClass[] t_sups = new JavaClass[other_sups.length + 1];
+        System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length);
+        System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length);
+        this_sups[0] = Repository.lookupClass(thiz.getClassName());
+        t_sups[0] = Repository.lookupClass(other.getClassName());
+        for (JavaClass t_sup : t_sups) {
+            for (JavaClass this_sup : this_sups) {
+                if (this_sup.equals(t_sup)) {
+                    return ObjectType.getInstance(this_sup.getClassName());
+                }
+            }
+        }
+        // Huh? Did you ask for Type.OBJECT's superclass??
+        return null;
+    }
 }

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/ClassPath.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/ClassPath.java?rev=1702419&r1=1702418&r2=1702419&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/ClassPath.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/ClassPath.java Fri Sep 11 10:34:45 2015
@@ -93,6 +93,15 @@ public class ClassPath {
         vec.toArray(paths);
     }
 
+    /**
+     * Search for classes in CLASSPATH.
+     * @deprecated Use SYSTEM_CLASS_PATH constant
+     */
+    @Deprecated
+    public ClassPath() {
+        this(getClassPath());
+    }
+
     /** @return used class path string
      */
     @Override

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/GraphicalVerifier.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/GraphicalVerifier.java?rev=1702419&r1=1702418&r2=1702419&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/GraphicalVerifier.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/GraphicalVerifier.java Fri Sep 11 10:34:45 2015
@@ -34,7 +34,7 @@ public class GraphicalVerifier {
 
 
     /** Constructor. */
-    private GraphicalVerifier() {
+    public GraphicalVerifier() {
         VerifierAppFrame frame = new VerifierAppFrame();
         //Frames �berpr�fen, die voreingestellte Gr��e haben
         //Frames packen, die nutzbare bevorzugte Gr��eninformationen enthalten, z.B. aus ihrem Layout

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/VerifierFactoryListModel.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/VerifierFactoryListModel.java?rev=1702419&r1=1702418&r2=1702419&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/VerifierFactoryListModel.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/VerifierFactoryListModel.java Fri Sep 11 10:34:45 2015
@@ -77,9 +77,6 @@ public class VerifierFactoryListModel im
     }
 
 
-    /**
-     * @since 6.0
-     */
     @Override
     public synchronized String getElementAt( int index ) {
         return (cache.toArray(new String[cache.size()]))[index];