Fri, 30 May 2008 10:29:27 +0100
6665223: Static import of inherited protected method causes compiler exception
Summary: Buggy accessibility check causes NPE during resolution of imported static methods
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu May 22 17:40:53 2008 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri May 30 10:29:27 2008 +0100 1.3 @@ -228,7 +228,7 @@ 1.4 // another symbol which is a member of `site' 1.5 // (because, if it is overridden, `sym' is not strictly 1.6 // speaking a member of `site'.) 1.7 - (sym.kind != MTH || sym.isConstructor() || 1.8 + (sym.kind != MTH || sym.isConstructor() || sym.isStatic() || 1.9 ((MethodSymbol)sym).implementation(site.tsym, types, true) == sym); 1.10 default: // this case includes erroneous combinations as well 1.11 return isAccessible(env, site);
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/staticImport/6665223/T6665223.java Fri May 30 10:29:27 2008 +0100 2.3 @@ -0,0 +1,31 @@ 2.4 +/* 2.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 2.24 + * have any questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 6665223 2.30 + * @summary Static import of inherited protected method causes compiler exception 2.31 + * @author Maurizio Cimadamore 2.32 + * 2.33 + * @compile pkg/A.java 2.34 + */
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/staticImport/6665223/pkg/A.java Fri May 30 10:29:27 2008 +0100 3.3 @@ -0,0 +1,31 @@ 3.4 +/* 3.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 3.24 + * have any questions. 3.25 + */ 3.26 +package pkg; 3.27 + 3.28 +import static pkg.B.b; 3.29 + 3.30 +class A { 3.31 + public static void main(String[] args) { 3.32 + b(); 3.33 + } 3.34 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/staticImport/6665223/pkg/B.java Fri May 30 10:29:27 2008 +0100 4.3 @@ -0,0 +1,29 @@ 4.4 +/* 4.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 4.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 4.24 + * have any questions. 4.25 + */ 4.26 +package pkg; 4.27 + 4.28 +class B extends B2 {} 4.29 + 4.30 +abstract class B2 { 4.31 + protected static void b() {} 4.32 +}