jdk/test/com/sun/jdi/ControlFlow.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/* /nodynamiccopyright/ */ // hard coded linenumbers in other tests - DO NOT CHANGE
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * Debuggee which exercises various types of control flow
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
class ControlFlow {
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
    boolean b = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
    int n = 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
        (new ControlFlow()).go();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
    void go() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
        if (b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
            System.out.println("if, no else");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
        if (b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
            System.out.println("if branch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
            throw new Exception("Wrong branch!?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
        if (!b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
            throw new Exception("Wrong branch!?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
            System.out.println("else branch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
            System.out.println("caught exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
            System.out.println("finally");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        // This isn't control flow at the source level,  but it is at the bytecode level
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
            System.out.println("synchronized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
            System.out.println("Loop iteration: " + (i+1) + "/" + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        switch (n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                throw new Exception("Wrong branch!?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                throw new Exception("Wrong branch!?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                throw new Exception("Wrong branch!?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                throw new Exception("Wrong branch!?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            case 22:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                System.out.println("switch case");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                throw new Exception("Wrong branch!?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        switch (n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                throw new Exception("Wrong branch!?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                throw new Exception("Wrong branch!?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                throw new Exception("Wrong branch!?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                throw new Exception("Wrong branch!?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                System.out.println("switch default");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
}