# HG changeset patch # User vromero # Date 1514928904 18000 # Node ID 3a52333a5e576541ca0b0542986e181c549bbbfd # Parent 2c1af559e9227d23a3d59fe2c39836338db933c2 8187487: crash with classes with same binary name Reviewed-by: jjg diff -r 2c1af559e922 -r 3a52333a5e57 src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java Fri Dec 22 14:00:03 2017 -0800 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java Tue Jan 02 16:35:04 2018 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -421,6 +421,12 @@ // We are seeing a member class. c = syms.enterClass(env.toplevel.modle, tree.name, (TypeSymbol)owner); if (c.owner != owner) { + if (c.name != tree.name) { + log.error(tree.pos(), Errors.SameBinaryName(c.name, tree.name)); + result = types.createErrorType(tree.name, (TypeSymbol)owner, Type.noType); + tree.sym = (ClassSymbol)result.tsym; + return; + } //anonymous class loaded from a classfile may be recreated from source (see below) //if this class is a member of such an anonymous class, fix the owner: Assert.check(owner.owner.kind != TYP, owner::toString); diff -r 2c1af559e922 -r 3a52333a5e57 src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Dec 22 14:00:03 2017 -0800 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Jan 02 16:35:04 2018 -0500 @@ -1,5 +1,5 @@ # -# Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -443,6 +443,10 @@ compiler.err.duplicate.class=\ duplicate class: {0} +# 0: name, 1: name +compiler.err.same.binary.name=\ + classes: {0} and {1} have the same binary name + compiler.err.duplicate.case.label=\ duplicate case label diff -r 2c1af559e922 -r 3a52333a5e57 test/langtools/tools/javac/NestedInnerClassNames.out --- a/test/langtools/tools/javac/NestedInnerClassNames.out Fri Dec 22 14:00:03 2017 -0800 +++ b/test/langtools/tools/javac/NestedInnerClassNames.out Tue Jan 02 16:35:04 2018 -0500 @@ -6,7 +6,7 @@ NestedInnerClassNames.java:59:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.foo$bar, kindname.class, NestedInnerClassNames NestedInnerClassNames.java:76:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.$bar, kindname.class, NestedInnerClassNames NestedInnerClassNames.java:90:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.bar$bar.bar, kindname.class, NestedInnerClassNames.bar$bar -NestedInnerClassNames.java:109:5: compiler.err.duplicate.class: NestedInnerClassNames.foo.foo +NestedInnerClassNames.java:109:5: compiler.err.same.binary.name: foo, foo$foo NestedInnerClassNames.java:19:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package NestedInnerClassNames.java:28:13: compiler.err.already.defined: kindname.class, foo, kindname.method, m2() NestedInnerClassNames.java:40:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package diff -r 2c1af559e922 -r 3a52333a5e57 test/langtools/tools/javac/T8187487/CrashWithDuplicateClassNamesTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/T8187487/CrashWithDuplicateClassNamesTest.java Tue Jan 02 16:35:04 2018 -0500 @@ -0,0 +1,20 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8187487 + * @summary crash with duplicate class name + * @compile/fail/ref=CrashWithDuplicateClassNamesTest.out -XDrawDiagnostics CrashWithDuplicateClassNamesTest.java + */ + +class CrashWithDuplicateClassNamesTest { + static class C1$C2 {} + + static class C1 { + static class C2 {} + } + + static class C3 { + static class C4 {} + } + + static class C3$C4 {} +} diff -r 2c1af559e922 -r 3a52333a5e57 test/langtools/tools/javac/T8187487/CrashWithDuplicateClassNamesTest.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/T8187487/CrashWithDuplicateClassNamesTest.out Tue Jan 02 16:35:04 2018 -0500 @@ -0,0 +1,3 @@ +CrashWithDuplicateClassNamesTest.java:12:16: compiler.err.same.binary.name: C1$C2, C2 +CrashWithDuplicateClassNamesTest.java:19:12: compiler.err.same.binary.name: C4, C3$C4 +2 errors diff -r 2c1af559e922 -r 3a52333a5e57 test/langtools/tools/javac/diags/examples/SameBinaryName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/diags/examples/SameBinaryName.java Tue Jan 02 16:35:04 2018 -0500 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.same.binary.name + +class SameBinaryName { + private static final class Foo$Bar {} + + private static final class Foo { + private static final class Bar {} + } +}