8187487: crash with classes with same binary name
Reviewed-by: jjg
This commit is contained in:
parent
0e4506a71b
commit
a316ab9ef3
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -421,6 +421,12 @@ public class Enter extends JCTree.Visitor {
|
|||||||
// We are seeing a member class.
|
// We are seeing a member class.
|
||||||
c = syms.enterClass(env.toplevel.modle, tree.name, (TypeSymbol)owner);
|
c = syms.enterClass(env.toplevel.modle, tree.name, (TypeSymbol)owner);
|
||||||
if (c.owner != 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)
|
//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:
|
//if this class is a member of such an anonymous class, fix the owner:
|
||||||
Assert.check(owner.owner.kind != TYP, owner::toString);
|
Assert.check(owner.owner.kind != TYP, owner::toString);
|
||||||
|
@ -443,6 +443,10 @@ compiler.err.invalid.repeatable.annotation.not.applicable.in.context=\
|
|||||||
compiler.err.duplicate.class=\
|
compiler.err.duplicate.class=\
|
||||||
duplicate class: {0}
|
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=\
|
compiler.err.duplicate.case.label=\
|
||||||
duplicate case label
|
duplicate case label
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ NestedInnerClassNames.java:46:13: compiler.err.already.defined: kindname.class,
|
|||||||
NestedInnerClassNames.java:59:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.foo$bar, kindname.class, NestedInnerClassNames
|
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: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: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: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: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
|
NestedInnerClassNames.java:40:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package
|
||||||
|
@ -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 {}
|
||||||
|
}
|
@ -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
|
@ -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 {}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user