6711619: javac doesn't allow access to protected members in intersection types

Thu, 23 Oct 2008 17:59:43 +0100

author
mcimadamore
date
Thu, 23 Oct 2008 17:59:43 +0100
changeset 155
4d2d8b6459e1
parent 154
6508d7e812e1
child 156
db77bf6adb53

6711619: javac doesn't allow access to protected members in intersection types
Summary: Accordingly to new accessibility rules all members of intersection types (but private ones) should be accessible
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/code/Symbol.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6531090/T6531090b.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6711619/T6711619a.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6711619/T6711619a.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/6711619/T6711619b.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6711619/T6711619b.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Thu Oct 23 17:59:16 2008 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Thu Oct 23 17:59:43 2008 +0100
     1.3 @@ -361,6 +361,8 @@
     1.4              for (Symbol sup = clazz;
     1.5                   sup != null && sup != this.owner;
     1.6                   sup = types.supertype(sup.type).tsym) {
     1.7 +                while (sup.type.tag == TYPEVAR)
     1.8 +                    sup = sup.type.getUpperBound().tsym;
     1.9                  if (sup.type.isErroneous())
    1.10                      return true; // error recovery
    1.11                  if ((sup.flags() & COMPOUND) != 0)
    1.12 @@ -1183,7 +1185,9 @@
    1.13           *  as possible implementations.
    1.14           */
    1.15          public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
    1.16 -            for (Type t = origin.type; t.tag == CLASS; t = types.supertype(t)) {
    1.17 +            for (Type t = origin.type; t.tag == CLASS || t.tag == TYPEVAR; t = types.supertype(t)) {
    1.18 +                while (t.tag == TYPEVAR)
    1.19 +                    t = t.getUpperBound();
    1.20                  TypeSymbol c = t.tsym;
    1.21                  for (Scope.Entry e = c.members().lookup(name);
    1.22                       e.scope != null;
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Oct 23 17:59:16 2008 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Oct 23 17:59:43 2008 +0100
     2.3 @@ -2007,6 +2007,10 @@
     2.4                      log.error(pos, "type.var.cant.be.deref");
     2.5                      return syms.errSymbol;
     2.6                  } else {
     2.7 +                    Symbol sym2 = (sym.flags() & Flags.PRIVATE) != 0 ?
     2.8 +                        rs.new AccessError(env, site, sym) :
     2.9 +                                sym;
    2.10 +                    rs.access(sym2, pos, site, name, true);
    2.11                      return sym;
    2.12                  }
    2.13              case ERROR:
     3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Oct 23 17:59:16 2008 +0100
     3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Oct 23 17:59:43 2008 +0100
     3.3 @@ -554,7 +554,6 @@
     3.4                        boolean useVarargs,
     3.5                        boolean operator) {
     3.6          if (sym.kind == ERR) return bestSoFar;
     3.7 -        if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar;
     3.8          assert sym.kind < AMBIGUOUS;
     3.9          try {
    3.10              if (rawInstantiate(env, site, sym, argtypes, typeargtypes,
     4.1 --- a/test/tools/javac/generics/6531090/T6531090b.java	Thu Oct 23 17:59:16 2008 +0100
     4.2 +++ b/test/tools/javac/generics/6531090/T6531090b.java	Thu Oct 23 17:59:43 2008 +0100
     4.3 @@ -23,7 +23,7 @@
     4.4  
     4.5  /*
     4.6   * @test
     4.7 - * @bug 6531090
     4.8 + * @bug 6531090 6711619
     4.9   *
    4.10   * @summary Cannot access methods/fields of a captured type belonging to an intersection type
    4.11   * @author Maurizio Cimadamore
    4.12 @@ -32,12 +32,20 @@
    4.13  public class T6531090b {
    4.14  
    4.15      static class A {
    4.16 -        public void a() {}
    4.17 -        public A a;
    4.18 +        public void a1() {}
    4.19 +        protected void a2() {}
    4.20 +        void a3() {}
    4.21 +        public A a1;
    4.22 +        protected A a2;
    4.23 +        A a3;
    4.24      }
    4.25      static class B extends A {
    4.26 -        public void b(){}
    4.27 -        public B b;
    4.28 +        public void b1() {}
    4.29 +        protected void b2() {}
    4.30 +        void b3() {}
    4.31 +        public B b1;
    4.32 +        protected B b2;
    4.33 +        B b3;
    4.34      }
    4.35      static interface I{
    4.36          void i();
    4.37 @@ -65,18 +73,35 @@
    4.38      }
    4.39  
    4.40      static void testMemberMethods(C<? extends A, ? extends I> arg) {
    4.41 -        arg.t.a();
    4.42 -        arg.t.b();
    4.43 +        arg.t.a1();
    4.44 +        arg.t.a2();
    4.45 +        arg.t.a3();
    4.46 +        arg.t.b1();
    4.47 +        arg.t.b2();
    4.48 +        arg.t.b3();
    4.49          arg.t.i1();
    4.50 -        arg.w.a();
    4.51 -        arg.w.b();
    4.52 +        arg.w.a1();
    4.53 +        arg.w.a2();
    4.54 +        arg.w.a3();
    4.55 +        arg.w.b1();
    4.56 +        arg.w.b2();
    4.57 +        arg.w.b3();
    4.58          arg.w.i1();
    4.59      }
    4.60  
    4.61      static void testMemberFields(C<? extends A, ? extends I> arg) {
    4.62 -        A ta = arg.t.a;
    4.63 -        B tb = arg.t.b;
    4.64 -        A wa = arg.w.a;
    4.65 -        B wb = arg.w.b;
    4.66 +        A ta; B tb;
    4.67 +        ta = arg.t.a1;
    4.68 +        ta = arg.t.a2;
    4.69 +        ta = arg.t.a3;
    4.70 +        tb = arg.t.b1;
    4.71 +        tb = arg.t.b2;
    4.72 +        tb = arg.t.b3;
    4.73 +        ta = arg.w.a1;
    4.74 +        ta = arg.w.a2;
    4.75 +        ta = arg.w.a3;
    4.76 +        tb = arg.w.b1;
    4.77 +        tb = arg.w.b2;
    4.78 +        tb = arg.w.b3;
    4.79      }
    4.80  }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/generics/6711619/T6711619a.java	Thu Oct 23 17:59:43 2008 +0100
     5.3 @@ -0,0 +1,74 @@
     5.4 +/*
     5.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    5.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    5.24 + * have any questions.
    5.25 + */
    5.26 +
    5.27 +/*
    5.28 + * @test
    5.29 + * @bug 6711619
    5.30 + *
    5.31 + * @summary javac doesn't allow access to protected members in intersection types
    5.32 + * @author Maurizio Cimadamore
    5.33 + *
    5.34 + * @compile/fail/ref=T6711619a.out -XDrawDiagnostics T6711619a.java
    5.35 + */
    5.36 +class T6711619a {
    5.37 +
    5.38 +    static class A {
    5.39 +        private void a() {}
    5.40 +        private A a;
    5.41 +    }
    5.42 +    static class B extends A {
    5.43 +        private B b() {}
    5.44 +        private B b;
    5.45 +    }
    5.46 +    static interface I{
    5.47 +        void i();
    5.48 +    }
    5.49 +    static interface I1{
    5.50 +        void i1();
    5.51 +    }
    5.52 +    static class E extends B implements I, I1{
    5.53 +        public void i() {}
    5.54 +        public void i1() {}
    5.55 +    }
    5.56 +    static class C<W extends B & I1, T extends W>{
    5.57 +        T t;
    5.58 +        W w;
    5.59 +        C(W w, T t) {
    5.60 +            this.w = w;
    5.61 +            this.t = t;
    5.62 +        }
    5.63 +    }
    5.64 +
    5.65 +    static void testMemberMethods(C<? extends A, ? extends I> arg) {
    5.66 +        arg.t.a();
    5.67 +        arg.t.b();
    5.68 +    }
    5.69 +
    5.70 +    static void testMemberFields(C<? extends A, ? extends I> arg) {
    5.71 +        A ta; B tb;
    5.72 +        ta = arg.t.a;
    5.73 +        tb = arg.t.b;
    5.74 +        ta = arg.w.a;
    5.75 +        tb = arg.w.b;
    5.76 +    }
    5.77 +}
    5.78 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/generics/6711619/T6711619a.out	Thu Oct 23 17:59:43 2008 +0100
     6.3 @@ -0,0 +1,7 @@
     6.4 +T6711619a.java:63:14: compiler.err.report.access: a(), private, T6711619a.A
     6.5 +T6711619a.java:64:14: compiler.err.report.access: b(), private, T6711619a.B
     6.6 +T6711619a.java:69:19: compiler.err.report.access: a, private, T6711619a.A
     6.7 +T6711619a.java:70:19: compiler.err.report.access: b, private, T6711619a.B
     6.8 +T6711619a.java:71:19: compiler.err.report.access: a, private, T6711619a.A
     6.9 +T6711619a.java:72:19: compiler.err.report.access: b, private, T6711619a.B
    6.10 +6 errors
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/tools/javac/generics/6711619/T6711619b.java	Thu Oct 23 17:59:43 2008 +0100
     7.3 @@ -0,0 +1,64 @@
     7.4 +/*
     7.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + *
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.
    7.11 + *
    7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.15 + * version 2 for more details (a copy is included in the LICENSE file that
    7.16 + * accompanied this code).
    7.17 + *
    7.18 + * You should have received a copy of the GNU General Public License version
    7.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.21 + *
    7.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    7.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    7.24 + * have any questions.
    7.25 + */
    7.26 +
    7.27 +/*
    7.28 + * @test
    7.29 + * @bug 6711619
    7.30 + *
    7.31 + * @summary javac doesn't allow access to protected members in intersection types
    7.32 + * @author Maurizio Cimadamore
    7.33 + *
    7.34 + * @compile/fail/ref=T6711619b.out -XDrawDiagnostics T6711619b.java
    7.35 + */
    7.36 +
    7.37 +class T6711619b {
    7.38 +    static class X1<E extends X1<E>> {
    7.39 +         private int i;
    7.40 +         E e;
    7.41 +         int f() {
    7.42 +             return e.i;
    7.43 +         }
    7.44 +    }
    7.45 +
    7.46 +    static class X2<E extends X2<E>> {
    7.47 +         static private int i;
    7.48 +         int f() {
    7.49 +             return E.i;
    7.50 +         }
    7.51 +    }
    7.52 +
    7.53 +    static class X3<E extends X3<E> & java.io.Serializable> {
    7.54 +         private int i;
    7.55 +         E e;
    7.56 +         int f() {
    7.57 +             return e.i;
    7.58 +         }
    7.59 +    }
    7.60 +
    7.61 +    static class X4<E extends X4<E> & java.io.Serializable> {
    7.62 +         static private int i;
    7.63 +         int f() {
    7.64 +             return E.i;
    7.65 +         }
    7.66 +    }
    7.67 +}
    7.68 \ No newline at end of file
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/tools/javac/generics/6711619/T6711619b.out	Thu Oct 23 17:59:43 2008 +0100
     8.3 @@ -0,0 +1,5 @@
     8.4 +T6711619b.java:39:22: compiler.err.report.access: i, private, T6711619b.X1
     8.5 +T6711619b.java:46:22: compiler.err.report.access: i, private, T6711619b.X2
     8.6 +T6711619b.java:54:22: compiler.err.report.access: i, private, T6711619b.X3
     8.7 +T6711619b.java:61:22: compiler.err.report.access: i, private, T6711619b.X4
     8.8 +4 errors

mercurial