Browse Source

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
master
Antoine Levy-Lambert 12 years ago
parent
commit
b103f7e356
6 changed files with 296 additions and 1 deletions
  1. +3
    -0
      WHATSNEW
  2. +1
    -1
      manual/Tasks/depend.html
  3. +21
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPoolEntry.java
  4. +85
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/InvokeDynamicCPInfo.java
  5. +107
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/MethodHandleCPInfo.java
  6. +79
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/MethodTypeCPInfo.java

+ 3
- 0
WHATSNEW View File

@@ -69,6 +69,9 @@ Fixed bugs:
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:
--------------



+ 1
- 1
manual/Tasks/depend.html View File

@@ -43,7 +43,7 @@ compiler. This is generally faster than parsing the Java source.</p>

<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>



+ 21
- 0
src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPoolEntry.java View File

@@ -62,6 +62,15 @@ public abstract class ConstantPoolEntry {
/** 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.
@@ -154,6 +163,18 @@ public abstract class ConstantPoolEntry {
case CONSTANT_NAMEANDTYPE:
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 "


+ 85
- 0
src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/InvokeDynamicCPInfo.java View File

@@ -0,0 +1,85 @@
/*
* 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);
}

}


+ 107
- 0
src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/MethodHandleCPInfo.java View File

@@ -0,0 +1,107 @@
/*
* 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);
}


}


+ 79
- 0
src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/MethodTypeCPInfo.java View File

@@ -0,0 +1,79 @@
/*
* 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;

}
}

}


Loading…
Cancel
Save