1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.lang.invoke.*; 25 26 class Parent { 27 Point foo() { 28 return Point.createPoint(); 29 } 30 } 31 32 interface InterfaceWithDefault { 33 default Point foo() { 34 return Point.createPoint(); 35 } 36 } 37 38 class Provider { 39 static Point getPoint() { 40 return Point.createPoint(); 41 } 42 static void foo(Point[] array) { } 43 44 static void processPoint(Point p) { } 45 } 46 47 // It's OK to declare a Flattenable field of a mismatched type, but only from a legacy class that doesn't know Point is a VT. 48 @LegacyPositiveTest 49 class FlattenableField { 50 static class Helper { 51 // test assumes __Flattenable is the default for non static fields 52 Point p; 53 } 54 public static void run() { 55 // Helper will fail to load if it's not a legacy class (i.e., it declares that Point is a VT, but 56 // point ends up not being a VT. 57 new Helper(); 58 } 59 } 60 61 // It's OK to declare a NonFlattenable field of a mismatched type 62 @PositiveTest 63 class NotFlattenableField { 64 __NotFlattened Point p; 65 public static void run() {}; 66 } 67 68 // It's OK to declare a NonFlattenable static field of a mismatched type 69 @PositiveTest 70 class NotFlattenableStaticField { 71 __NotFlattened static Point p; 72 public static void run() {} 73 } 74 75 // It's OK to declare a NonFlattenable static field of a mismatched type 76 @PositiveTest 77 class ValueArrayField { 78 Point[] p; 79 public static void run() {}; 80 } 81 82 // Cannot resolve the Point class if your idea of whether it's a ValueType is wrong. 83 @NegativeTest 84 class ResolveClass { 85 public static void run() { 86 Class c = Point.class; 87 //TODO Point p = Point.createPoint(); 88 } 89 } 90 91 // It's NOT OK to resolve the array class of Point even if your idea of whether it's a ValueType is wrong. 92 @NegativeTest 93 class ResolveArray { 94 public static void run() { 95 Point[] array = new Point[5]; 96 } 97 } 98 99 // Yet it's OK to resolve a higher-dimensional array class of Point even if your idea of whether it's a ValueType is wrong. (BUG??) 100 @PositiveTest 101 class ResolveMultiArray { 102 public static void run() { 103 Point[][] array = new Point[5][4]; 104 } 105 } 106 107 // Cannot resolve a method in the Point class if your idea of whether it's a ValueType is wrong. 108 @NegativeTest 109 class ResolveMethod { 110 public static void run() { 111 Point.createPoint(); 112 } 113 } 114 115 // It's OK for a legacy class to declare (but not use) a method whose signature contains a mismatched VT. 116 @LegacyPositiveTest 117 class LocalMethod { 118 static class Helper { 119 Point foo() { 120 return Point.createPoint(); 121 } 122 } 123 public static void run() { 124 new Helper(); 125 } 126 } 127 128 // It's OK for a legacy class to declare (but not use) a method whose signature contains a array of a mismatched VT. 129 @LegacyPositiveTest 130 class LocalMethodWithArray { 131 static class Helper { 132 void foo(Point[] array) { } 133 } 134 public static void run() { 135 new Helper(); 136 } 137 } 138 139 140 // Two legacy classes can call each other's methods, as long as both of them 141 // have the wrong understanding of whether Point is a VT. 142 @LegacyPositiveTest 143 class BothWrongRemoteMethod { 144 static __NotFlattened Point p; // to get a null value 145 public static void run() { 146 Provider.processPoint(p); 147 } 148 } 149 150 // helper class used by InvokeMethodHandle (defined in ConsistencyTest.java). 151 class InvokeMethodHandle_mismatched { 152 static void test(MethodHandle mh) throws Throwable { 153 Point p = (Point)mh.invoke(); 154 System.out.println("(should not get here) Point = " + p); 155 } 156 }