undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8058112
|
||||
* @summary Invalid BootstrapMethod for constructor/method reference
|
||||
*/
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
public class MethodReferenceIntersection1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
MethodReferenceIntersection1 main = new MethodReferenceIntersection1();
|
||||
List<Info_MRI1> list = main.toInfoListError(Arrays.asList(new Base_MRI1()));
|
||||
System.out.printf("result %d\n", list.size());
|
||||
}
|
||||
|
||||
public <H extends B_MRI1 & A_MRI1> List<Info_MRI1> toInfoListError(List<H> list) {
|
||||
Comparator<B_MRI1> byNameComparator =
|
||||
(B_MRI1 b1, B_MRI1 b2) -> b1.getB().compareToIgnoreCase(b2.getB());
|
||||
return list.stream().sorted(byNameComparator).map(Info_MRI1::new).collect(toList());
|
||||
}
|
||||
|
||||
public <H extends B_MRI1 & A_MRI1> List<Info_MRI1> toInfoListWorks(List<H> list) {
|
||||
Comparator<B_MRI1> byNameComparator =
|
||||
(B_MRI1 b1, B_MRI1 b2) -> b1.getB().compareToIgnoreCase(b2.getB());
|
||||
return list.stream().sorted(byNameComparator).map(s -> new Info_MRI1(s)).collect(toList());
|
||||
}
|
||||
}
|
||||
|
||||
interface B_MRI1 {
|
||||
public String getB();
|
||||
}
|
||||
|
||||
interface A_MRI1 {
|
||||
public long getA();
|
||||
}
|
||||
|
||||
class Info_MRI1 {
|
||||
private final long a;
|
||||
private final String b;
|
||||
|
||||
<H extends A_MRI1 & B_MRI1> Info_MRI1(H h) {
|
||||
a = h.getA();
|
||||
b = h.getB();
|
||||
}
|
||||
}
|
||||
|
||||
class Base_MRI1 implements A_MRI1, B_MRI1 {
|
||||
|
||||
@Override
|
||||
public long getA() {
|
||||
return 7L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getB() {
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8058112
|
||||
* @summary Invalid BootstrapMethod for constructor/method reference
|
||||
*/
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class MethodReferenceIntersection2 {
|
||||
|
||||
interface B { }
|
||||
|
||||
interface A { }
|
||||
|
||||
static class C implements A, B { }
|
||||
|
||||
static class Info {
|
||||
<H extends A & B> Info(H h) { }
|
||||
|
||||
static <H extends A & B> Info info(H h) {
|
||||
return new Info(h);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test();
|
||||
}
|
||||
|
||||
// Note the switch in order compared to that on Info
|
||||
static <H extends B & A> void test() {
|
||||
Function<H, Info> f1L = _h -> new Info(_h);
|
||||
Function<H, Info> f1 = Info::new;
|
||||
Function<H, Info> f2L = _h -> Info.info(_h);
|
||||
Function<H, Info> f2 = Info::info;
|
||||
H c = (H) new C();
|
||||
if(f1.apply(c) instanceof Info &&
|
||||
f2.apply(c) instanceof Info) {
|
||||
System.out.println("Passes.");
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8058112
|
||||
* @summary Invalid BootstrapMethod for constructor/method reference
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Remi Forax
|
||||
*/
|
||||
|
||||
public class MethodReferenceIntersection3 {
|
||||
interface A {}
|
||||
|
||||
interface Foo {
|
||||
<T extends Object & A> void foo(T t);
|
||||
}
|
||||
|
||||
static <T extends A> void bar(T t) {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Foo foo = MethodReferenceIntersection3::bar;
|
||||
foo.foo(new A(){});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8213032
|
||||
* @summary program fails with LambdaConversionException at execution time
|
||||
*/
|
||||
|
||||
import java.util.stream.*;
|
||||
|
||||
public class MethodReferenceIntersection4 {
|
||||
interface I {}
|
||||
static abstract class C { }
|
||||
static class A extends C implements I { }
|
||||
static class B extends C implements I { }
|
||||
|
||||
static String f(I i) { return null; }
|
||||
|
||||
public static void main(String[] args) {
|
||||
Stream.of(new A(), new B())
|
||||
.map(MethodReferenceIntersection4::f)
|
||||
.forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8191655
|
||||
* @summary LambdaConversionException: Invalid receiver type interface; not a subtype of implementation type interface
|
||||
* @run main MethodReferenceIntersectionInducedTest
|
||||
*/
|
||||
|
||||
|
||||
import java.util.function.Consumer;
|
||||
public class MethodReferenceIntersectionInducedTest {
|
||||
static String blah;
|
||||
<T> void forAll(Consumer<T> consumer, T... values) { consumer.accept(values[0]); }
|
||||
|
||||
public void secondTest() {
|
||||
forAll(Picture::draw, new MyPicture(), new Universal());
|
||||
}
|
||||
|
||||
interface Shape { void draw(); }
|
||||
interface Marker { }
|
||||
interface Picture { void draw(); }
|
||||
|
||||
class MyShape implements Marker, Shape { public void draw() { } }
|
||||
class MyPicture implements Marker, Picture { public void draw() { blah = "MyPicture"; } }
|
||||
class Universal implements Marker, Picture, Shape { public void draw() { System.out.println("Universal"); } }
|
||||
|
||||
public static void main(String[] args) {
|
||||
new MethodReferenceIntersectionInducedTest().secondTest();
|
||||
if (!blah.equals("MyPicture"))
|
||||
throw new AssertionError("Incorrect output");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8024696 8075752
|
||||
* @summary Missing null check in bound method reference capture
|
||||
*/
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MethodReferenceNullCheckTest {
|
||||
public static void main(String[] args) {
|
||||
String s = null;
|
||||
boolean npeFired = false;
|
||||
try {
|
||||
Supplier<Boolean> ss = s::isEmpty;
|
||||
} catch (NullPointerException npe) {
|
||||
npeFired = true;
|
||||
} finally {
|
||||
if (!npeFired)
|
||||
throw new AssertionError("NPE should have been thrown");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8068254
|
||||
* @summary Method reference uses wrong qualifying type
|
||||
* @author srikanth
|
||||
* @run main MethodReferencePackagePrivateQualifier
|
||||
*/
|
||||
import pkg.B;
|
||||
public class MethodReferencePackagePrivateQualifier {
|
||||
public static void main(String... args) {
|
||||
pkg.B.m();
|
||||
Runnable r = pkg.B::m;
|
||||
r.run();
|
||||
r = B::m;
|
||||
r.run();
|
||||
if (!pkg.B.result.equals("A.m()A.m()A.m()"))
|
||||
throw new AssertionError("Incorrect result");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestFDCCE
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Method references and raw types.
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class MethodReferenceTestFDCCE {
|
||||
|
||||
static void assertCCE(Throwable t) {
|
||||
assertEquals("java.lang.ClassCastException", t.getClass().getName());
|
||||
}
|
||||
|
||||
interface Pred<T> { boolean accept(T x); }
|
||||
|
||||
interface Ps { boolean accept(short x); }
|
||||
|
||||
interface Oo { Object too(int x); }
|
||||
|
||||
interface Reto<T> { T m(); }
|
||||
|
||||
class A {}
|
||||
class B extends A {}
|
||||
|
||||
static boolean isMinor(int x) {
|
||||
return x < 18;
|
||||
}
|
||||
|
||||
static boolean tst(A x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static Object otst(Object x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
static boolean stst(Short x) {
|
||||
return x < 18;
|
||||
}
|
||||
|
||||
static short ritst() {
|
||||
return 123;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceFDPrim1() {
|
||||
Pred<Byte> p = MethodReferenceTestFDCCE::isMinor;
|
||||
Pred p2 = p;
|
||||
assertTrue(p2.accept((Byte)(byte)15));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceFDPrim2() {
|
||||
Pred<Byte> p = MethodReferenceTestFDCCE::isMinor;
|
||||
Pred p2 = p;
|
||||
assertTrue(p2.accept((byte)15));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceFDPrimICCE() {
|
||||
Pred<Byte> p = MethodReferenceTestFDCCE::isMinor;
|
||||
Pred p2 = p;
|
||||
try {
|
||||
p2.accept(15); // should throw CCE
|
||||
fail("Exception should have been thrown");
|
||||
} catch (Throwable t) {
|
||||
assertCCE(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceFDPrimOCCE() {
|
||||
Pred<Byte> p = MethodReferenceTestFDCCE::isMinor;
|
||||
Pred p2 = p;
|
||||
try {
|
||||
p2.accept(new Object()); // should throw CCE
|
||||
fail("Exception should have been thrown");
|
||||
} catch (Throwable t) {
|
||||
assertCCE(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceFDRef() {
|
||||
Pred<B> p = MethodReferenceTestFDCCE::tst;
|
||||
Pred p2 = p;
|
||||
assertTrue(p2.accept(new B()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceFDRefCCE() {
|
||||
Pred<B> p = MethodReferenceTestFDCCE::tst;
|
||||
Pred p2 = p;
|
||||
try {
|
||||
p2.accept(new A()); // should throw CCE
|
||||
fail("Exception should have been thrown");
|
||||
} catch (Throwable t) {
|
||||
assertCCE(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceFDPrimPrim() {
|
||||
Ps p = MethodReferenceTestFDCCE::isMinor;
|
||||
assertTrue(p.accept((byte)15));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceFDPrimBoxed() {
|
||||
Ps p = MethodReferenceTestFDCCE::stst;
|
||||
assertTrue(p.accept((byte)15));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceFDPrimRef() {
|
||||
Oo p = MethodReferenceTestFDCCE::otst;
|
||||
assertEquals("java.lang.Integer", p.too(15).getClass().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceFDRet1() {
|
||||
Reto<Short> p = MethodReferenceTestFDCCE::ritst;
|
||||
assertEquals((Short)(short)123, p.m());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestInnerDefault
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
interface IDSs { String m(String a); }
|
||||
|
||||
interface InDefA {
|
||||
default String xsA__(String s) {
|
||||
return "A__xsA:" + s;
|
||||
}
|
||||
|
||||
default String xsAB_(String s) {
|
||||
return "AB_xsA:" + s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interface InDefB extends InDefA {
|
||||
|
||||
default String xsAB_(String s) {
|
||||
return "AB_xsB:" + s;
|
||||
}
|
||||
|
||||
default String xs_B_(String s) {
|
||||
return "_B_xsB:" + s;
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodReferenceTestInnerDefault implements InDefB {
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceInnerDefault() {
|
||||
(new In()).testMethodReferenceInnerDefault();
|
||||
}
|
||||
|
||||
class In {
|
||||
|
||||
public void testMethodReferenceInnerDefault() {
|
||||
IDSs q;
|
||||
|
||||
q = MethodReferenceTestInnerDefault.this::xsA__;
|
||||
assertEquals("A__xsA:*", q.m("*"));
|
||||
|
||||
q = MethodReferenceTestInnerDefault.this::xsAB_;
|
||||
assertEquals("AB_xsB:*", q.m("*"));
|
||||
|
||||
q = MethodReferenceTestInnerDefault.this::xs_B_;
|
||||
assertEquals("_B_xsB:*", q.m("*"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestInnerInstance
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
public class MethodReferenceTestInnerInstance {
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceInnerInstance() {
|
||||
cia().cib().testMethodReferenceInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceInnerExternal() {
|
||||
cia().cib().testMethodReferenceExternal();
|
||||
}
|
||||
|
||||
interface SI {
|
||||
String m(Integer a);
|
||||
}
|
||||
|
||||
class CIA {
|
||||
|
||||
String xI(Integer i) {
|
||||
return "xI:" + i;
|
||||
}
|
||||
|
||||
public class CIB {
|
||||
|
||||
public void testMethodReferenceInstance() {
|
||||
SI q;
|
||||
|
||||
q = CIA.this::xI;
|
||||
assertEquals("xI:55", q.m(55));
|
||||
}
|
||||
|
||||
public void testMethodReferenceExternal() {
|
||||
SI q;
|
||||
|
||||
q = (new E())::xI;
|
||||
assertEquals("ExI:77", q.m(77));
|
||||
}
|
||||
}
|
||||
|
||||
CIB cib() {
|
||||
return new CIB();
|
||||
}
|
||||
|
||||
class E {
|
||||
|
||||
String xI(Integer i) {
|
||||
return "ExI:" + i;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CIA cia() {
|
||||
return new CIA();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,253 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestInnerVarArgsThis
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
public class MethodReferenceTestInnerVarArgsThis {
|
||||
|
||||
interface NsII {
|
||||
|
||||
String m(Integer a, Integer b);
|
||||
}
|
||||
|
||||
interface Nsiii {
|
||||
|
||||
String m(int a, int b, int c);
|
||||
}
|
||||
|
||||
interface Nsi {
|
||||
|
||||
String m(int a);
|
||||
}
|
||||
|
||||
interface NsaO {
|
||||
|
||||
String m(Object[] a);
|
||||
}
|
||||
|
||||
interface Nsai {
|
||||
|
||||
String m(int[] a);
|
||||
}
|
||||
|
||||
interface Nsvi {
|
||||
|
||||
String m(int... va);
|
||||
}
|
||||
|
||||
class CIA {
|
||||
|
||||
String xvI(Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvI:");
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
String xIvI(Integer f, Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xIvI:");
|
||||
sb.append(f);
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
String xvi(int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xvi:" + sum;
|
||||
}
|
||||
|
||||
String xIvi(Integer f, int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xIvi:(" + f + ")" + sum;
|
||||
}
|
||||
|
||||
String xvO(Object... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvO:");
|
||||
for (Object i : vi) {
|
||||
if (i.getClass().isArray()) {
|
||||
sb.append("[");
|
||||
int len = Array.getLength(i);
|
||||
for (int x = 0; x < len; ++x) {
|
||||
sb.append(Array.get(i, x));
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("]");
|
||||
|
||||
} else {
|
||||
sb.append(i);
|
||||
}
|
||||
sb.append("*");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public class CIB {
|
||||
|
||||
// These should be processed as var args
|
||||
public void testVarArgsNsSuperclass() {
|
||||
NsII q;
|
||||
|
||||
q = CIA.this::xvO;
|
||||
assertEquals("xvO:55*66*", q.m(55, 66));
|
||||
}
|
||||
|
||||
public void testVarArgsNsArray() {
|
||||
Nsai q;
|
||||
|
||||
q = CIA.this::xvO;
|
||||
assertEquals("xvO:[55,66,]*", q.m(new int[]{55, 66}));
|
||||
}
|
||||
|
||||
public void testVarArgsNsII() {
|
||||
NsII q;
|
||||
|
||||
q = CIA.this::xvI;
|
||||
assertEquals("xvI:33-7-", q.m(33, 7));
|
||||
|
||||
q = CIA.this::xIvI;
|
||||
assertEquals("xIvI:5040-", q.m(50, 40));
|
||||
|
||||
q = CIA.this::xvi;
|
||||
assertEquals("xvi:123", q.m(100, 23));
|
||||
|
||||
q = CIA.this::xIvi;
|
||||
assertEquals("xIvi:(9)21", q.m(9, 21));
|
||||
}
|
||||
|
||||
public void testVarArgsNsiii() {
|
||||
Nsiii q;
|
||||
|
||||
q = CIA.this::xvI;
|
||||
assertEquals("xvI:3-2-1-", q.m(3, 2, 1));
|
||||
|
||||
q = CIA.this::xIvI;
|
||||
assertEquals("xIvI:88899-2-", q.m(888, 99, 2));
|
||||
|
||||
q = CIA.this::xvi;
|
||||
assertEquals("xvi:987", q.m(900, 80, 7));
|
||||
|
||||
q = CIA.this::xIvi;
|
||||
assertEquals("xIvi:(333)99", q.m(333, 27, 72));
|
||||
}
|
||||
|
||||
public void testVarArgsNsi() {
|
||||
Nsi q;
|
||||
|
||||
q = CIA.this::xvI;
|
||||
assertEquals("xvI:3-", q.m(3));
|
||||
|
||||
q = CIA.this::xIvI;
|
||||
assertEquals("xIvI:888", q.m(888));
|
||||
|
||||
q = CIA.this::xvi;
|
||||
assertEquals("xvi:900", q.m(900));
|
||||
|
||||
q = CIA.this::xIvi;
|
||||
assertEquals("xIvi:(333)0", q.m(333));
|
||||
}
|
||||
|
||||
// These should NOT be processed as var args
|
||||
public void testVarArgsNsaO() {
|
||||
NsaO q;
|
||||
|
||||
q = CIA.this::xvO;
|
||||
assertEquals("xvO:yo*there*dude*", q.m(new String[]{"yo", "there", "dude"}));
|
||||
}
|
||||
}
|
||||
|
||||
CIB cib() {
|
||||
return new CIB();
|
||||
}
|
||||
|
||||
class E {
|
||||
|
||||
String xI(Integer i) {
|
||||
return "ExI:" + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CIA cia() {
|
||||
return new CIA();
|
||||
}
|
||||
|
||||
// These should be processed as var args
|
||||
@Test
|
||||
public void testVarArgsNsSuperclass() {
|
||||
cia().cib().testVarArgsNsSuperclass();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNsArray() {
|
||||
cia().cib().testVarArgsNsArray();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNsII() {
|
||||
cia().cib().testVarArgsNsII();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNsiii() {
|
||||
cia().cib().testVarArgsNsiii();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNsi() {
|
||||
cia().cib().testVarArgsNsi();
|
||||
}
|
||||
|
||||
// These should NOT be processed as var args
|
||||
|
||||
@Test
|
||||
public void testVarArgsNsaO() {
|
||||
cia().cib().testVarArgsNsaO();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestInstance
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
class MethodReferenceTestInstance_E {
|
||||
String xI(Integer i) {
|
||||
return "ExI:" + i;
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodReferenceTestInstance {
|
||||
|
||||
interface SI { String m(Integer a); }
|
||||
|
||||
String xI(Integer i) {
|
||||
return "xI:" + i;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceInstance() {
|
||||
SI q;
|
||||
|
||||
q = this::xI;
|
||||
assertEquals("xI:55", q.m(55));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceExternal() {
|
||||
SI q;
|
||||
|
||||
q = (new MethodReferenceTestInstance_E())::xI;
|
||||
assertEquals("ExI:77", q.m(77));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestKinds
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
public class MethodReferenceTestKinds extends MethodReferenceTestKindsSup {
|
||||
|
||||
interface S0 { String get(); }
|
||||
interface S1 { String get(MethodReferenceTestKinds x); }
|
||||
interface S2 { String get(MethodReferenceTestKinds x, MethodReferenceTestKinds y); }
|
||||
|
||||
interface SXN0 { MethodReferenceTestKindsBase make(MethodReferenceTestKinds x); }
|
||||
interface SXN1 { MethodReferenceTestKindsBase make(MethodReferenceTestKinds x, String str); }
|
||||
|
||||
interface SN0 { MethodReferenceTestKindsBase make(); }
|
||||
interface SN1 { MethodReferenceTestKindsBase make(String x); }
|
||||
|
||||
class In extends MethodReferenceTestKindsBase {
|
||||
In(String val) {
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
In() {
|
||||
this("blank");
|
||||
}
|
||||
}
|
||||
|
||||
String instanceMethod0() { return "IM:0-" + this; }
|
||||
String instanceMethod1(MethodReferenceTestKinds x) { return "IM:1-" + this + x; }
|
||||
|
||||
static String staticMethod0() { return "SM:0"; }
|
||||
static String staticMethod1(MethodReferenceTestKinds x) { return "SM:1-" + x; }
|
||||
|
||||
MethodReferenceTestKinds() {
|
||||
super("blank");
|
||||
}
|
||||
|
||||
MethodReferenceTestKinds inst(String val) {
|
||||
var inst = new MethodReferenceTestKinds();
|
||||
inst.val = val; // simulate `MethodReferenceTestKinds(String val)` constructor
|
||||
return inst;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRBound() {
|
||||
S0 var = this::instanceMethod0;
|
||||
assertEquals("IM:0-MethodReferenceTestKinds(blank)", var.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRBoundArg() {
|
||||
S1 var = this::instanceMethod1;
|
||||
assertEquals("IM:1-MethodReferenceTestKinds(blank)MethodReferenceTestKinds(arg)", var.get(inst("arg")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRUnbound() {
|
||||
S1 var = MethodReferenceTestKinds::instanceMethod0;
|
||||
assertEquals("IM:0-MethodReferenceTestKinds(rcvr)", var.get(inst("rcvr")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRUnboundArg() {
|
||||
S2 var = MethodReferenceTestKinds::instanceMethod1;
|
||||
assertEquals("IM:1-MethodReferenceTestKinds(rcvr)MethodReferenceTestKinds(arg)", var.get(inst("rcvr"), inst("arg")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRSuper() {
|
||||
S0 var = super::instanceMethod0;
|
||||
assertEquals("SIM:0-MethodReferenceTestKinds(blank)", var.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRSuperArg() {
|
||||
S1 var = super::instanceMethod1;
|
||||
assertEquals("SIM:1-MethodReferenceTestKinds(blank)MethodReferenceTestKinds(arg)", var.get(inst("arg")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRStatic() {
|
||||
S0 var = MethodReferenceTestKinds::staticMethod0;
|
||||
assertEquals("SM:0", var.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRStaticArg() {
|
||||
S1 var = MethodReferenceTestKinds::staticMethod1;
|
||||
assertEquals("SM:1-MethodReferenceTestKinds(arg)", var.get(inst("arg")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRTopLevel() {
|
||||
SN0 var = MethodReferenceTestKindsBase::new;
|
||||
assertEquals("MethodReferenceTestKindsBase(blank)", var.make().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRTopLevelArg() {
|
||||
SN1 var = MethodReferenceTestKindsBase::new;
|
||||
assertEquals("MethodReferenceTestKindsBase(name)", var.make("name").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRImplicitInner() {
|
||||
SN0 var = MethodReferenceTestKinds.In::new;
|
||||
assertEquals("In(blank)", var.make().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMRImplicitInnerArg() {
|
||||
SN1 var = MethodReferenceTestKinds.In::new;
|
||||
assertEquals("In(name)", var.make("name").toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class MethodReferenceTestKindsBase {
|
||||
String val = "unset";
|
||||
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "(" + val + ")";
|
||||
}
|
||||
|
||||
MethodReferenceTestKindsBase(String val) {
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
MethodReferenceTestKindsBase() {
|
||||
this("blank");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MethodReferenceTestKindsSup extends MethodReferenceTestKindsBase {
|
||||
String instanceMethod0() { return "SIM:0-" + this; }
|
||||
String instanceMethod1(MethodReferenceTestKinds x) { return "SIM:1-" + this + x; }
|
||||
|
||||
MethodReferenceTestKindsSup(String val) {
|
||||
super(val);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8028739
|
||||
* @summary javac generates incorrect descriptor for MethodHandle::invoke
|
||||
* @run junit MethodReferenceTestMethodHandle
|
||||
*/
|
||||
|
||||
import java.lang.invoke.*;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MethodReferenceTestMethodHandle {
|
||||
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
|
||||
interface ReplaceItf {
|
||||
Object apply(String a, char b, char c) throws Throwable;
|
||||
}
|
||||
|
||||
interface FormatItf {
|
||||
Object apply(String a, Object... args) throws Throwable;
|
||||
}
|
||||
|
||||
interface AddItf {
|
||||
void apply(List st, int idx, Object v) throws Throwable;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVirtual() throws Throwable {
|
||||
|
||||
MethodType mt = MethodType.methodType(String.class, char.class, char.class);
|
||||
MethodHandle ms = lookup.findVirtual(String.class, "replace", mt);
|
||||
|
||||
// --- String.replace(String, char, char) ---
|
||||
|
||||
assertEquals("oome otring to oearch", ms.invoke("some string to search", 's', 'o'));
|
||||
|
||||
ReplaceItf f1 = (a, b, c) -> ms.invoke(a,b,c);
|
||||
assertEquals("oome otring to oearch", f1.apply("some string to search", 's', 'o'));
|
||||
|
||||
ReplaceItf f2 = ms::invoke;
|
||||
assertEquals("oome otring to oearch", f2.apply("some string to search", 's', 'o'));
|
||||
assertEquals("oome otring to oearch", f2.apply("some string to search", new Character('s'), 'o'));
|
||||
assertEquals("oome otring to oearch", ((ReplaceItf) ms::invoke).apply("some string to search", 's', 'o'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatic() throws Throwable {
|
||||
MethodType fmt = MethodType.methodType(String.class, String.class, (new Object[1]).getClass());
|
||||
MethodHandle fms = lookup.findStatic(String.class, "format", fmt);
|
||||
|
||||
// --- String.format(String, Object...) ---
|
||||
|
||||
assertEquals("Testing One 2 3", fms.invoke("Testing %s %d %x", "One", new Integer(2), 3));
|
||||
|
||||
FormatItf ff2 = fms::invoke;
|
||||
assertEquals("Testing One 2 3", ff2.apply("Testing %s %d %x", "One", new Integer(2), 3));
|
||||
assertEquals("Testing One 2 3", ((FormatItf) fms::invoke).apply("Testing %s %d %x", "One", new Integer(2), 3));
|
||||
assertEquals("Testing One 2 3 four", ff2.apply("Testing %s %d %x %s", "One", new Integer(2), 3, "four"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVoid() throws Throwable {
|
||||
MethodType pmt = MethodType.methodType(void.class, int.class, Object.class);
|
||||
MethodHandle pms = lookup.findVirtual(List.class, "add", pmt);
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
// --- List.add(int,String) ---
|
||||
|
||||
pms.invoke(list, 0, "Hi");
|
||||
|
||||
AddItf pf2 = pms::invoke;
|
||||
pf2.apply(list, 1, "there");
|
||||
AddItf pf3 = pms::invokeExact;
|
||||
pf3.apply(list, 2, "you");
|
||||
assertEquals("Hi", list.get(0));
|
||||
assertEquals("there", list.get(1));
|
||||
assertEquals("you", list.get(2));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestNew
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
public class MethodReferenceTestNew {
|
||||
|
||||
interface M0<T> {
|
||||
|
||||
T m();
|
||||
}
|
||||
|
||||
static class N0 {
|
||||
|
||||
N0() {
|
||||
}
|
||||
}
|
||||
|
||||
interface M1<T> {
|
||||
|
||||
T m(Integer a);
|
||||
}
|
||||
|
||||
static class N1 {
|
||||
|
||||
int i;
|
||||
|
||||
N1(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
}
|
||||
|
||||
interface M2<T> {
|
||||
|
||||
T m(Integer n, String o);
|
||||
}
|
||||
|
||||
static class N2 {
|
||||
|
||||
Number n;
|
||||
Object o;
|
||||
|
||||
N2(Number n, Object o) {
|
||||
this.n = n;
|
||||
this.o = o;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "N2(" + n + "," + o + ")";
|
||||
}
|
||||
}
|
||||
|
||||
interface MV {
|
||||
|
||||
NV m(Integer ai, int i);
|
||||
}
|
||||
|
||||
static class NV {
|
||||
|
||||
int i;
|
||||
|
||||
NV(int... v) {
|
||||
i = 0;
|
||||
for (int x : v) {
|
||||
i += x;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "NV(" + i + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorReference0() {
|
||||
M0<N0> q;
|
||||
|
||||
q = N0::new;
|
||||
assertEquals("N0", q.m().getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorReference1() {
|
||||
M1<N1> q;
|
||||
|
||||
q = N1::new;
|
||||
assertEquals("N1", q.m(14).getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorReference2() {
|
||||
M2<N2> q;
|
||||
|
||||
q = N2::new;
|
||||
assertEquals("N2(7,hi)", q.m(7, "hi").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorReferenceVarArgs() {
|
||||
MV q;
|
||||
|
||||
q = NV::new;
|
||||
assertEquals("NV(50)", q.m(5, 45).toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestNewInner
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
public class MethodReferenceTestNewInner {
|
||||
|
||||
String note = "NO NOTE";
|
||||
|
||||
interface M0<T> {
|
||||
|
||||
T m();
|
||||
}
|
||||
|
||||
interface MP<T> {
|
||||
|
||||
T m(MethodReferenceTestNewInner m);
|
||||
}
|
||||
|
||||
class N0 {
|
||||
|
||||
N0() {
|
||||
}
|
||||
}
|
||||
|
||||
interface M1<T> {
|
||||
|
||||
T m(Integer a);
|
||||
}
|
||||
|
||||
class N1 {
|
||||
|
||||
int i;
|
||||
|
||||
N1(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
}
|
||||
|
||||
interface M2<T> {
|
||||
|
||||
T m(Integer n, String o);
|
||||
}
|
||||
|
||||
class N2 {
|
||||
|
||||
Number n;
|
||||
Object o;
|
||||
|
||||
N2(Number n, Object o) {
|
||||
this.n = n;
|
||||
this.o = o;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return note + ":N2(" + n + "," + o + ")";
|
||||
}
|
||||
}
|
||||
|
||||
interface MV {
|
||||
|
||||
NV m(Integer ai, int i);
|
||||
}
|
||||
|
||||
class NV {
|
||||
|
||||
int i;
|
||||
|
||||
NV(int... v) {
|
||||
i = 0;
|
||||
for (int x : v) {
|
||||
i += x;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return note + ":NV(" + i + ")";
|
||||
}
|
||||
}
|
||||
|
||||
/* unbound constructor case not supported anymore (dropped by EG)
|
||||
public static void testConstructorReferenceP() {
|
||||
MP<N0> q;
|
||||
|
||||
q = N0::new;
|
||||
assertEquals(q.m(new MethodReferenceTestNewInner()).getClass().getSimpleName(), "N0");
|
||||
}
|
||||
*/
|
||||
@Test
|
||||
public void testConstructorReference0() {
|
||||
M0<N0> q;
|
||||
|
||||
q = N0::new;
|
||||
assertEquals("N0", q.m().getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorReference1() {
|
||||
M1<N1> q;
|
||||
|
||||
q = N1::new;
|
||||
assertEquals("N1", q.m(14).getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorReference2() {
|
||||
M2<N2> q;
|
||||
|
||||
note = "T2";
|
||||
q = N2::new;
|
||||
assertEquals("T2:N2(7,hi)", q.m(7, "hi").toString());
|
||||
}
|
||||
|
||||
/***
|
||||
public void testConstructorReferenceVarArgs() {
|
||||
MV q;
|
||||
|
||||
note = "TVA";
|
||||
q = NV::new;
|
||||
assertEquals(q.m(5, 45).toString(), "TNV:NV(50)");
|
||||
}
|
||||
***/
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8011591
|
||||
* @summary BootstrapMethodError when capturing constructor ref to local classes
|
||||
* @run junit MethodReferenceTestNewInnerImplicitArgs
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test the case that a constructor has implicit parameters added to
|
||||
* access local variables and that this constructor is used in a
|
||||
* method reference.
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
public class MethodReferenceTestNewInnerImplicitArgs {
|
||||
|
||||
|
||||
static class S {
|
||||
String b;
|
||||
S(String s, String s2) { b = s + s2; }
|
||||
}
|
||||
|
||||
interface I {
|
||||
S m();
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
S m(int i, int j);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorReferenceImplicitParameters() {
|
||||
String title = "Hey";
|
||||
String a2 = "!!!";
|
||||
class MS extends S {
|
||||
MS() {
|
||||
super(title, a2);
|
||||
}
|
||||
}
|
||||
|
||||
I result = MS::new;
|
||||
assertEquals("Hey!!!", result.m().b);
|
||||
|
||||
class MS2 extends S {
|
||||
MS2(int x, int y) {
|
||||
super(title+x, a2+y);
|
||||
}
|
||||
}
|
||||
|
||||
I2 result2 = MS2::new;
|
||||
assertEquals("Hey8!!!4", result2.m(8, 4).b);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestSueCase1
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
public class MethodReferenceTestSueCase1 {
|
||||
|
||||
public interface Sam2<T> { public String get(T target, String s); }
|
||||
|
||||
String instanceMethod(String s) { return "2"; }
|
||||
Sam2<MethodReferenceTestSueCase1> var = MethodReferenceTestSueCase1::instanceMethod;
|
||||
|
||||
String m() { return var.get(new MethodReferenceTestSueCase1(), ""); }
|
||||
|
||||
@Test
|
||||
public void testSueCase1() {
|
||||
assertEquals("2", m());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestSueCase2
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
public class MethodReferenceTestSueCase2 {
|
||||
|
||||
public interface Sam2<T> { public String get(T target, String s); }
|
||||
|
||||
String instanceMethod(String s) { return "2"; }
|
||||
static Sam2<MethodReferenceTestSueCase2> var = MethodReferenceTestSueCase2::instanceMethod;
|
||||
|
||||
String m() { return var.get(new MethodReferenceTestSueCase2(), ""); }
|
||||
|
||||
@Test
|
||||
public void testSueCase2() {
|
||||
assertEquals("2", m());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestSueCase4
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
public class MethodReferenceTestSueCase4 {
|
||||
|
||||
public interface Sam2<T> { public String get(T target, String s); }
|
||||
|
||||
Sam2<Target> var = new Object().equals(new Object()) ? Target::instanceMethod : Target::instanceMethod;
|
||||
|
||||
String m() {
|
||||
return var.get(new Target(), "");
|
||||
}
|
||||
|
||||
static class Target {
|
||||
String instanceMethod(String s) { return "2"; }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSueCase4() {
|
||||
assertEquals("2", m());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestSuper
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
interface SPRI { String m(String a); }
|
||||
|
||||
class SPRA {
|
||||
String xsA__(String s) {
|
||||
return "A__xsA:" + s;
|
||||
}
|
||||
|
||||
String xsA_M(String s) {
|
||||
return "A_MxsA:" + s;
|
||||
}
|
||||
|
||||
String xsAB_(String s) {
|
||||
return "AB_xsA:" + s;
|
||||
}
|
||||
|
||||
String xsABM(String s) {
|
||||
return "ABMxsA:" + s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SPRB extends SPRA {
|
||||
|
||||
String xsAB_(String s) {
|
||||
return "AB_xsB:" + s;
|
||||
}
|
||||
|
||||
String xsABM(String s) {
|
||||
return "ABMxsB:" + s;
|
||||
}
|
||||
|
||||
String xs_B_(String s) {
|
||||
return "_B_xsB:" + s;
|
||||
}
|
||||
|
||||
String xs_BM(String s) {
|
||||
return "_BMxsB:" + s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class MethodReferenceTestSuper extends SPRB {
|
||||
|
||||
String xsA_M(String s) {
|
||||
return "A_MxsM:" + s;
|
||||
}
|
||||
|
||||
|
||||
String xsABM(String s) {
|
||||
return "ABMxsM:" + s;
|
||||
}
|
||||
|
||||
String xs_BM(String s) {
|
||||
return "_BMxsM:" + s;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceSuper() {
|
||||
SPRI q;
|
||||
|
||||
q = super::xsA__;
|
||||
assertEquals("A__xsA:*", q.m("*"));
|
||||
|
||||
q = super::xsA_M;
|
||||
assertEquals("A_MxsA:*", q.m("*"));
|
||||
|
||||
q = super::xsAB_;
|
||||
assertEquals("AB_xsB:*", q.m("*"));
|
||||
|
||||
q = super::xsABM;
|
||||
assertEquals("ABMxsB:*", q.m("*"));
|
||||
|
||||
q = super::xs_B_;
|
||||
assertEquals("_B_xsB:*", q.m("*"));
|
||||
|
||||
q = super::xs_BM;
|
||||
assertEquals("_BMxsB:*", q.m("*"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestSuperDefault
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
interface DSPRI { String m(String a); }
|
||||
|
||||
interface DSPRA {
|
||||
default String xsA__(String s) {
|
||||
return "A__xsA:" + s;
|
||||
}
|
||||
|
||||
default String xsAB_(String s) {
|
||||
return "AB_xsA:" + s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interface DSPRB extends DSPRA {
|
||||
|
||||
default String xsAB_(String s) {
|
||||
return "AB_xsB:" + s;
|
||||
}
|
||||
|
||||
default String xs_B_(String s) {
|
||||
return "_B_xsB:" + s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class MethodReferenceTestSuperDefault implements DSPRB {
|
||||
|
||||
@Test
|
||||
public void testMethodReferenceSuper() {
|
||||
DSPRI q;
|
||||
|
||||
q = DSPRB.super::xsA__;
|
||||
assertEquals("A__xsA:*", q.m("*"));
|
||||
|
||||
q = DSPRB.super::xsAB_;
|
||||
assertEquals("AB_xsB:*", q.m("*"));
|
||||
|
||||
q = DSPRB.super::xs_B_;
|
||||
assertEquals("_B_xsB:*", q.m("*"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestTypeConversion
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
class MethodReferenceTestTypeConversion_E<T> {
|
||||
T xI(T t) { return t; }
|
||||
}
|
||||
|
||||
public class MethodReferenceTestTypeConversion {
|
||||
|
||||
interface ISi { int m(Short a); }
|
||||
|
||||
interface ICc { char m(Character a); }
|
||||
|
||||
@Test
|
||||
public void testUnboxObjectToNumberWiden() {
|
||||
ISi q = (new MethodReferenceTestTypeConversion_E<Short>())::xI;
|
||||
assertEquals((short)77, q.m((short)77));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnboxObjectToChar() {
|
||||
ICc q = (new MethodReferenceTestTypeConversion_E<Character>())::xI;
|
||||
assertEquals('@', q.m('@'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestVarArgs
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
public class MethodReferenceTestVarArgs {
|
||||
|
||||
interface SII {
|
||||
|
||||
String m(Integer a, Integer b);
|
||||
}
|
||||
|
||||
interface Siii {
|
||||
|
||||
String m(int a, int b, int c);
|
||||
}
|
||||
|
||||
interface Si {
|
||||
|
||||
String m(int a);
|
||||
}
|
||||
|
||||
interface SaO {
|
||||
|
||||
String m(Object[] a);
|
||||
}
|
||||
|
||||
interface Sai {
|
||||
|
||||
String m(int[] a);
|
||||
}
|
||||
|
||||
interface Svi {
|
||||
|
||||
String m(int... va);
|
||||
}
|
||||
|
||||
// These should be processed as var args
|
||||
|
||||
static String xvI(Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvI:");
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static String xIvI(Integer f, Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xIvI:");
|
||||
sb.append(f);
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static String xvi(int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xvi:" + sum;
|
||||
}
|
||||
|
||||
static String xIvi(Integer f, int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xIvi:(" + f + ")" + sum;
|
||||
}
|
||||
|
||||
static String xvO(Object... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvO:");
|
||||
for (Object i : vi) {
|
||||
if (i.getClass().isArray()) {
|
||||
sb.append("[");
|
||||
int len = Array.getLength(i);
|
||||
for (int x = 0; x < len; ++x) {
|
||||
sb.append(Array.get(i, x));
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("]");
|
||||
|
||||
} else {
|
||||
sb.append(i);
|
||||
}
|
||||
sb.append("*");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsSuperclass() {
|
||||
SII q;
|
||||
|
||||
q = MethodReferenceTestVarArgs::xvO;
|
||||
assertEquals("xvO:55*66*", q.m(55,66));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsArray() {
|
||||
Sai q;
|
||||
|
||||
q = MethodReferenceTestVarArgs::xvO;
|
||||
assertEquals("xvO:[55,66,]*", q.m(new int[] { 55,66 } ));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsII() {
|
||||
SII q;
|
||||
|
||||
q = MethodReferenceTestVarArgs::xvI;
|
||||
assertEquals("xvI:33-7-", q.m(33,7));
|
||||
|
||||
q = MethodReferenceTestVarArgs::xIvI;
|
||||
assertEquals("xIvI:5040-", q.m(50,40));
|
||||
|
||||
q = MethodReferenceTestVarArgs::xvi;
|
||||
assertEquals("xvi:123", q.m(100,23));
|
||||
|
||||
q = MethodReferenceTestVarArgs::xIvi;
|
||||
assertEquals("xIvi:(9)21", q.m(9,21));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsiii() {
|
||||
Siii q;
|
||||
|
||||
q = MethodReferenceTestVarArgs::xvI;
|
||||
assertEquals("xvI:3-2-1-", q.m(3, 2, 1));
|
||||
|
||||
q = MethodReferenceTestVarArgs::xIvI;
|
||||
assertEquals("xIvI:88899-2-", q.m(888, 99, 2));
|
||||
|
||||
q = MethodReferenceTestVarArgs::xvi;
|
||||
assertEquals("xvi:987", q.m(900,80,7));
|
||||
|
||||
q = MethodReferenceTestVarArgs::xIvi;
|
||||
assertEquals("xIvi:(333)99", q.m(333,27, 72));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsi() {
|
||||
Si q;
|
||||
|
||||
q = MethodReferenceTestVarArgs::xvI;
|
||||
assertEquals("xvI:3-", q.m(3));
|
||||
|
||||
q = MethodReferenceTestVarArgs::xIvI;
|
||||
assertEquals("xIvI:888", q.m(888));
|
||||
|
||||
q = MethodReferenceTestVarArgs::xvi;
|
||||
assertEquals("xvi:900", q.m(900));
|
||||
|
||||
q = MethodReferenceTestVarArgs::xIvi;
|
||||
assertEquals("xIvi:(333)0", q.m(333));
|
||||
}
|
||||
|
||||
// These should NOT be processed as var args
|
||||
|
||||
@Test
|
||||
public void testVarArgsaO() {
|
||||
SaO q;
|
||||
|
||||
q = MethodReferenceTestVarArgs::xvO;
|
||||
assertEquals("xvO:yo*there*dude*", q.m(new String[] { "yo", "there", "dude" }));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,194 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestVarArgsExt
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
interface NXII { String m(Integer a, Integer b); }
|
||||
|
||||
interface NXiii { String m(int a, int b, int c); }
|
||||
|
||||
interface NXi { String m(int a); }
|
||||
|
||||
interface NXaO { String m(Object[] a); }
|
||||
|
||||
interface NXai { String m(int[] a); }
|
||||
|
||||
interface NXvi { String m(int... va); }
|
||||
|
||||
public class MethodReferenceTestVarArgsExt {
|
||||
|
||||
// These should be processed as var args
|
||||
|
||||
@Test
|
||||
public void testVarArgsNXSuperclass() {
|
||||
NXII q;
|
||||
|
||||
q = (new Ext())::xvO;
|
||||
assertEquals("xvO:55*66*", q.m(55,66));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNXArray() {
|
||||
NXai q;
|
||||
|
||||
q = (new Ext())::xvO;
|
||||
assertEquals("xvO:[55,66,]*", q.m(new int[] { 55,66 } ));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNXII() {
|
||||
NXII q;
|
||||
|
||||
q = (new Ext())::xvI;
|
||||
assertEquals("xvI:33-7-", q.m(33,7));
|
||||
|
||||
q = (new Ext())::xIvI;
|
||||
assertEquals("xIvI:5040-", q.m(50,40));
|
||||
|
||||
q = (new Ext())::xvi;
|
||||
assertEquals("xvi:123", q.m(100,23));
|
||||
|
||||
q = (new Ext())::xIvi;
|
||||
assertEquals("xIvi:(9)21", q.m(9,21));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNXiii() {
|
||||
NXiii q;
|
||||
|
||||
q = (new Ext())::xvI;
|
||||
assertEquals("xvI:3-2-1-", q.m(3, 2, 1));
|
||||
|
||||
q = (new Ext())::xIvI;
|
||||
assertEquals("xIvI:88899-2-", q.m(888, 99, 2));
|
||||
|
||||
q = (new Ext())::xvi;
|
||||
assertEquals("xvi:987", q.m(900,80,7));
|
||||
|
||||
q = (new Ext())::xIvi;
|
||||
assertEquals("xIvi:(333)99", q.m(333,27, 72));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNXi() {
|
||||
NXi q;
|
||||
|
||||
q = (new Ext())::xvI;
|
||||
assertEquals("xvI:3-", q.m(3));
|
||||
|
||||
q = (new Ext())::xIvI;
|
||||
assertEquals("xIvI:888", q.m(888));
|
||||
|
||||
q = (new Ext())::xvi;
|
||||
assertEquals("xvi:900", q.m(900));
|
||||
|
||||
q = (new Ext())::xIvi;
|
||||
assertEquals("xIvi:(333)0", q.m(333));
|
||||
}
|
||||
|
||||
// These should NOT be processed as var args
|
||||
|
||||
@Test
|
||||
public void testVarArgsNXaO() {
|
||||
NXaO q;
|
||||
|
||||
q = (new Ext())::xvO;
|
||||
assertEquals("xvO:yo*there*dude*", q.m(new String[] { "yo", "there", "dude" }));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Ext {
|
||||
|
||||
String xvI(Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvI:");
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
String xIvI(Integer f, Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xIvI:");
|
||||
sb.append(f);
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
String xvi(int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xvi:" + sum;
|
||||
}
|
||||
|
||||
String xIvi(Integer f, int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xIvi:(" + f + ")" + sum;
|
||||
}
|
||||
|
||||
String xvO(Object... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvO:");
|
||||
for (Object i : vi) {
|
||||
if (i.getClass().isArray()) {
|
||||
sb.append("[");
|
||||
int len = Array.getLength(i);
|
||||
for (int x = 0; x < len; ++x) {
|
||||
sb.append(Array.get(i, x));
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("]");
|
||||
|
||||
} else {
|
||||
sb.append(i);
|
||||
}
|
||||
sb.append("*");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,210 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestVarArgsSuper
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
class MethodReferenceTestVarArgsSuper_Sub {
|
||||
|
||||
String xvI(Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvI:");
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
String xIvI(Integer f, Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xIvI:");
|
||||
sb.append(f);
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
String xvi(int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xvi:" + sum;
|
||||
}
|
||||
|
||||
String xIvi(Integer f, int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xIvi:(" + f + ")" + sum;
|
||||
}
|
||||
|
||||
String xvO(Object... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvO:");
|
||||
for (Object i : vi) {
|
||||
if (i.getClass().isArray()) {
|
||||
sb.append("[");
|
||||
int len = Array.getLength(i);
|
||||
for (int x = 0; x < len; ++x) {
|
||||
sb.append(Array.get(i, x));
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("]");
|
||||
|
||||
} else {
|
||||
sb.append(i);
|
||||
}
|
||||
sb.append("*");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodReferenceTestVarArgsSuper extends MethodReferenceTestVarArgsSuper_Sub {
|
||||
|
||||
interface SPRII { String m(Integer a, Integer b); }
|
||||
|
||||
interface SPRiii { String m(int a, int b, int c); }
|
||||
|
||||
interface SPRi { String m(int a); }
|
||||
|
||||
interface SPRaO { String m(Object[] a); }
|
||||
|
||||
interface SPRai { String m(int[] a); }
|
||||
|
||||
interface SPRvi { String m(int... va); }
|
||||
|
||||
String xvI(Integer... vi) {
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
String xIvI(Integer f, Integer... vi) {
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
String xvi(int... vi) {
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
String xIvi(Integer f, int... vi) {
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
String xvO(Object... vi) {
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
// These should be processed as var args
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRSuperclass() {
|
||||
SPRII q;
|
||||
|
||||
q = super::xvO;
|
||||
assertEquals("xvO:55*66*", q.m(55,66));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRArray() {
|
||||
SPRai q;
|
||||
|
||||
q = super::xvO;
|
||||
assertEquals("xvO:[55,66,]*", q.m(new int[] { 55,66 } ));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRII() {
|
||||
SPRII q;
|
||||
|
||||
q = super::xvI;
|
||||
assertEquals("xvI:33-7-", q.m(33,7));
|
||||
|
||||
q = super::xIvI;
|
||||
assertEquals("xIvI:5040-", q.m(50,40));
|
||||
|
||||
q = super::xvi;
|
||||
assertEquals("xvi:123", q.m(100,23));
|
||||
|
||||
q = super::xIvi;
|
||||
assertEquals("xIvi:(9)21", q.m(9,21));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRiii() {
|
||||
SPRiii q;
|
||||
|
||||
q = super::xvI;
|
||||
assertEquals("xvI:3-2-1-", q.m(3, 2, 1));
|
||||
|
||||
q = super::xIvI;
|
||||
assertEquals("xIvI:88899-2-", q.m(888, 99, 2));
|
||||
|
||||
q = super::xvi;
|
||||
assertEquals("xvi:987", q.m(900,80,7));
|
||||
|
||||
q = super::xIvi;
|
||||
assertEquals("xIvi:(333)99", q.m(333,27, 72));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRi() {
|
||||
SPRi q;
|
||||
|
||||
q = super::xvI;
|
||||
assertEquals("xvI:3-", q.m(3));
|
||||
|
||||
q = super::xIvI;
|
||||
assertEquals("xIvI:888", q.m(888));
|
||||
|
||||
q = super::xvi;
|
||||
assertEquals("xvi:900", q.m(900));
|
||||
|
||||
q = super::xIvi;
|
||||
assertEquals("xIvi:(333)0", q.m(333));
|
||||
}
|
||||
|
||||
// These should NOT be processed as var args
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRaO() {
|
||||
SPRaO q;
|
||||
|
||||
q = super::xvO;
|
||||
assertEquals("xvO:yo*there*dude*", q.m(new String[] { "yo", "there", "dude" }));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestVarArgsSuperDefault
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
interface MethodReferenceTestVarArgsSuperDefault_I {
|
||||
|
||||
default String xvI(Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvI:");
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
default String xIvI(Integer f, Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xIvI:");
|
||||
sb.append(f);
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
default String xvi(int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xvi:" + sum;
|
||||
}
|
||||
|
||||
default String xIvi(Integer f, int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xIvi:(" + f + ")" + sum;
|
||||
}
|
||||
|
||||
default String xvO(Object... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvO:");
|
||||
for (Object i : vi) {
|
||||
if (i.getClass().isArray()) {
|
||||
sb.append("[");
|
||||
int len = Array.getLength(i);
|
||||
for (int x = 0; x < len; ++x) {
|
||||
sb.append(Array.get(i, x));
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("]");
|
||||
|
||||
} else {
|
||||
sb.append(i);
|
||||
}
|
||||
sb.append("*");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodReferenceTestVarArgsSuperDefault implements MethodReferenceTestVarArgsSuperDefault_I {
|
||||
|
||||
interface DSPRII { String m(Integer a, Integer b); }
|
||||
|
||||
interface DSPRiii { String m(int a, int b, int c); }
|
||||
|
||||
interface DSPRi { String m(int a); }
|
||||
|
||||
interface DSPRaO { String m(Object[] a); }
|
||||
|
||||
interface DSPRai { String m(int[] a); }
|
||||
|
||||
interface DSPRvi { String m(int... va); }
|
||||
|
||||
// These should be processed as var args
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRSuperclass() {
|
||||
DSPRII q;
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xvO;
|
||||
assertEquals("xvO:55*66*", q.m(55,66));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRArray() {
|
||||
DSPRai q;
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xvO;
|
||||
assertEquals("xvO:[55,66,]*", q.m(new int[] { 55,66 } ));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRII() {
|
||||
DSPRII q;
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xvI;
|
||||
assertEquals("xvI:33-7-", q.m(33,7));
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvI;
|
||||
assertEquals("xIvI:5040-", q.m(50,40));
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xvi;
|
||||
assertEquals("xvi:123", q.m(100,23));
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvi;
|
||||
assertEquals("xIvi:(9)21", q.m(9,21));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRiii() {
|
||||
DSPRiii q;
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xvI;
|
||||
assertEquals("xvI:3-2-1-", q.m(3, 2, 1));
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvI;
|
||||
assertEquals("xIvI:88899-2-", q.m(888, 99, 2));
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xvi;
|
||||
assertEquals("xvi:987", q.m(900,80,7));
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvi;
|
||||
assertEquals("xIvi:(333)99", q.m(333,27, 72));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRi() {
|
||||
DSPRi q;
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xvI;
|
||||
assertEquals("xvI:3-", q.m(3));
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvI;
|
||||
assertEquals("xIvI:888", q.m(888));
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xvi;
|
||||
assertEquals("xvi:900", q.m(900));
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xIvi;
|
||||
assertEquals("xIvi:(333)0", q.m(333));
|
||||
}
|
||||
|
||||
// These should NOT be processed as var args
|
||||
|
||||
@Test
|
||||
public void testVarArgsSPRaO() {
|
||||
DSPRaO q;
|
||||
|
||||
q = MethodReferenceTestVarArgsSuperDefault_I.super::xvO;
|
||||
assertEquals("xvO:yo*there*dude*", q.m(new String[] { "yo", "there", "dude" }));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8003639
|
||||
* @summary convert lambda testng tests to jtreg and add them
|
||||
* @run junit MethodReferenceTestVarArgsThis
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Robert Field
|
||||
*/
|
||||
|
||||
interface NsII { String m(Integer a, Integer b); }
|
||||
|
||||
interface Nsiii { String m(int a, int b, int c); }
|
||||
|
||||
interface Nsi { String m(int a); }
|
||||
|
||||
interface NsaO { String m(Object[] a); }
|
||||
|
||||
interface Nsai { String m(int[] a); }
|
||||
|
||||
interface Nsvi { String m(int... va); }
|
||||
|
||||
public class MethodReferenceTestVarArgsThis {
|
||||
|
||||
// These should be processed as var args
|
||||
|
||||
String xvI(Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvI:");
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
String xIvI(Integer f, Integer... vi) {
|
||||
StringBuilder sb = new StringBuilder("xIvI:");
|
||||
sb.append(f);
|
||||
for (Integer i : vi) {
|
||||
sb.append(i);
|
||||
sb.append("-");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
String xvi(int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xvi:" + sum;
|
||||
}
|
||||
|
||||
String xIvi(Integer f, int... vi) {
|
||||
int sum = 0;
|
||||
for (int i : vi) {
|
||||
sum += i;
|
||||
}
|
||||
return "xIvi:(" + f + ")" + sum;
|
||||
}
|
||||
|
||||
String xvO(Object... vi) {
|
||||
StringBuilder sb = new StringBuilder("xvO:");
|
||||
for (Object i : vi) {
|
||||
if (i.getClass().isArray()) {
|
||||
sb.append("[");
|
||||
int len = Array.getLength(i);
|
||||
for (int x = 0; x < len; ++x) {
|
||||
sb.append(Array.get(i, x));
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("]");
|
||||
|
||||
} else {
|
||||
sb.append(i);
|
||||
}
|
||||
sb.append("*");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNsSuperclass() {
|
||||
NsII q;
|
||||
|
||||
q = this::xvO;
|
||||
assertEquals("xvO:55*66*", q.m(55,66));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNsArray() {
|
||||
Nsai q;
|
||||
|
||||
q = this::xvO;
|
||||
assertEquals("xvO:[55,66,]*", q.m(new int[] { 55,66 } ));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNsII() {
|
||||
NsII q;
|
||||
|
||||
q = this::xvI;
|
||||
assertEquals("xvI:33-7-", q.m(33,7));
|
||||
|
||||
q = this::xIvI;
|
||||
assertEquals("xIvI:5040-", q.m(50,40));
|
||||
|
||||
q = this::xvi;
|
||||
assertEquals("xvi:123", q.m(100,23));
|
||||
|
||||
q = this::xIvi;
|
||||
assertEquals("xIvi:(9)21", q.m(9,21));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNsiii() {
|
||||
Nsiii q;
|
||||
|
||||
q = this::xvI;
|
||||
assertEquals("xvI:3-2-1-", q.m(3, 2, 1));
|
||||
|
||||
q = this::xIvI;
|
||||
assertEquals("xIvI:88899-2-", q.m(888, 99, 2));
|
||||
|
||||
q = this::xvi;
|
||||
assertEquals("xvi:987", q.m(900,80,7));
|
||||
|
||||
q = this::xIvi;
|
||||
assertEquals("xIvi:(333)99", q.m(333,27, 72));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgsNsi() {
|
||||
Nsi q;
|
||||
|
||||
q = this::xvI;
|
||||
assertEquals("xvI:3-", q.m(3));
|
||||
|
||||
q = this::xIvI;
|
||||
assertEquals("xIvI:888", q.m(888));
|
||||
|
||||
q = this::xvi;
|
||||
assertEquals("xvi:900", q.m(900));
|
||||
|
||||
q = this::xIvi;
|
||||
assertEquals("xIvi:(333)0", q.m(333));
|
||||
}
|
||||
|
||||
// These should NOT be processed as var args
|
||||
|
||||
@Test
|
||||
public void testVarArgsNsaO() {
|
||||
NsaO q;
|
||||
|
||||
q = this::xvO;
|
||||
assertEquals("xvO:yo*there*dude*", q.m(new String[] { "yo", "there", "dude" }));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary test for VarHandle signature polymorphic methods
|
||||
* @run junit MethodReferenceTestVarHandle
|
||||
*/
|
||||
|
||||
import java.lang.invoke.*;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MethodReferenceTestVarHandle {
|
||||
|
||||
interface Setter {
|
||||
void apply(int[] arr, int idx, int val);
|
||||
}
|
||||
|
||||
interface Getter {
|
||||
int apply(int[] arr, int idx);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSet() throws Throwable {
|
||||
VarHandle vh = MethodHandles.arrayElementVarHandle(int[].class);
|
||||
|
||||
Setter f = vh::set;
|
||||
|
||||
int[] data = {0};
|
||||
f.apply(data, 0, 42);
|
||||
assertEquals(42, data[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet() throws Throwable {
|
||||
VarHandle vh = MethodHandles.arrayElementVarHandle(int[].class);
|
||||
|
||||
Getter f = vh::get;
|
||||
|
||||
int[] data = {42};
|
||||
int v = f.apply(data, 0);
|
||||
assertEquals(42, v);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary test for VarHandle signature polymorphic methods with wrong return type
|
||||
* @compile/fail/ref=MethodReferenceTestVarHandle_neg.out -XDrawDiagnostics MethodReferenceTestVarHandle_neg.java
|
||||
*/
|
||||
|
||||
import java.lang.invoke.*;
|
||||
import java.util.*;
|
||||
|
||||
public class MethodReferenceTestVarHandle_neg {
|
||||
|
||||
interface Setter {
|
||||
int apply(int[] arr, int idx, int val);
|
||||
}
|
||||
|
||||
public static void meth() {
|
||||
VarHandle vh = MethodHandles.arrayElementVarHandle(int[].class);
|
||||
|
||||
// Return type of Setter::apply does not match return type of VarHandle::set
|
||||
Setter f = vh::set;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
MethodReferenceTestVarHandle_neg.java:20:18: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.mref: (compiler.misc.inconvertible.types: void, int))
|
||||
1 error
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8191655
|
||||
* @summary LambdaConversionException: Invalid receiver type interface; not a subtype of implementation type interface
|
||||
* @run main MethodReferenceUnionTypeTest
|
||||
*/
|
||||
|
||||
import java.util.function.Consumer;
|
||||
public class MethodReferenceUnionTypeTest {
|
||||
static String blah = "NONE";
|
||||
<T> void forAll(Consumer<T> consumer, T value) { consumer.accept(value); }
|
||||
|
||||
public void secondTest() {
|
||||
try {
|
||||
throwing();
|
||||
} catch (A | B ex) {
|
||||
forAll(Picture::draw, ex);
|
||||
}
|
||||
}
|
||||
|
||||
void throwing() throws A, B { throw new A();}
|
||||
|
||||
interface Shape { void draw(); }
|
||||
interface Marker { }
|
||||
interface Picture { void draw(); }
|
||||
|
||||
class A extends Exception implements Marker, Picture { public void draw() { blah = "A"; }}
|
||||
class B extends Exception implements Marker, Picture, Shape { public void draw() {}}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new MethodReferenceUnionTypeTest().secondTest();
|
||||
if (!blah.equals("A"))
|
||||
throw new AssertionError("Incorrect output");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package pkg;
|
||||
class A {
|
||||
public static void m() {
|
||||
B.result += "A.m()";
|
||||
}
|
||||
}
|
||||
|
||||
public class B extends A {
|
||||
public static String result = "";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue