langtools/test/tools/javac/protectedAccess/ProtectedMemberAccess2.java
author vromero
Tue, 06 Sep 2016 17:04:43 -0700
changeset 40835 6ab9ed1abc46
parent 39812 6272642715a1
permissions -rw-r--r--
8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags Reviewed-by: mcimadamore
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 4319507 4785453
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 * @summary Verify correct implementation of JLS2e 6.6.2.1
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * @author maddox
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 *
40835
6ab9ed1abc46 8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents: 39812
diff changeset
     7
 * @compile/fail/ref=ProtectedMemberAccess2.out --diags:formatterOptions=-simpleNames;layout=%b:%l:%_%m ProtectedMemberAccess2.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
// 71 errors expected.
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
import pkg.SuperClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
class ProtectedMemberAccess2 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
  // Since this class is not a subclass of the class in which the
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
  // protected members are declared, all of the accesses are illegal.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
  pkg.SuperClass x = new pkg.SuperClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
  static pkg.SuperClass sx = new pkg.SuperClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
  int i = x.pi;                                 // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
  int j = x.spi;                                // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
  int n = sx.pi;                                // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
  int m = sx.spi;                               // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
  static int sn = sx.pi;                        // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
  static int sm = sx.spi;                       // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
  int w = x.pm();                               // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
  int y = x.spm();                              // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
  int u = sx.pm();                              // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
  int v = sx.spm();                             // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
  pkg.SuperClass.pC  obj1;                      // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
  pkg.SuperClass.spC obj2;                      // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
  pkg.SuperClass.pI  obj3;                      // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
  pkg.SuperClass.spI obj4;                      // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
  Object o1 = (pkg.SuperClass.pC) null;         // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
  Object o2 = (pkg.SuperClass.spC) null;        // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
  Object o3 = (pkg.SuperClass.pI) null;         // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
  Object o4 = (pkg.SuperClass.spI) null;        // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
  class C1 extends pkg.SuperClass.pC {}         // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
  class C2 extends pkg.SuperClass.spC {}        // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
  interface I1 extends pkg.SuperClass.pI {}     // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
  interface I2 extends pkg.SuperClass.spI {}    // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
  static {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    pkg.SuperClass lx = new pkg.SuperClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    sx.pi  = 1;                                 // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    sx.spi = 2;                                 // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    lx.pi  = 1;                                 // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    lx.spi = 2;                                 // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    int n = sx.pi;                              // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    int m = sx.spi;                             // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    int k = lx.pi;                              // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    int l = lx.spi;                             // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    int u = sx.pm();                            // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    int v = sx.spm();                           // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    int w = lx.pm();                            // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    int z = lx.spm();                           // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    pkg.SuperClass.pC  obj1;                    // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    pkg.SuperClass.spC obj2;                    // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    pkg.SuperClass.pI  obj3;                    // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    pkg.SuperClass.spI obj4;                    // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    Object o1 = (pkg.SuperClass.pC) null;       // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    Object o2 = (pkg.SuperClass.spC) null;      // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    Object o3 = (pkg.SuperClass.pI) null;       // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    Object o4 = (pkg.SuperClass.spI) null;      // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    //class C1 extends pkg.SuperClass.pC {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    class C2 extends pkg.SuperClass.spC {}      // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    //interface I1 extends pkg.SuperClass.pI {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    //interface I2 extends pkg.SuperClass.spI {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
  void m() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    pkg.SuperClass lx = new pkg.SuperClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    x.pi  = 1;                                  // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    x.spi = 2;                                  // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    sx.pi  = 1;                                 // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    sx.spi = 2;                                 // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    lx.pi  = 1;                                 // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    lx.spi = 2;                                 // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    int t = x.pm();                             // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    int y = x.spm();                            // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    int u = sx.pm();                            // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    int v = sx.spm();                           // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    int w = lx.pm();                            // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    int z = lx.spm();                           // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    int i = x.pi;                               // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    int j = x.spi;                              // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    int n = sx.pi;                              // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    int m = sx.spi;                             // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    int k = lx.pi;                              // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    int l = lx.spi;                             // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    pkg.SuperClass.pC  obj1;                    // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    pkg.SuperClass.spC obj2;                    // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    pkg.SuperClass.pI  obj3;                    // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    pkg.SuperClass.spI obj4;                    // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    Object o1 = (pkg.SuperClass.pC) null;       // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    Object o2 = (pkg.SuperClass.spC) null;      // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    Object o3 = (pkg.SuperClass.pI) null;       // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    Object o4 = (pkg.SuperClass.spI) null;      // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    class C1 extends pkg.SuperClass.pC {}       // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    class C2 extends pkg.SuperClass.spC {}      // illegal
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    //interface I1 extends pkg.SuperClass.pI {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    //interface I2 extends pkg.SuperClass.spI {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
}