/* * @test /nodynamiccopyright/ * @bug 8354556 * @summary Expand value-based class warnings to java.lang.ref API * @compile --patch-module java.base=${test.src} RequiresIdentityHelper.java * @compile/fail/ref=RequiresIdentityTest.out --patch-module java.base=${test.src} -Werror -XDrawDiagnostics -Xlint:identity RequiresIdentityTest.java * @compile/fail/ref=RequiresIdentityTest.out --patch-module java.base=${test.src} -Werror -XDrawDiagnostics -Xlint:synchronization RequiresIdentityTest.java * @compile/ref=RequiresIdentityTest2.out --patch-module java.base=${test.src} -Werror -XDrawDiagnostics -Xlint:-identity RequiresIdentityTest.java * @compile/ref=RequiresIdentityTest2.out --patch-module java.base=${test.src} -Werror -XDrawDiagnostics -Xlint:-synchronization RequiresIdentityTest.java * @compile/fail/ref=RequiresIdentityTest.out --patch-module java.base=${test.src} -Werror -XDrawDiagnostics -Xlint:identity RequiresIdentityHelper.java RequiresIdentityTest.java * @compile/fail/ref=RequiresIdentityTest.out --patch-module java.base=${test.src} -Werror -XDrawDiagnostics -Xlint:synchronization RequiresIdentityHelper.java RequiresIdentityTest.java * @compile/ref=RequiresIdentityTest2.out --patch-module java.base=${test.src} -Werror -XDrawDiagnostics -Xlint:-identity RequiresIdentityHelper.java RequiresIdentityTest.java * @compile/ref=RequiresIdentityTest2.out --patch-module java.base=${test.src} -Werror -XDrawDiagnostics -Xlint:-synchronization RequiresIdentityHelper.java RequiresIdentityTest.java */ package java.lang; @SuppressWarnings("deprecation") public class RequiresIdentityTest extends RequiresIdentityHelper // should warn implements RequiresIdentityHelper.RequiresIdentityInt { // should warn class Box {} RequiresIdentityHelper field; // should warn RequiresIdentityHelper[] field2; // should warn Box> field3; // should warn Box> field4; // should warn RequiresIdentityHelper field5 = new RequiresIdentityHelper(); // two warnings here public RequiresIdentityTest() {} public RequiresIdentityTest(Integer i) { super(i); // should warn } void test(RequiresIdentity2 ri, Integer i) { // warn on the first argument due to its enclosing type: RequiresIdentityHelper RequiresIdentityHelper localVar; // should warn RequiresIdentityHelper[] localVar2; // should warn // there should be warnings for the invocations below ri.foo(i); ri.bar(i, // warn here i); // and here too ri.gg(i); } interface I extends RequiresIdentityHelper.RequiresIdentityInt {} // should warn void m(Object o) { RequiresIdentityHelper ri = (RequiresIdentityHelper) o; // should warn } RequiresIdentityHelper test() { // warn return null; } // two warns here one for the type parameter and one for the result type > T test2() { return null; } class SomeClass> {} // warn record R(RequiresIdentityHelper c) {} // warn record RR(R r) {} void m1(RequiresIdentityInt ri) { // warn here if (ri instanceof RequiresIdentityInt rii) {} // and here } void m2(RR rr) { if (rr instanceof RR(R(RequiresIdentityHelper rii))) {} } void m3() {} void m4() { this.>m3(); } MyIntFunction field6 = Integer::new; // two warnings here class Run { public <@jdk.internal.RequiresIdentity K> void run() {} } void m5(Runnable r) {} void m6() { m5(new Run()::run); } void m7(Integer i, Object o) { RequiresIdentityHelper var1 = new RequiresIdentityHelper(i); RequiresIdentityHelper var2 = new RequiresIdentityHelper(o); RequiresIdentityHelper var3 = new RequiresIdentityHelper(o); } }