diff --git a/WHATSNEW b/WHATSNEW index e5baae1fa..1b7814452 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -31,6 +31,11 @@ Fixed bugs: * died with a NullPointerException since Ant 1.10.2. Bugzilla Report 62335 + * The task would fail with + "java.lang.ClassFormatError: Invalid Constant Pool entry Type 19" while + parsing a module-info.class. This is now fixed. + Bug reported by Simon IJskes https://issues.apache.org/jira/browse/NETBEANS-781 + Other changes: -------------- diff --git a/src/etc/testcases/taskdefs/optional/depend/depend.xml b/src/etc/testcases/taskdefs/optional/depend/depend.xml index 8465bb026..26260a7c5 100644 --- a/src/etc/testcases/taskdefs/optional/depend/depend.xml +++ b/src/etc/testcases/taskdefs/optional/depend/depend.xml @@ -33,6 +33,11 @@ + + + + + This buildfile is used as part of Ant's test suite. @@ -193,4 +198,10 @@ + + + + + + diff --git a/src/etc/testcases/taskdefs/optional/depend/src6/Foo.java b/src/etc/testcases/taskdefs/optional/depend/src6/Foo.java new file mode 100644 index 000000000..a305cb02f --- /dev/null +++ b/src/etc/testcases/taskdefs/optional/depend/src6/Foo.java @@ -0,0 +1,22 @@ +/* +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. +*/ + +public class Foo { + public static void main(final String[] args) { + System.out.println("foo"); + } +} \ No newline at end of file diff --git a/src/etc/testcases/taskdefs/optional/depend/src6/module-info.java b/src/etc/testcases/taskdefs/optional/depend/src6/module-info.java new file mode 100644 index 000000000..24e075db1 --- /dev/null +++ b/src/etc/testcases/taskdefs/optional/depend/src6/module-info.java @@ -0,0 +1,3 @@ +module dummy { + requires java.base; +} \ No newline at end of file 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 b639fa9ae..ab66215e8 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 @@ -71,6 +71,9 @@ public abstract class ConstantPoolEntry { /** Tag value for InvokeDynamic entries*/ public static final int CONSTANT_INVOKEDYNAMIC = 18; + /** Tag value for CONSTANT_Module_info entry */ + public static final int CONSTANT_MODULEINFO = 19; + /** * This entry's tag which identifies the type of this constant pool * entry. @@ -162,6 +165,9 @@ public abstract class ConstantPoolEntry { case CONSTANT_INVOKEDYNAMIC: cpInfo = new InvokeDynamicCPInfo(); break; + case CONSTANT_MODULEINFO: + cpInfo = new ModuleCPInfo(); + break; default: throw new ClassFormatError("Invalid Constant Pool entry Type " + cpTag); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ModuleCPInfo.java b/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ModuleCPInfo.java new file mode 100644 index 000000000..f24bae248 --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ModuleCPInfo.java @@ -0,0 +1,34 @@ +package org.apache.tools.ant.taskdefs.optional.depend.constantpool; + +import java.io.DataInputStream; +import java.io.IOException; + +/** + * Represents the module info constant pool entry + */ +public class ModuleCPInfo extends ConstantCPInfo { + + private int moduleNameIndex; + private String moduleName; + + public ModuleCPInfo() { + super(CONSTANT_MODULEINFO, 1); + } + + @Override + public void read(final DataInputStream cpStream) throws IOException { + this.moduleNameIndex = cpStream.readUnsignedShort(); + } + + @Override + public void resolve(final ConstantPool constantPool) { + this.moduleName = ((Utf8CPInfo) constantPool.getEntry(this.moduleNameIndex)).getValue(); + + super.resolve(constantPool); + } + + @Override + public String toString() { + return "Module info Constant Pool Entry for " + this.moduleName + "[" + this.moduleNameIndex + "]"; + } +} diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java index 023c36b43..e3919c151 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java @@ -27,7 +27,9 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.FileUtilities; +import org.apache.tools.ant.taskdefs.condition.JavaVersion; import org.apache.tools.ant.types.FileSet; +import org.junit.Assume; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -194,4 +196,16 @@ public class DependTest { .and(containsString("but has not been deleted because its source file could not be determined"))); } + /** + * Tests that the depend task when run against a path containing a module-info.class (Java 9+ construct) + * doesn't run into error + */ + @Test + public void testModuleInfo() { + final JavaVersion atLeastJava9 = new JavaVersion(); + atLeastJava9.setAtLeast("9"); + Assume.assumeTrue("Skipping test execution since Java version is lesser than 9", atLeastJava9.eval()); + buildRule.executeTarget("testmoduleinfo"); + } + }