Anonymous avatar Anonymous committed 124b23c

PR 54090 Depend task does not handle invokeDynamic constant pool entries - java.lang.ClassFormatError: Invalid Constant Pool entry Type 18

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1436748 13f79535-47bb-0310-9956-ffa450edef68

Comments (0)

Files changed (6)

    MacOS X 10.7
    Bugzilla Report 52632
 
+ * Depend task does not handle invokeDynamic constant pool entries - java.lang.ClassFormatError: Invalid Constant Pool entry Type 18
+   Bugzilla Report 54090
+
 Other changes:
 --------------
 

manual/Tasks/depend.html

 
 <p>
 To learn more about how this information is obtained from the class files, 
-please refer to <a href="http://java.sun.com/docs/books/jvms/">the Java 
+please refer to <a href="http://docs.oracle.com/javase/specs/">the Java
 Virtual Machine Specification</a>
 </p>
 

src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPoolEntry.java

     /** Tag value for Name and Type entries. */
     public static final int CONSTANT_NAMEANDTYPE = 12;
 
+    /** Tag value for Method Handle entries */
+    public static final int CONSTANT_METHODHANDLE  = 15;
+
+    /** Tag value for Method Type entries */
+    public static final int CONSTANT_METHODTYPE = 16;
+
+    /** Tag value for InvokeDynamic entries*/
+    public static final int CONSTANT_INVOKEDYNAMIC = 18;
+
     /**
      * This entry's tag which identifies the type of this constant pool
      * entry.
                 cpInfo = new NameAndTypeCPInfo();
 
                 break;
+            case CONSTANT_METHODHANDLE:
+                cpInfo = new MethodHandleCPInfo();
+
+                break;
+            case CONSTANT_METHODTYPE:
+                cpInfo = new MethodTypeCPInfo();
+
+                break;
+            case CONSTANT_INVOKEDYNAMIC:
+                cpInfo = new InvokeDynamicCPInfo();
+
+                break;
             default:
                 throw new ClassFormatError("Invalid Constant Pool entry Type "
                      + cpTag);

src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/InvokeDynamicCPInfo.java

+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+
+/**
+ * An InvokeDynamic CP Info
+ *
+ */
+public class InvokeDynamicCPInfo extends ConstantCPInfo {
+
+    /** Index into the bootstrap methods for the class */
+    private int bootstrapMethodAttrIndex;
+    /** the value of the method descriptor pointed to */
+    private int nameAndTypeIndex;
+    /** the name and type CP info pointed to */
+    private NameAndTypeCPInfo nameAndTypeCPInfo;
+    /** */
+    /** Constructor.  */
+    public InvokeDynamicCPInfo() {
+        super(CONSTANT_INVOKEDYNAMIC, 1);
+    }
+
+    /**
+     * read a constant pool entry from a class stream.
+     *
+     * @param cpStream the DataInputStream which contains the constant pool
+     *      entry to be read.
+     * @exception java.io.IOException if there is a problem reading the entry from
+     *      the stream.
+     */
+    public void read(DataInputStream cpStream) throws IOException {
+        bootstrapMethodAttrIndex = cpStream.readUnsignedShort();
+        nameAndTypeIndex = cpStream.readUnsignedShort();
+    }
+
+    /**
+     * Print a readable version of the constant pool entry.
+     *
+     * @return the string representation of this constant pool entry.
+     */
+    public String toString() {
+        String value;
+        if (isResolved()) {
+            value = "Name = " + nameAndTypeCPInfo.getName() + ", type = " + nameAndTypeCPInfo.getType();
+        } else {
+            value = "BootstrapMethodAttrIndex inx = " + bootstrapMethodAttrIndex
+            + "NameAndType index = " + nameAndTypeIndex;
+        }
+
+        return value;
+    }
+    /**
+     * Resolve this constant pool entry with respect to its dependents in
+     * the constant pool.
+     *
+     * @param constantPool the constant pool of which this entry is a member
+     *      and against which this entry is to be resolved.
+     */
+    public void resolve(ConstantPool constantPool) {
+        nameAndTypeCPInfo
+                = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex);
+        nameAndTypeCPInfo.resolve(constantPool);
+        super.resolve(constantPool);
+    }
+
+}
+

src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/MethodHandleCPInfo.java

+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+
+/**
+ * A MethodHandle CP Info
+ *
+ */
+public class MethodHandleCPInfo extends ConstantPoolEntry {
+    private ConstantPoolEntry reference;
+
+    /** reference kind **/
+    private ReferenceKind referenceKind;
+    /** Must be a valid index into the constant pool tabel. */
+    private int referenceIndex;
+    /**
+     * the index into the constant pool which defined the name and type
+     * signature of the method
+     */
+    private int nameAndTypeIndex;
+    public enum ReferenceKind {
+        REF_getField(1),
+        REF_getStatic(2),
+        REF_putField(3),
+        REF_putStatic(4),
+        REF_invokeVirtual(5),
+        REF_invokeStatic(6),
+        REF_invokeSpecial(7),
+        REF_newInvokeSpecial(8),
+        REF_invokeInterface(9);
+        private final int referenceKind;
+        ReferenceKind(int referenceKind) {
+            this.referenceKind = referenceKind;
+        }
+
+    }
+    /** Constructor. */
+    public MethodHandleCPInfo() {
+        super(CONSTANT_METHODHANDLE, 1);
+    }
+
+    /**
+     * read a constant pool entry from a class stream.
+     *
+     * @param cpStream the DataInputStream which contains the constant pool
+     *      entry to be read.
+     * @exception java.io.IOException if there is a problem reading the entry from
+     *      the stream.
+     */
+    public void read(DataInputStream cpStream) throws IOException {
+        referenceKind = ReferenceKind.values()[cpStream.readUnsignedByte() - 1];
+
+        referenceIndex = cpStream.readUnsignedShort();
+    }
+
+    /**
+     * Print a readable version of the constant pool entry.
+     *
+     * @return the string representation of this constant pool entry.
+     */
+    public String toString() {
+        String value;
+
+        if (isResolved()) {
+            value = "MethodHandle : " + reference.toString();
+        } else {
+            value = "MethodHandle : Reference kind = " + referenceKind
+                 +  "Reference index = " + referenceIndex;
+        }
+
+        return value;
+    }
+
+    /**
+     * Resolve this constant pool entry with respect to its dependents in
+     * the constant pool.
+     *
+     * @param constantPool the constant pool of which this entry is a member
+     *      and against which this entry is to be resolved.
+     */
+    public void resolve(ConstantPool constantPool) {
+        reference = constantPool.getEntry(referenceIndex);
+        reference.resolve(constantPool);
+        super.resolve(constantPool);
+    }
+
+
+}
+

src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/MethodTypeCPInfo.java

+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+
+/**
+ * A Method Type CP Info
+ *
+ */
+public class MethodTypeCPInfo extends ConstantCPInfo {
+
+    /** Index into the constant pool for the class */
+    private int methodDescriptorIndex;
+    /** the value of the method descriptor pointed to */
+    private String methodDescriptor;
+    /** Constructor.  */
+    public MethodTypeCPInfo() {
+        super(CONSTANT_METHODTYPE, 1);
+    }
+
+    /**
+     * read a constant pool entry from a class stream.
+     *
+     * @param cpStream the DataInputStream which contains the constant pool
+     *      entry to be read.
+     * @exception java.io.IOException if there is a problem reading the entry from
+     *      the stream.
+     */
+    public void read(DataInputStream cpStream) throws IOException {
+        methodDescriptorIndex = cpStream.readUnsignedShort();
+    }
+
+    /**
+     * Resolve this constant pool entry with respect to its dependents in
+     * the constant pool.
+     *
+     * @param constantPool the constant pool of which this entry is a member
+     *      and against which this entry is to be resolved.
+     */
+    public void resolve(ConstantPool constantPool) {
+        Utf8CPInfo methodClass
+                = (Utf8CPInfo) constantPool.getEntry(methodDescriptorIndex);
+        methodClass.resolve(constantPool);
+        methodDescriptor = methodClass.getValue();
+        super.resolve(constantPool);
+    }
+    /**
+     * Print a readable version of the constant pool entry.
+     *
+     * @return the string representation of this constant pool entry.
+     */
+    public String toString() {
+        if (! isResolved()) {
+            return "MethodDescriptorIndex: " + methodDescriptorIndex;
+        } else {
+            return "MethodDescriptor: " + methodDescriptor;
+
+        }
+    }
+
+}
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.