langtools/test/tools/javac/CyclicInheritance.java
author jeff
Wed, 22 Jun 2011 10:10:54 -0700
changeset 9916 c35ecac744a5
parent 6150 d055fa8ced62
permissions -rw-r--r--
7057046: Add embedded license to THIRD PARTY README Reviewed-by: lana
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * @test  /nodynamiccopyright/
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * @bug 4018525 4059072 4277274 4785453
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 * @summary Test that recursive 'extends' and 'implements' clauses are detected
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * and disallowed.
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 *
6150
d055fa8ced62 6971882: Remove -XDstdout from javac test
jjg
parents: 863
diff changeset
     7
 * @compile/fail/ref=CyclicInheritance.out -XDrawDiagnostics CyclicInheritance.java
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
class C1 extends C1 {}                  // ERROR - Cyclic inheritance
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
class C11 extends C12 {}                // ERROR - Cyclic inheritance
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
class C12 extends C11 {}                // error in previous line could correctly be reported here as well
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
interface I1 extends I1 {}              // ERROR - Cyclic inheritance
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
interface I11 extends I12 {}            // ERROR - Cyclic inheritance
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
interface I12 extends I11 {}            // error in previous line could correctly be reported here as well
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
//-----
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
class C211 implements C211.I {          // ERROR - may change pending resoluation of 4087020
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
        interface I {};                 // error in previous line could correctly be reported here as well
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
class C212 extends C212.C {             // ERROR - Cyclic inheritance, subclass cannot enclose superclass
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
        static class C {};              // error in previous line could correctly be reported here as well
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
class C221 implements C221.I {          // ERROR - Cannot access C21 (private)
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
        private interface I {};         // error in previous line could correctly be reported here as well
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
class C222 extends C222.C {             // ERROR - Cannot access C22 (private)
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
        private static class C {};      // error in previous line could correctly be reported here as well
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
//-----
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
class C3 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    class A {
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
        class B extends A {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
class C4 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    class A extends B {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    class B {
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
        class C extends A {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
}