1
+ /*
2
+ * Copyright (c) 2020, 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
+ /*
25
+ * @test
26
+ * @bug 8254557
27
+ * @summary Method Attr.preFlow shouldn't visit class definitions that have not yet been entered and attributed.
28
+ * @compile T8254557.java
29
+ */
30
+
31
+ import java .util .Iterator ;
32
+ import java .util .function .Function ;
33
+
34
+ public class T8254557 {
35
+ // test anonymous class in if statement
36
+ public <T > void testIf (boolean b ) {
37
+ test (rs -> {
38
+ if (b ) {
39
+ return new Iterator <>() {
40
+ @ Override
41
+ public boolean hasNext () {
42
+ return true ;
43
+ }
44
+
45
+ @ Override
46
+ public T next () {
47
+ return null ;
48
+ }
49
+ };
50
+ } else {
51
+ return new Iterator <>() {
52
+ @ Override
53
+ public boolean hasNext () {
54
+ return true ;
55
+ }
56
+
57
+ @ Override
58
+ public T next () {
59
+ return null ;
60
+ }
61
+ };
62
+ }
63
+ });
64
+ }
65
+
66
+ // test anonymous class in while statement
67
+ public <T > void testWhile (boolean b ) {
68
+ test (rs -> {
69
+ while (b ) {
70
+ return new Iterator <>() {
71
+ @ Override
72
+ public boolean hasNext () {
73
+ return true ;
74
+ }
75
+
76
+ @ Override
77
+ public T next () {
78
+ return null ;
79
+ }
80
+ };
81
+ }
82
+ return null ;
83
+ });
84
+ }
85
+
86
+ // test anonymous class in do while statement
87
+ public <T > void testDoWhileLoop (boolean b ) {
88
+ test (rs -> {
89
+ do {
90
+ return new Iterator <>() {
91
+ @ Override
92
+ public boolean hasNext () {
93
+ return true ;
94
+ }
95
+
96
+ @ Override
97
+ public T next () {
98
+ return null ;
99
+ }
100
+ };
101
+ } while (b );
102
+ });
103
+ }
104
+
105
+ // test anonymous class in for statement
106
+ public <T > void testForLoop (boolean b ) {
107
+ test (rs -> {
108
+ for ( ; ; ) {
109
+ return new Iterator <>() {
110
+ @ Override
111
+ public boolean hasNext () {
112
+ return true ;
113
+ }
114
+
115
+ @ Override
116
+ public T next () {
117
+ return null ;
118
+ }
119
+ };
120
+ }
121
+ });
122
+ }
123
+
124
+ private void test (Function function ) { }
125
+ }
0 commit comments