Jtest logo




Contents  Previous  Next  Index

PB.TLS


Don't use text labels in "switch" statements

Description

This rule flags any text label in a "switch" statement.

Example

The example below shows two situations where errors might occur. Omitting a space between the word "case" and the value being tested prevents the structure from performing the desired action. Also, `wronglabel' will be unused because "switch" handles only "case" labels.

 package PB;
 
 public class TLS {
     static int method (int i) {
         switch (i) {
         case 4:
         case3:      // i == 3 will not go through here.
             i++;
             break;
         case 25:
         wronglabel: // unused label.
             break;
         }
         return i;
     }
 
     public static void main (String args[]) {
         int i = method (3);
         System.out.println (i);
     }
 }

Repair

Change "case3 to "case 3".


Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft