Skip to content

Commit

Permalink
8262117: jextract crashes with javac compilation error "class u is al…
Browse files Browse the repository at this point in the history
…ready defined"
  • Loading branch information
sundararajana committed Feb 23, 2021
1 parent 1529a7e commit bea8e2d
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
Expand Up @@ -205,7 +205,14 @@ String build() {
*/
final String uniqueNestedClassName(String name) {
name = Utils.javaSafeIdentifier(name);
return nestedClassNames.add(name.toLowerCase()) ? name : (name + "$" + nestedClassNameCount++);
var notSeen = nestedClassNames.add(name.toLowerCase());
var notEnclosed = !isEnclosedBySameName(name.toLowerCase());
return notSeen && notEnclosed? name : (name + "$" + nestedClassNameCount++);
}

// is the name enclosed enclosed by a class of the same name?
boolean isEnclosedBySameName(String name) {
return false;
}

protected void emitPackagePrefix() {
Expand Down
Expand Up @@ -45,6 +45,11 @@ protected String mods() {
"public " : "public static ";
}

@Override
boolean isEnclosedBySameName(String name) {
return className().equals(name) || enclosing.isEnclosedBySameName(name);
}

@Override
String fullName() {
return enclosing.className() + "." + className();
Expand Down
59 changes: 59 additions & 0 deletions test/jdk/tools/jextract/Test8262117.java
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2021, 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.
*/

import java.lang.reflect.Method;
import java.nio.file.Path;
import jdk.incubator.foreign.NativeScope;
import org.testng.annotations.Test;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

/*
* @test
* @modules jdk.incubator.jextract
* @library /test/lib
* @build JextractToolRunner
* @bug 8262117
* @summary jextract crashes with javac compilation error "class u is already defined"
* @run testng/othervm -Dforeign.restricted=permit Test8262117
*/
public class Test8262117 extends JextractToolRunner {
@Test
public void testNameClash() {
Path test8262117Output = getOutputFilePath("test8262117_gen");
Path test8262117H = getInputFilePath("test8262117.h");
run("-d", test8262117Output.toString(), test8262117H.toString()).checkSuccess();
try(Loader loader = classLoader(test8262117Output)) {
Class<?> cls = loader.loadClass("test8262117_h");
assertNotNull(cls);

assertNotNull(loader.loadClass("test8262117_h$u"));
assertNotNull(loader.loadClass("test8262117_h$u$outer$u$0"));
assertNotNull(loader.loadClass("test8262117_h$v"));
assertNotNull(loader.loadClass("test8262117_h$v$v$0"));
} finally {
deleteDir(test8262117Output);
}
}
}
38 changes: 38 additions & 0 deletions test/jdk/tools/jextract/test8262117.h
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2021, 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.
*/


union {
struct {
union {
struct { int x; } inner;
} u;
} outer;
} u;


union {
union {
int x; long y;
} v;
} v;

0 comments on commit bea8e2d

Please sign in to comment.