This is an automated email from the ASF dual-hosted git repository.
jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git
The following commit(s) were added to refs/heads/master by this push:
new 685f2e795 bz-66552 fix Depend task does not handle Dynamic constant
pool entries - java.lang.ClassFormatError: Invalid Constant Pool entry Type 17
In cases the Depend task scans a class file with Constant Pool entry Type 17
there was no handling, just fireing an Exception. Constant is defined since
JDK11, and format is same as InvokeDynamic Type 18. Provide Identical handling.
685f2e795 is described below
commit 685f2e795f5892202e685c5355cab8efb9c8455e
Author: Joerg Michelberger <[email protected]>
AuthorDate: Mon Sep 11 16:20:07 2023 +0200
bz-66552 fix Depend task does not handle Dynamic constant pool entries -
java.lang.ClassFormatError: Invalid Constant Pool entry Type 17
In cases the Depend task scans a class file with Constant Pool entry Type
17 there was no handling, just fireing an Exception.
Constant is defined since JDK11, and format is same as InvokeDynamic Type
18.
Provide Identical handling.
This closes #204 pull request at github.com/apache/ant
---
CONTRIBUTORS | 1 +
WHATSNEW | 4 ++
contributors.xml | 4 ++
.../depend/constantpool/ConstantPoolEntry.java | 6 ++
.../depend/constantpool/DynamicCPInfo.java | 84 ++++++++++++++++++++++
5 files changed, 99 insertions(+)
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 208347017..d55ea4472 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -216,6 +216,7 @@ Jesse Stockall
Jim Allers
Jimmy Casey
Joel Tucci
+Joerg Michelberger
Joerg Wassmer
Joey Richey
Johann Herunter
diff --git a/WHATSNEW b/WHATSNEW
index 185cb6a91..97f7ff858 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -8,6 +8,10 @@ Fixed bugs:
would unintentionally trim the string output.
Bugzilla Report 67082
+ * Fixes a bug in <depend> task which would throw a ClassFormatError
+ if it encountered constant pool entry type 17.
+ Bugzilla Report 66552
+
Changes from Ant 1.10.13 TO Ant 1.10.14
=======================================
diff --git a/contributors.xml b/contributors.xml
index 00eae460c..42fd240a2 100644
--- a/contributors.xml
+++ b/contributors.xml
@@ -900,6 +900,10 @@
<first>Joel</first>
<last>Tucci</last>
</name>
+ <name>
+ <first>Joerg</first>
+ <last>Michelberger</last>
+ </name>
<name>
<first>Joerg</first>
<last>Wassmer</last>
diff --git
a/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPoolEntry.java
b/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPoolEntry.java
index 5b0bb02b1..c44554d40 100644
---
a/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPoolEntry.java
+++
b/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPoolEntry.java
@@ -68,6 +68,9 @@ public abstract class ConstantPoolEntry {
/** Tag value for Method Type entries */
public static final int CONSTANT_METHODTYPE = 16;
+ /** Tag value for Dynamic entries*/
+ public static final int CONSTANT_DYNAMIC = 17;
+
/** Tag value for InvokeDynamic entries*/
public static final int CONSTANT_INVOKEDYNAMIC = 18;
@@ -166,6 +169,9 @@ public abstract class ConstantPoolEntry {
case CONSTANT_METHODTYPE:
cpInfo = new MethodTypeCPInfo();
break;
+ case CONSTANT_DYNAMIC:
+ cpInfo = new DynamicCPInfo();
+ break;
case CONSTANT_INVOKEDYNAMIC:
cpInfo = new InvokeDynamicCPInfo();
break;
diff --git
a/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/DynamicCPInfo.java
b/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/DynamicCPInfo.java
new file mode 100644
index 000000000..d9f83b5fa
--- /dev/null
+++
b/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/DynamicCPInfo.java
@@ -0,0 +1,84 @@
+/*
+ * 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
+ *
+ * https://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 Dynamic CP Info
+ *
+ */
+public class DynamicCPInfo 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 DynamicCPInfo() {
+ super(CONSTANT_DYNAMIC, 1);
+ }
+
+ /**
+ * read a constant pool entry from a class stream.
+ *
+ * @param cpStream the DataInputStream which contains the constant pool
+ * entry to be read.
+ * @exception IOException if there is a problem reading the entry from
+ * the stream.
+ */
+ @Override
+ 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.
+ */
+ @Override
+ public String toString() {
+ if (isResolved()) {
+ return "Name = " + nameAndTypeCPInfo.getName() + ", type = "
+ + nameAndTypeCPInfo.getType();
+ }
+ return "BootstrapMethodAttrIndex inx = " + bootstrapMethodAttrIndex
+ + "NameAndType index = " + nameAndTypeIndex;
+ }
+ /**
+ * 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.
+ */
+ @Override
+ public void resolve(ConstantPool constantPool) {
+ nameAndTypeCPInfo
+ = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex);
+ nameAndTypeCPInfo.resolve(constantPool);
+ super.resolve(constantPool);
+ }
+
+}