Skip to content

Commit 4e9005d

Browse files
committed
Add test for signature polymorphic methods
1 parent 794442a commit 4e9005d

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

build.xml

+11-1
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@
633633
<condition property="-gen.sunmisc">
634634
<available classname="sun.misc.BASE64Encoder"/>
635635
</condition>
636+
<condition property="-gen.jdk7">
637+
<available classname="java.lang.invoke.MethodHandle"/>
638+
</condition>
636639
<condition property="-gen.jdk8">
637640
<hasmethod classname="java.util.Collections" method="emptySortedSet"/>
638641
</condition>
@@ -655,14 +658,21 @@
655658
nowarn="true" source="1.6" target="1.6" debug="true" deprecation="false" encoding="${build.encoding}"/>
656659
</target>
657660

661+
<target name="-generate-test-classes-jdk7" if="-gen.jdk7">
662+
<echo level="info" message="Generating test classes for Java 7:"/>
663+
<delete dir="src/test/antunit" includes="Java7*.class"/>
664+
<javac includeantruntime="false" srcdir="src/test/antunit" destdir="src/test/antunit" includes="Java7*.java"
665+
nowarn="true" source="1.7" target="1.7" debug="true" deprecation="false" encoding="${build.encoding}"/>
666+
</target>
667+
658668
<target name="-generate-test-classes-jdk8" if="-gen.jdk8">
659669
<echo level="info" message="Generating test classes for Java 8:"/>
660670
<delete dir="src/test/antunit" includes="Java8*.class"/>
661671
<javac includeantruntime="false" srcdir="src/test/antunit" destdir="src/test/antunit" includes="Java8*.java"
662672
nowarn="true" source="1.8" target="1.8" debug="true" deprecation="false" encoding="${build.encoding}"/>
663673
</target>
664674

665-
<target name="generate-test-classes" depends="-generate-test-classes-init,-generate-test-classes-sunmisc,-generate-test-classes-jdk6,-generate-test-classes-jdk8" description="Regenerates .class files used by tests if the current JDK version supports it"/>
675+
<target name="generate-test-classes" depends="-generate-test-classes-init,-generate-test-classes-sunmisc,-generate-test-classes-jdk6,-generate-test-classes-jdk7,-generate-test-classes-jdk8" description="Regenerates .class files used by tests if the current JDK version supports it"/>
666676

667677
<target name="show-help-mojo" depends="install-maven-artifacts" description="Shows help about mojo usage">
668678
<artifact:mvn mavenVersion="${maven.version}" failonerror="true" fork="${maven.fork}" taskname="help">
1.21 KB
Binary file not shown.
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* (C) Copyright Uwe Schindler (Generics Policeman) and others.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/* The binary class file is packaged together with the source distribution.
18+
*/
19+
20+
import java.lang.invoke.MethodHandle;
21+
import java.lang.invoke.MethodHandles;
22+
import java.lang.invoke.MethodType;
23+
24+
class Java7MethodHandles {
25+
static void main(String... args) throws Throwable {
26+
MethodHandle mh = MethodHandles.publicLookup().findVirtual(StringBuilder.class, "append",
27+
MethodType.methodType(StringBuilder.class, int.class));
28+
StringBuilder result = (StringBuilder) mh.invoke(new StringBuilder(), 1);
29+
}
30+
}

src/test/antunit/TestJava7.xml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
* (C) Copyright Uwe Schindler (Generics Policeman) and others.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
-->
17+
<project xmlns:au="antlib:org.apache.ant.antunit">
18+
19+
<condition property="has.MethodHandle">
20+
<available classname="java.lang.invoke.MethodHandle"/>
21+
</condition>
22+
23+
<target name="testSignaturePolymorphic" if="has.MethodHandle">
24+
<au:expectfailure expectedMessage="Check for forbidden API calls failed, see log">
25+
<forbiddenapis failOnMissingClasses="false">
26+
<file file="Java7MethodHandles.class"/>
27+
java.lang.invoke.MethodHandle#invoke(java.lang.Object[]) @ Forbidden signature polymorphic method
28+
</forbiddenapis>
29+
</au:expectfailure>
30+
<au:assertLogContains level="error" text="Forbidden method invocation (signature polymorphic): java.lang.invoke.MethodHandle#invoke(java.lang.Object[]) [Forbidden signature polymorphic method]"/>
31+
<au:assertLogContains level="error" text=" 1 error(s)"/>
32+
</target>
33+
34+
</project>

0 commit comments

Comments
 (0)