Browse Source

Fix parsing of module-info.class, when being analyzed by "depend" task

master
Jaikiran Pai 7 years ago
parent
commit
d0f9c2e121
7 changed files with 95 additions and 0 deletions
  1. +5
    -0
      WHATSNEW
  2. +11
    -0
      src/etc/testcases/taskdefs/optional/depend/depend.xml
  3. +22
    -0
      src/etc/testcases/taskdefs/optional/depend/src6/Foo.java
  4. +3
    -0
      src/etc/testcases/taskdefs/optional/depend/src6/module-info.java
  5. +6
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPoolEntry.java
  6. +34
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ModuleCPInfo.java
  7. +14
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java

+ 5
- 0
WHATSNEW View File

@@ -31,6 +31,11 @@ Fixed bugs:
* <cab> died with a NullPointerException since Ant 1.10.2.
Bugzilla Report 62335

* The <depend> 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:
--------------



+ 11
- 0
src/etc/testcases/taskdefs/optional/depend/depend.xml View File

@@ -33,6 +33,11 @@
<property name="src3.dir" value="src3"/>
<property name="src4.dir" value="src4"/>
<property name="src5.dir" value="src5"/>
<property name="src6.dir" value="src6"/>

<condition property="atleast.java9">
<javaversion atleast="9"/>
</condition>

<target name="help">
<echo>This buildfile is used as part of Ant's test suite.</echo>
@@ -193,4 +198,10 @@
<depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" closure="yes"/>
<fileset id="result" dir="${classes.dir}"/>
</target>

<target name="testmoduleinfo" if="${atleast.java9}">
<mkdir dir="${output}/java9"/>
<javac srcdir="${src6.dir}" destdir="${output}/java9" source="9" target="9"/>
<depend srcdir="${src6.dir}" destdir="${output}/java9"/>
</target>
</project>

+ 22
- 0
src/etc/testcases/taskdefs/optional/depend/src6/Foo.java View File

@@ -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");
}
}

+ 3
- 0
src/etc/testcases/taskdefs/optional/depend/src6/module-info.java View File

@@ -0,0 +1,3 @@
module dummy {
requires java.base;
}

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

@@ -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);


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

@@ -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 + "]";
}
}

+ 14
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java View File

@@ -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");
}

}

Loading…
Cancel
Save