KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > InputFallThrough


1 public class InputFallThrough
2 {
3     void method(int i, int j, boolean cond) {
4         while (true) {
5             switch (i) {
6             case 0: // no problem
7
case 1:
8                 i++;
9                 break;
10             case 2:
11                 i++;
12             case 3: //fall through!!!
13
i++;
14                 break;
15             case 4:
16                 return;
17             case 5:
18                 throw new RuntimeException JavaDoc("");
19             case 6:
20                 continue;
21             case 7: {
22                 break;
23             }
24             case 8: {
25                 return;
26             }
27             case 9: {
28                 throw new RuntimeException JavaDoc("");
29             }
30             case 10: {
31                 continue;
32             }
33             case 11: {
34                 i++;
35             }
36             case 12: //fall through!!!
37
if (false)
38                     break;
39                 else
40                     break;
41             case 13:
42                 if (true) {
43                     return;
44                 }
45             case 14:
46                 if (true) {
47                     return;
48                 } else {
49                     //do nothing
50
}
51             case 15: //fall through!!!
52
do {
53                     System.out.println("something");
54                     return;
55                 } while(true);
56             case 16:
57                 for (int j1 = 0; j1 < 10; j1++) {
58                     System.err.println("something");
59                     return;
60                 }
61             case 17:
62                 while (true)
63                     throw new RuntimeException JavaDoc("");
64             case 18:
65                 while(cond) {
66                     break;
67                 }
68             case 19: //fall through!!!
69
try {
70                     i++;
71                     break;
72                 } catch (RuntimeException JavaDoc e) {
73                     break;
74                 } catch (Error JavaDoc e) {
75                     return;
76                 }
77             case 20:
78                 try {
79                     i++;
80                     break;
81                 } catch (RuntimeException JavaDoc e) {
82                 } catch (Error JavaDoc e) {
83                     return;
84                 }
85             case 21: //fall through!!!
86
try {
87                     i++;
88                 } catch (RuntimeException JavaDoc e) {
89                     i--;
90                 } finally {
91                     break;
92                 }
93             case 22:
94                 try {
95                     i++;
96                     break;
97                 } catch (RuntimeException JavaDoc e) {
98                     i--;
99                     break;
100                 } finally {
101                     i++;
102                 }
103             case 23: //fall through!!!
104
switch (j) {
105                 case 1:
106                     continue;
107                 case 2:
108                     return;
109                 default:
110                     return;
111                 }
112             case 24:
113                 switch (j) {
114                 case 1:
115                     continue;
116                 case 2:
117                     break;
118                 default:
119                     return;
120                 }
121             default: //fall through!!!
122
// this is the last label
123
i++;
124             }
125         }
126     }
127     
128     
129     
130     /* Like above, but all fall throughs with relief comment */
131     void methodFallThru(int i, int j, boolean cond) {
132       while (true) {
133           switch (i) {
134           case -1: // FALLTHRU
135

136           case 0: // no problem
137
case 1:
138               i++;
139               break;
140           case 2:
141               i++;
142               // fallthru
143
case 3:
144               i++;
145               break;
146           case 4:
147               return;
148           case 5:
149               throw new RuntimeException JavaDoc("");
150           case 6:
151               continue;
152           case 7: {
153               break;
154           }
155           case 8: {
156               return;
157           }
158           case 9: {
159               throw new RuntimeException JavaDoc("");
160           }
161           case 10: {
162               continue;
163           }
164           case 11: {
165               i++;
166           }
167           // fallthru
168
case 12:
169               if (false)
170                   break;
171               else
172                   break;
173           case 13:
174               if (true) {
175                   return;
176               }
177           case 14:
178               if (true) {
179                   return;
180               } else {
181                   //do nothing
182
}
183               // fallthru
184
case 15:
185               do {
186                   System.out.println("something");
187                   return;
188               } while(true);
189           case 16:
190               for (int j1 = 0; j1 < 10; j1++) {
191                   System.err.println("something");
192                   return;
193               }
194           case 17:
195               while (cond)
196                   throw new RuntimeException JavaDoc("");
197           case 18:
198               while(cond) {
199                   break;
200               }
201               // fallthru
202
case 19:
203               try {
204                   i++;
205                   break;
206               } catch (RuntimeException JavaDoc e) {
207                   break;
208               } catch (Error JavaDoc e) {
209                   return;
210               }
211           case 20:
212               try {
213                   i++;
214                   break;
215               } catch (RuntimeException JavaDoc e) {
216               } catch (Error JavaDoc e) {
217                   return;
218               }
219               // fallthru
220
case 21:
221               try {
222                   i++;
223               } catch (RuntimeException JavaDoc e) {
224                   i--;
225               } finally {
226                   break;
227               }
228           case 22:
229               try {
230                   i++;
231                   break;
232               } catch (RuntimeException JavaDoc e) {
233                   i--;
234                   break;
235               } finally {
236                   i++;
237               }
238               /* fallthru */
239           case 23:
240               switch (j) {
241               case 1:
242                   continue;
243               case 2:
244                   return;
245               default:
246                   return;
247               }
248           case 24:
249               i++;
250           /* fallthru */ case 25:
251               i++;
252               break;
253
254           case 26:
255               switch (j) {
256               case 1:
257                   continue;
258               case 2:
259                   break;
260               default:
261                   return;
262               }
263               // fallthru
264
default:
265               // this is the last label
266
i++;
267           // fallthru
268
}
269       }
270    }
271     
272    /* Test relief comment. */
273    void methodFallThruCC(int i, int j, boolean cond) {
274       while (true) {
275           switch (i){
276           case 0:
277               i++; // fallthru
278

279           case 1:
280               i++;
281           // fallthru
282
case 2: {
283               i++;
284           }
285           // fallthru
286
case 3:
287               i++;
288           /* fallthru */case 4:
289                 break;
290           case 5:
291               i++;
292           // fallthru
293
}
294       }
295    }
296     
297    /* Like above, but C-style comments. */
298    void methodFallThruC(int i, int j, boolean cond) {
299       while (true) {
300           switch (i){
301           case 0:
302               i++; /* fallthru */
303
304           case 1:
305               i++;
306           /* fallthru */
307           case 2:
308               i++;
309           /* fallthru */case 3:
310                 break;
311           case 4:
312               i++;
313           /* fallthru */
314           }
315       }
316    }
317
318    /* Like above, but C-style comments with no spaces. */
319    void methodFallThruC2(int i, int j, boolean cond) {
320       while (true) {
321           switch (i){
322           case 0:
323               i++; /*fallthru*/
324
325           case 1:
326               i++;
327           /*fallthru*/
328           case 2:
329               i++;
330           /*fallthru*/case 3:
331                 break;
332           case 4:
333               i++;
334           /*fallthru*/
335           }
336       }
337    }
338     
339    /* C-style comments with other default fallthru-comment. */
340    void methodFallThruCOtherWords(int i, int j, boolean cond) {
341       while (true) {
342           switch (i){
343           case 0:
344               i++; /* falls through */
345
346           case 1:
347               i++;
348           /* falls through */
349           case 2:
350               i++;
351           /* falls through */case 3:
352                 break;
353           case 4:
354               i++;
355           /* falls through */
356           }
357       }
358    }
359     
360    /* C-style comments with custom fallthru-comment. */
361    void methodFallThruCCustomWords(int i, int j, boolean cond) {
362       while (true) {
363           switch (i){
364           case 0:
365               i++; /* Continue with next case */
366
367           case 1:
368               i++;
369           /* Continue with next case */
370           case 2:
371               i++;
372           /* Continue with next case */case 3:
373                 break;
374           case 4:
375               i++;
376           /* Continue with next case */
377           }
378       }
379    }
380    
381    void methodFallThruLastCaseGroup(int i, int j, boolean cond) {
382        while (true) {
383            switch (i){
384            case 0:
385                i++; // fallthru
386
}
387            switch (i){
388            case 0:
389                i++;
390                // fallthru
391
}
392            switch (i){
393            case 0:
394                i++;
395            /* fallthru */ }
396        }
397     }
398    
399    
400
401 }
402
Popular Tags